webpack.prod.conf.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. 'use strict';
  2. const path = require('path');
  3. const utils = require('./utils');
  4. const webpack = require('webpack');
  5. const config = require('../config');
  6. const merge = require('webpack-merge');
  7. const baseWebpackConfig = require('./webpack.base.conf');
  8. const HtmlWebpackPlugin = require('html-webpack-plugin');
  9. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  10. const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
  11. const CopyWebpackPlugin = require('copy-webpack-plugin');
  12. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  13. const es3ifyPlugin=require('es3ify-webpack-plugin');
  14. const env = config.build.env;
  15. const cssSourceMap=config.build.cssSourceMap;
  16. const webpackConfig = merge(baseWebpackConfig, {
  17. devtool: config.build.productionSourceMap ? '#source-map' : false,
  18. output: {
  19. path: config.build.assetsRoot,
  20. publicPath: "./",
  21. filename: utils.assetsPath('js/[name].[chunkhash].js'),
  22. chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
  23. },
  24. resolve: {
  25. alias: {
  26. 'react': 'anujs/dist/ReactIE',
  27. 'react-dom': 'anujs/dist/ReactIE',
  28. 'prop-types': 'anujs/lib/ReactPropTypes'
  29. }
  30. },
  31. module: {
  32. rules: [
  33. {
  34. test: /\.(js|jsx)$/,
  35. loader: 'babel-loader',
  36. exclude: /node_modules/
  37. },
  38. {
  39. test: /\.css$/,
  40. use: ExtractTextPlugin.extract({
  41. fallback: 'style-loader?sourceMap',
  42. use: [{
  43. loader: 'css-loader',
  44. options: {
  45. minimize: false,
  46. sourceMap: cssSourceMap,
  47. localIdentName: '[path][hash:base64:5]',
  48. module:true
  49. }
  50. }]
  51. })
  52. },
  53. {
  54. test: /\.less/,
  55. use: ExtractTextPlugin.extract({
  56. fallback: 'style-loader?sourceMap',
  57. use: [{
  58. loader: 'css-loader',
  59. options: {
  60. minimize: false,
  61. sourceMap: cssSourceMap,
  62. importLoaders: 1,
  63. localIdentName: '[path][hash:base64:5]',
  64. module:true
  65. }
  66. },
  67. {
  68. loader: 'less-loader',
  69. options: {
  70. sourceMap: cssSourceMap
  71. }
  72. }
  73. ]
  74. })
  75. }
  76. ]
  77. },
  78. plugins: [
  79. new webpack.DefinePlugin({
  80. 'process.env': env
  81. }),
  82. new UglifyJsPlugin({
  83. sourceMap: true,
  84. uglifyOptions:{
  85. ie8:true,
  86. ecma:5,
  87. warnings: false,
  88. mangle:{
  89. reserved:['export','default','$','exports','import','module']
  90. },
  91. compress:{
  92. // booleans:false,
  93. // comparisons:false,
  94. // computed_props:false,
  95. // conditionals:false,
  96. // evaluate:false,
  97. // hoist_props:false,
  98. // if_return:false,
  99. // inline:false,
  100. // join_vars:false,
  101. // loops:false,
  102. // negate_iife:false,
  103. // properties:false,
  104. // pure_getters:true,
  105. reduce_funcs:false,//确定影响IE8的报错的配置
  106. // reduce_vars:false,
  107. // sequences:false,
  108. },
  109. output:{
  110. comments:false
  111. }
  112. }
  113. }),
  114. new HtmlWebpackPlugin({
  115. filename: config.build.index,
  116. template: 'index.html',
  117. inject: 'body',
  118. favicon:'./favicon.ico',
  119. minify: {
  120. removeComments: true,
  121. collapseWhitespace: true,
  122. removeAttributeQuotes: true
  123. },
  124. chunksSortMode: 'dependency',
  125. }),
  126. new ExtractTextPlugin({
  127. filename: utils.assetsPath('css/[name].[contenthash].css')
  128. }),
  129. new OptimizeCSSPlugin({
  130. cssProcessorOptions: {
  131. safe: true
  132. }
  133. }),
  134. // new es3ifyPlugin(),
  135. new webpack.HashedModuleIdsPlugin(),
  136. new webpack.optimize.CommonsChunkPlugin({
  137. name: 'vendor',
  138. minChunks: function (module) {
  139. return (
  140. module.resource &&
  141. /\.js$/.test(module.resource) &&
  142. module.resource.indexOf(
  143. path.join(__dirname, '../node_modules')
  144. ) === 0
  145. )
  146. }
  147. }),
  148. new webpack.optimize.CommonsChunkPlugin({
  149. name: 'manifest',
  150. chunks: ['vendor']
  151. }),
  152. new CopyWebpackPlugin([
  153. {
  154. from: path.join(__dirname, "../static/"),
  155. to:path.join( __dirname , "../app/public/static")
  156. }
  157. ])
  158. ]
  159. });
  160. module.exports = webpackConfig;