webpack.config.pro.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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': '#58a3ff',
  7. '@link-color': '#58a3ff',
  8. '@border-radius-base': '0px'
  9. };
  10. module.exports = {
  11. entry: {
  12. //user
  13. 'user/index': './js/user/index.js',
  14. 'user/login': './js/user/login.js',
  15. 'user/signIn': './js/user/signIn.js',
  16. //usre-account
  17. 'user/account/index': './js/user/account/index.js',
  18. 'user/account/set': './js/user/account/set.js',
  19. //admin
  20. 'admin/index':'./js/admin/index.js',
  21. vendors: ['jquery']
  22. },
  23. output: {
  24. path: path.resolve(__dirname, './build'),
  25. filename: '[name].js',
  26. },
  27. module: {
  28. loaders: [{
  29. test: /\.jsx?$/,
  30. exclude: /node_modules/,
  31. loader: 'babel-loader',
  32. query: {
  33. "presets": ["es2015", "react"],
  34. "plugins": [
  35. ["antd", {
  36. "style": true
  37. }]
  38. ]
  39. }
  40. //loaders: ['babel-loader?presets[]=es2015,presets[]=react']
  41. }, {
  42. test: /\.css$/,
  43. loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
  44. }, {
  45. test: /\.less$/,
  46. loader: ExtractTextPlugin.extract('style', `css!less?{"modifyVars":${JSON.stringify(theme)}}`)
  47. }, {
  48. test: /\.(png|jpg)$/,
  49. loader: 'url?limit=8192&name=[path][name].[ext]'
  50. }]
  51. },
  52. resolve: {
  53. extensions: ['', '.js', '.jsx']
  54. },
  55. plugins: [
  56. //这个使用uglifyJs压缩你的js代码
  57. new webpack.optimize.UglifyJsPlugin({
  58. minimize: true,
  59. compress: {
  60. warnings: true
  61. }
  62. }),
  63. new webpack.DefinePlugin({
  64. "process.env": {
  65. NODE_ENV: JSON.stringify("production")
  66. }
  67. }),
  68. new ExtractTextPlugin('[name].css', {
  69. allChunks: true
  70. }),
  71. //把入口文件里面的数组打包成verdors.js
  72. new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
  73. //user
  74. new HtmlWebpackPlugin({
  75. title: '用户首页',
  76. filename: 'user/index.html',
  77. template: './template/template.html',
  78. chunks:['user/index','vendors']
  79. }),
  80. new HtmlWebpackPlugin({
  81. title: '用户登录',
  82. filename: 'user/login.html',
  83. template: './template/template.html',
  84. chunks:['user/login','vendors']
  85. }),
  86. new HtmlWebpackPlugin({
  87. title: '用户注册',
  88. filename: 'user/signIn.html',
  89. template: './template/template.html',
  90. chunks:['user/signIn','vendors']
  91. }),
  92. //user-account
  93. new HtmlWebpackPlugin({
  94. title: '用户中心-首页',
  95. filename: 'user/account/index.html',
  96. template: './template/template.html',
  97. chunks:['user/account/index','vendors']
  98. }),
  99. new HtmlWebpackPlugin({
  100. title: '用户中心-首页',
  101. filename: 'user/account/set.html',
  102. template: './template/template.html',
  103. chunks:['user/account/set','vendors']
  104. }),
  105. //admin
  106. new HtmlWebpackPlugin({
  107. title: 'admin_index',
  108. filename: 'admin/index.html',
  109. template: './template/template.html',
  110. chunks:['admin/index','vendors']
  111. })
  112. ]
  113. };