webpack.dev.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. const webpack = require('webpack')
  2. const path = require('path')
  3. const readEntryFile = require('./webpack.common.js')
  4. const HtmlWebpackPlugin = require('html-webpack-plugin')
  5. const ExtractTextPlugin = require("extract-text-webpack-plugin")
  6. const CleanWebpackPlugin = require('clean-webpack-plugin')
  7. /**
  8. * 默认入口是有vendor的 如果不需要可以去除
  9. */
  10. var entry = {
  11. }
  12. var plugins = [
  13. new webpack.HotModuleReplacementPlugin(),
  14. new CleanWebpackPlugin(['dist']),
  15. new webpack.optimize.CommonsChunkPlugin('vendor'),
  16. new webpack.ProvidePlugin({
  17. _: "underscore"
  18. })
  19. ]
  20. readEntryFile().forEach(function (file) {
  21. plugins.push(new HtmlWebpackPlugin({
  22. filename: file.name + '.html',
  23. template: file.htmlentry,
  24. inject: 'body',
  25. chunksSortMode: 'manual',
  26. chunks: ['vendor', file.name]
  27. }))
  28. entry[file.name] = file.jsentry
  29. }, this);
  30. module.exports = {
  31. entry: entry,
  32. output: {
  33. publicPath: "/",
  34. filename: '[name].js',
  35. path: path.resolve(__dirname, 'dist')
  36. },
  37. module: {
  38. rules: [
  39. {
  40. test: /\.vue$/,
  41. loader: 'vue-loader',
  42. exclude: /node_modules/
  43. },
  44. {
  45. test: /\.js$/,
  46. loader: 'babel-loader',
  47. exclude: /node_modules/
  48. },
  49. {
  50. test: /\.css$/,
  51. use: [{
  52. loader: "style-loader",
  53. }, {
  54. loader: "css-loader",
  55. options: {
  56. sourceMap: true
  57. }
  58. }]
  59. },
  60. {
  61. test: /\.scss$/,
  62. use: [{
  63. loader: "style-loader",
  64. }, {
  65. loader: "css-loader",
  66. options: {
  67. sourceMap: true
  68. }
  69. }, {
  70. loader: "postcss-loader",
  71. options: {
  72. ctx: {
  73. autoprefixer: true
  74. }, sourceMap: true
  75. }
  76. }, {
  77. loader: "sass-loader",
  78. options: {
  79. sourceMap: true
  80. }
  81. }]
  82. },
  83. {
  84. test: /\.html$/,
  85. use: [{
  86. loader: 'html-loader',
  87. options: {
  88. attrs: ['img:src', 'img:data-src'],
  89. minimize: false
  90. }
  91. }]
  92. },
  93. {
  94. test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
  95. loader: 'file-loader',
  96. options: {
  97. name: '[name]_[hash:6].[ext]',
  98. }
  99. },
  100. {
  101. test: /\.tmpl$/,
  102. use: 'ejs-loader'
  103. }
  104. ]
  105. },
  106. devtool: 'inline-source-map',
  107. devServer: {
  108. contentBase: './dist',
  109. host: '127.0.0.1',
  110. hot: true,
  111. disableHostCheck: true
  112. },
  113. plugins: plugins,
  114. resolve: {
  115. alias: {
  116. 'vue$': 'vue/dist/vue.esm.js',
  117. "jsonp": path.resolve(__dirname, './src/lib/jsonp.js'),
  118. "clipboard": path.resolve(__dirname, './src/lib/clipboard/clipboard.js'),
  119. "lib": path.resolve(__dirname, './src/lib/library.js'),
  120. "extSdk": path.resolve(__dirname, './src/lib/extSdk/extSdk.js')
  121. }
  122. }
  123. }