webpack.prod.config.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const webpack = require('webpack');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  4. const merge = require('webpack-merge');
  5. const webpackBaseConfig = require('./webpack.base.config.js');
  6. const fs = require('fs');
  7. fs.open('./src/config/env.js', 'w', function (err, fd) {
  8. const buf = 'export default "production";';
  9. fs.write(fd, buf, 0, buf.length, 0, function (err, written, buffer){});
  10. });
  11. module.exports = merge(webpackBaseConfig, {
  12. output: {
  13. publicPath: '/dist/',
  14. filename: '[name].[hash].js',
  15. chunkFilename: '[name].[hash].chunk.js'
  16. },
  17. plugins: [
  18. new ExtractTextPlugin({
  19. filename: '[name].[hash].css',
  20. allChunks: true
  21. }),
  22. new webpack.optimize.CommonsChunkPlugin({
  23. name: 'vendors',
  24. filename: 'vendors.[hash].js'
  25. }),
  26. new webpack.DefinePlugin({
  27. 'process.env': {
  28. NODE_ENV: '"production"'
  29. }
  30. }),
  31. new webpack.optimize.UglifyJsPlugin({
  32. compress: {
  33. warnings: false
  34. }
  35. }),
  36. new HtmlWebpackPlugin({
  37. filename: '../index_prod.html',
  38. template: './src/template/index.ejs',
  39. inject: false
  40. })
  41. ]
  42. });