webpack.config.js 6.9 KB

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