webpack.config.pro.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. };
  9. module.exports = {
  10. entry: {
  11. //user
  12. 'user/index': './js/user/index.js',
  13. 'user/login': './js/user/login.js',
  14. 'user/signIn': './js/user/signIn.js',
  15. 'user/certify': './js/user/certify.js',
  16. 'user/groupCertify': './js/user/groupCertify.js',
  17. //user-account
  18. 'user/account/index': './js/user/account/index.js',
  19. 'user/account/set': './js/user/account/set.js',
  20. 'user/account/services': './js/user/account/services.js',
  21. //admin
  22. 'admin/index': './js/admin/index.js',
  23. 'admin/login': './js/admin/login.js',
  24. 'admin/userManage': './js/admin/userManage.js',
  25. //admin-servicesManage
  26. 'admin/servicesManage/patent': './js/admin/servicesManage/patent.js',
  27. 'admin/servicesManage/copyright': './js/admin/servicesManage/copyright.js',
  28. 'admin/servicesManage/highTech': './js/admin/servicesManage/highTech.js',
  29. vendors: ['jquery']
  30. },
  31. output: {
  32. path: path.resolve(__dirname, './build'),
  33. filename: '[name].js',
  34. },
  35. module: {
  36. rules: [{
  37. test: /\.jsx?$/,
  38. exclude: /node_modules/,
  39. use: {
  40. loader: 'babel-loader',
  41. options: {
  42. "presets": ["es2015", "react"],
  43. "plugins": [
  44. ["antd", {
  45. "style": true
  46. }]
  47. ]
  48. }
  49. }
  50. },
  51. {
  52. test: /\.less$/,
  53. use: ExtractTextPlugin.extract({
  54. fallback: 'style-loader',
  55. use: [{
  56. loader: 'css-loader',
  57. options: {
  58. importLoaders: 1
  59. }
  60. }, {
  61. loader: 'less-loader',
  62. options: {
  63. modifyVars: theme
  64. }
  65. }]
  66. })
  67. }, {
  68. test: /\.(png|jpg)$/,
  69. use: [{
  70. loader: 'url-loader',
  71. options: {
  72. limit: 8192,
  73. name: '[path][name].[ext]'
  74. }
  75. }]
  76. }
  77. ]
  78. },
  79. resolve: {
  80. extensions: ['.js', '.jsx']
  81. },
  82. plugins: [
  83. //这个使用uglifyJs压缩你的js代码
  84. new webpack.optimize.UglifyJsPlugin({
  85. minimize: true,
  86. compress: {
  87. warnings: true
  88. }
  89. }),
  90. new webpack.DefinePlugin({
  91. "process.env": {
  92. NODE_ENV: JSON.stringify("production")
  93. }
  94. }),
  95. new ExtractTextPlugin({
  96. filename: "[name].css",
  97. disable: false,
  98. allChunks: true
  99. }),
  100. //把入口文件里面的数组打包成verdors.js
  101. new webpack.optimize.CommonsChunkPlugin({
  102. name: 'vendors',
  103. chunks: ['vendors']
  104. }),
  105. //user
  106. new HtmlWebpackPlugin({
  107. title: '用户首页',
  108. filename: 'user/index.html',
  109. template: './template/template.html',
  110. chunks: ['user/index', 'vendors']
  111. }),
  112. new HtmlWebpackPlugin({
  113. title: '用户登录',
  114. filename: 'user/login.html',
  115. template: './template/template.html',
  116. chunks: ['user/login', 'vendors']
  117. }),
  118. new HtmlWebpackPlugin({
  119. title: '用户注册',
  120. filename: 'user/signIn.html',
  121. template: './template/template.html',
  122. chunks: ['user/signIn', 'vendors']
  123. }),
  124. new HtmlWebpackPlugin({
  125. title: '个人用户认证',
  126. filename: 'user/certify.html',
  127. template: './template/template.html',
  128. chunks: ['user/certify', 'vendors']
  129. }),
  130. new HtmlWebpackPlugin({
  131. title: '团体用户认证',
  132. filename: 'user/groupCertify.html',
  133. template: './template/template.html',
  134. chunks: ['user/groupCertify', 'vendors']
  135. }),
  136. //user-account
  137. new HtmlWebpackPlugin({
  138. title: '用户中心-首页',
  139. filename: 'user/account/index.html',
  140. template: './template/template.html',
  141. chunks: ['user/account/index', 'vendors']
  142. }),
  143. new HtmlWebpackPlugin({
  144. title: '用户中心-设置',
  145. filename: 'user/account/set.html',
  146. template: './template/template.html',
  147. chunks: ['user/account/set', 'vendors']
  148. }),
  149. //user-account-services-patent
  150. new HtmlWebpackPlugin({
  151. title: '用户中心-科技服务',
  152. filename: 'user/account/services.html',
  153. template: './template/template.html',
  154. chunks: ['user/account/services', 'vendors']
  155. }),
  156. //admin
  157. new HtmlWebpackPlugin({
  158. title: '管理员-首页',
  159. filename: 'admin/index.html',
  160. template: './template/template.html',
  161. chunks: ['admin/index', 'vendors']
  162. }),
  163. new HtmlWebpackPlugin({
  164. title: '管理员-登录',
  165. filename: 'admin/login.html',
  166. template: './template/template.html',
  167. chunks: ['admin/login', 'vendors']
  168. }),
  169. new HtmlWebpackPlugin({
  170. title: '管理员-用户管理',
  171. filename: 'admin/userManage.html',
  172. template: './template/template.html',
  173. chunks: ['admin/userManage', 'vendors']
  174. }),
  175. //admin-servicesManage
  176. new HtmlWebpackPlugin({
  177. title: '管理员-科技服务管理-专利',
  178. filename: 'admin/servicesManage/patent.html',
  179. template: './template/template.html',
  180. chunks: ['admin/servicesManage/patent', 'vendors']
  181. }),
  182. new HtmlWebpackPlugin({
  183. title: '管理员-科技服务管理-软著',
  184. filename: 'admin/servicesManage/copyright.html',
  185. template: './template/template.html',
  186. chunks: ['admin/servicesManage/copyright', 'vendors']
  187. }),
  188. new HtmlWebpackPlugin({
  189. title: '管理员-科技服务管理-高企',
  190. filename: 'admin/servicesManage/highTech.html',
  191. template: './template/template.html',
  192. chunks: ['admin/servicesManage/highTech', 'vendors']
  193. }),
  194. ]
  195. };