webpack.dev.conf.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. var utils = require('./utils')
  2. var webpack = require('webpack')
  3. var config = require('../config')
  4. var merge = require('webpack-merge')
  5. var baseWebpackConfig = require('./webpack.base.conf')
  6. // var HtmlWebpackPlugin = require('html-webpack-plugin')
  7. var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
  8. var MpvueVendorPlugin = require('webpack-mpvue-vendor-plugin')
  9. // copy from ./webpack.prod.conf.js
  10. var path = require('path')
  11. var ExtractTextPlugin = require('extract-text-webpack-plugin')
  12. var CopyWebpackPlugin = require('copy-webpack-plugin')
  13. var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
  14. var UglifyJsPlugin = require('uglifyjs-webpack-plugin')
  15. // add hot-reload related code to entry chunks
  16. // Object.keys(baseWebpackConfig.entry).forEach(function (name) {
  17. // baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
  18. // })
  19. module.exports = merge(baseWebpackConfig, {
  20. module: {
  21. rules: utils.styleLoaders({
  22. sourceMap: config.dev.cssSourceMap,
  23. extract: true
  24. })
  25. },
  26. // cheap-module-eval-source-map is faster for development
  27. // devtool: '#cheap-module-eval-source-map',
  28. // devtool: '#source-map',
  29. output: {
  30. path: config.build.assetsRoot,
  31. // filename: utils.assetsPath('[name].[chunkhash].js'),
  32. // chunkFilename: utils.assetsPath('[id].[chunkhash].js')
  33. filename: utils.assetsPath('[name].js'),
  34. chunkFilename: utils.assetsPath('[id].js')
  35. },
  36. plugins: [
  37. new webpack.DefinePlugin({
  38. 'process.env': config.dev.env
  39. }),
  40. // copy from ./webpack.prod.conf.js
  41. // extract css into its own file
  42. new ExtractTextPlugin({
  43. // filename: utils.assetsPath('[name].[contenthash].css')
  44. filename: utils.assetsPath(`[name].${config.dev.fileExt.style}`)
  45. }),
  46. // Compress extracted CSS. We are using this plugin so that possible
  47. // duplicated CSS from different components can be deduped.
  48. new OptimizeCSSPlugin({
  49. cssProcessorOptions: {
  50. safe: true
  51. }
  52. }),
  53. new webpack.optimize.CommonsChunkPlugin({
  54. name: 'common/vendor',
  55. minChunks: function (module, count) {
  56. // any required modules inside node_modules are extracted to vendor
  57. return (
  58. module.resource &&
  59. /\.js$/.test(module.resource) &&
  60. module.resource.indexOf('node_modules') >= 0
  61. ) || count > 1
  62. }
  63. }),
  64. new webpack.optimize.CommonsChunkPlugin({
  65. name: 'common/webext',
  66. chunks:['common/vendor'],
  67. minChunks: function (module, count) {
  68. // any required modules inside node_modules are extracted to vendor
  69. return (
  70. module.resource &&
  71. /\.js$/.test(module.resource) &&
  72. module.resource.indexOf('echarts') >= 0 &&
  73. module.resource.indexOf('node_modules') === -1
  74. )
  75. }
  76. }),
  77. new webpack.optimize.CommonsChunkPlugin({
  78. name: 'common/manifest',
  79. chunks: ['common/webext']
  80. }),
  81. new MpvueVendorPlugin({
  82. platform: process.env.PLATFORM
  83. }),
  84. // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
  85. // new webpack.HotModuleReplacementPlugin(),
  86. new webpack.NoEmitOnErrorsPlugin(),
  87. // https://github.com/ampedandwired/html-webpack-plugin
  88. // new HtmlWebpackPlugin({
  89. // filename: 'index.html',
  90. // template: 'index.html',
  91. // inject: true
  92. // }),
  93. new FriendlyErrorsPlugin(),
  94. new UglifyJsPlugin({ sourceMap: true })
  95. ]
  96. })