webpack.prod.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. const webpack = require('webpack');
  2. const merge = require('webpack-merge');
  3. const path = require('path');
  4. const base = require('./webpack.base.config');
  5. const HtmlWebpackPlugin = require('html-webpack-plugin');
  6. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  7. const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
  8. // const BabelMinifyPlugin = require("babel-minify-webpack-plugin");
  9. let output = {
  10. path : path.resolve(__dirname, `./build`),
  11. publicPath : `build/`,
  12. filename : 'bundle/[name].bundle.js?[hash]',
  13. chunkFilename : 'chunk/[name].chunk.js?[hash]'
  14. }
  15. // config.output.path = config.extraPath + '/build';
  16. // config.output.publicPath = 'build/';
  17. // config.output.filename = '[name].js?[hash]';
  18. // config.output.chunkFilename = '[name].chunk.js?[hash]';
  19. // config.vue = {
  20. // loaders : {
  21. // css: ExtractTextPlugin.extract(
  22. // "style-loader",
  23. // "css-loader?sourceMap",
  24. // {
  25. // publicPath: './',
  26. // }
  27. // ),
  28. // less: ExtractTextPlugin.extract(
  29. // 'vue-style-loader',
  30. // 'css-loader!less-loader'
  31. // ),
  32. // sass: ExtractTextPlugin.extract(
  33. // 'vue-style-loader',
  34. // 'css-loader!sass-loader',
  35. // {
  36. // publicPath: './',
  37. // }
  38. // )
  39. // }
  40. // }
  41. // config.plugins = (config.plugins || []).concat([
  42. // new ExtractTextPlugin("[name].css?[hash]",{ allChunks : false, resolve : ['modules'] }),
  43. // new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js?[hash]'),
  44. // new webpack.DefinePlugin({
  45. // 'process.env': {
  46. // NODE_ENV: '"production"'
  47. // }
  48. // }),
  49. // new webpack.optimize.UglifyJsPlugin({
  50. // compress: {
  51. // warnings: false
  52. // }
  53. // }),
  54. // new HtmlWebpackPlugin({
  55. // filename: '../index.html',
  56. // template: './index.ejs',
  57. // inject: false
  58. // }),
  59. // new webpack.ProvidePlugin({
  60. // $: "jquery",
  61. // jQuery: "jquery",
  62. // "window.jQuery": "jquery"
  63. // })
  64. // ]);
  65. let plugins = [
  66. new ExtractTextPlugin("style/[name].css?[hash]",{
  67. allChunks : true,
  68. resolve : ['modules']
  69. }),
  70. new webpack.optimize.CommonsChunkPlugin({
  71. name : 'vendors',
  72. filename : 'chunk/vendors.chunk.js?[hash]'
  73. }),
  74. new webpack.DefinePlugin({
  75. 'process.env': {
  76. NODE_ENV: JSON.stringify("production")
  77. }
  78. }),
  79. new UglifyJSPlugin({
  80. uglifyOptions: {
  81. compress: {
  82. warnings: false
  83. }
  84. },
  85. parallel: true
  86. }),
  87. // new BabelMinifyPlugin(),
  88. new HtmlWebpackPlugin({
  89. filename: './index.html',
  90. template: './index.ejs',
  91. inject: 'body',
  92. // chunks: ['main','vendors'],
  93. minify: {
  94. html5: false,
  95. removeComments: true,
  96. removeEmptyAttributes: true,
  97. collapseWhitespace: true
  98. }
  99. }),
  100. new webpack.ProvidePlugin({
  101. $: "jquery",
  102. jQuery: "jquery",
  103. "window.jQuery": "jquery"
  104. })
  105. ]
  106. module.exports = merge(base, {
  107. // devtool: 'source-map',
  108. output: output,
  109. plugins: plugins
  110. });