webpack.config.prod.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Created by magedu on 2017/4/20.
  3. */
  4. const path = require('path');
  5. const webpack = require('webpack');
  6. const HtmlWebpackPlugin = require('html-webpack-plugin');
  7. module.exports = {
  8. devtool: 'source-map',
  9. entry: {
  10. 'app': [
  11. './src/index'
  12. ]
  13. },
  14. output: {
  15. path: path.join(__dirname, 'dist'),
  16. filename: '[name]-[hash:8].js',
  17. publicPath: '/assets/'
  18. },
  19. resolve: {
  20. extensions: ['.js']
  21. },
  22. module: {
  23. rules: [
  24. {
  25. test: /\.js$/,
  26. exclude: /node_modules/, // 不编译第三方包
  27. use: [
  28. { loader: 'react-hot-loader/webpack' },
  29. { loader: 'babel-loader' }
  30. ]
  31. },
  32. {
  33. test: /\.less$/,
  34. use: [
  35. { loader: "style-loader" },
  36. { loader: "css-loader" },
  37. { loader: "less-loader" }
  38. ]
  39. }
  40. ]
  41. },
  42. plugins: [
  43. new webpack.optimize.OccurrenceOrderPlugin(true),
  44. new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify('production') } }),
  45. new webpack.optimize.UglifyJsPlugin({
  46. compress: {
  47. warnings: false
  48. },
  49. sourceMap: true
  50. }),
  51. new HtmlWebpackPlugin({
  52. template: 'src/index.html',
  53. inject: true
  54. })
  55. ]
  56. };