webpack.config.pro.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const webpack = require('webpack');
  2. const path = require('path');
  3. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. let theme = {
  6. '@primary-color': '#1DA57A',
  7. '@link-color': '#1DA57A',
  8. '@border-radius-base': '8px'
  9. };
  10. module.exports = {
  11. entry: {
  12. 'user/index': './js/user/index.js',
  13. 'user/login': './js/user/login.js',
  14. 'admin/index':'./js/admin/index.js',
  15. vendors: ['jquery']
  16. },
  17. output: {
  18. path: path.resolve(__dirname, './build'),
  19. filename: '[name].js',
  20. },
  21. module: {
  22. loaders: [{
  23. test: /\.jsx?$/,
  24. exclude: /node_modules/,
  25. loader: 'babel-loader',
  26. query: {
  27. "presets": ["es2015", "react"],
  28. "plugins": [
  29. ["antd", {
  30. "style": true
  31. }]
  32. ]
  33. }
  34. //loaders: ['babel-loader?presets[]=es2015,presets[]=react']
  35. }, {
  36. test: /\.css$/,
  37. loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
  38. }, {
  39. test: /\.less$/,
  40. loader: ExtractTextPlugin.extract('style', `css!less?{"modifyVars":${JSON.stringify(theme)}}`)
  41. }, {
  42. test: /\.(png|jpg)$/,
  43. loader: 'url?limit=8192&name=[path][name].[ext]'
  44. }]
  45. },
  46. resolve: {
  47. extensions: ['', '.js', '.jsx']
  48. },
  49. plugins: [
  50. //这个使用uglifyJs压缩你的js代码
  51. new webpack.optimize.UglifyJsPlugin({
  52. minimize: true,
  53. compress: {
  54. warnings: true
  55. }
  56. }),
  57. new webpack.DefinePlugin({
  58. "process.env": {
  59. NODE_ENV: JSON.stringify("production")
  60. }
  61. }),
  62. new ExtractTextPlugin('[name].css', {
  63. allChunks: true
  64. }),
  65. //把入口文件里面的数组打包成verdors.js
  66. new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
  67. //user
  68. new HtmlWebpackPlugin({
  69. title: 'user_index',
  70. filename: 'user/index.html',
  71. template: './template/template.html',
  72. chunks:['user/index','vendors']
  73. }),
  74. new HtmlWebpackPlugin({
  75. title: 'user_login',
  76. filename: 'user/login.html',
  77. template: './template/template.html',
  78. chunks:['user/login','vendors']
  79. }),
  80. //admin
  81. new HtmlWebpackPlugin({
  82. title: 'admin_index',
  83. filename: 'admin/index.html',
  84. template: './template/template.html',
  85. chunks:['admin/index','vendors']
  86. })
  87. ]
  88. };