webpack.config.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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('./webpack/entry.config.js');
  7. const version = require('./package.json').version;
  8. const argv = require('yargs').argv;
  9. const dirVars = require('./webpack/dir.config.js');
  10. let theme = {
  11. '@primary-color': '#58a3ff',
  12. '@link-color': '#58a3ff'
  13. };
  14. let isWatch = argv.env.deploy == 'watch';
  15. let isDev = isWatch || argv.env.deploy == 'dev';
  16. module.exports = (function () {
  17. var dllContext = path.resolve(dirVars.dllDir, './' + argv.env.deploy);
  18. let plugins = [
  19. /* 配置好Dll */
  20. new webpack.DllReferencePlugin({
  21. context: dirVars.staticRootDir, // 指定一个路径作为上下文环境,需要与DllPlugin的context参数保持一致,建议统一设置为项目根目录
  22. manifest: path.resolve(dllContext, 'manifest.json'), // 指定manifest.json
  23. name: 'dll', // 当前Dll的所有内容都会存放在这个参数指定变量名的一个全局变量下,注意与DllPlugin的name参数保持一致
  24. }),
  25. new ExtractTextPlugin({
  26. filename: "[name].css",
  27. disable: false,
  28. allChunks: true
  29. }),
  30. //把入口文件里面的数组打包成verdors.js
  31. new webpack.optimize.CommonsChunkPlugin({
  32. name: 'vendors'
  33. }),
  34. //user
  35. new HtmlWebpackPlugin({
  36. title: '用户首页',
  37. filename: 'user/index.html',
  38. template: './template/template.html',
  39. chunks: ['user/index', 'vendors']
  40. }),
  41. new HtmlWebpackPlugin({
  42. title: '用户登录',
  43. filename: 'user/login.html',
  44. template: './template/template.html',
  45. chunks: ['user/login', 'vendors']
  46. }),
  47. new HtmlWebpackPlugin({
  48. title: '用户注册',
  49. filename: 'user/signIn.html',
  50. template: './template/template.html',
  51. chunks: ['user/signIn', 'vendors']
  52. }),
  53. new HtmlWebpackPlugin({
  54. title: '个人用户认证',
  55. filename: 'user/certify.html',
  56. template: './template/template.html',
  57. chunks: ['user/certify', 'vendors']
  58. }),
  59. new HtmlWebpackPlugin({
  60. title: '团体用户认证',
  61. filename: 'user/groupCertify.html',
  62. template: './template/template.html',
  63. chunks: ['user/groupCertify', 'vendors']
  64. }),
  65. //user-account
  66. new HtmlWebpackPlugin({
  67. title: '用户中心-首页',
  68. filename: 'user/account/index.html',
  69. template: './template/template.html',
  70. chunks: ['user/account/index', 'vendors']
  71. }),
  72. new HtmlWebpackPlugin({
  73. title: '用户中心-设置',
  74. filename: 'user/account/set.html',
  75. template: './template/template.html',
  76. chunks: ['user/account/set', 'vendors']
  77. }),
  78. new HtmlWebpackPlugin({
  79. title: '用户中心-科技服务',
  80. filename: 'user/account/services.html',
  81. template: './template/template.html',
  82. chunks: ['user/account/services', 'vendors']
  83. }),
  84. new HtmlWebpackPlugin({
  85. title: '用户中心-科技服务',
  86. filename: 'user/account/achievement.html',
  87. template: './template/template.html',
  88. chunks: ['user/account/achievement', 'vendors']
  89. }),
  90. new HtmlWebpackPlugin({
  91. title: '用户中心-科技服务',
  92. filename: 'user/account/demand.html',
  93. template: './template/template.html',
  94. chunks: ['user/account/demand', 'vendors']
  95. }),
  96. //admin
  97. new HtmlWebpackPlugin({
  98. title: '管理员-首页',
  99. filename: 'admin/index.html',
  100. template: './template/template.html',
  101. chunks: ['admin/index', 'vendors']
  102. }),
  103. new HtmlWebpackPlugin({
  104. title: '管理员-登录',
  105. filename: 'admin/login.html',
  106. template: './template/template.html',
  107. chunks: ['admin/login', 'vendors']
  108. }),
  109. new HtmlWebpackPlugin({
  110. title: '管理员-用户管理',
  111. filename: 'admin/userManage.html',
  112. template: './template/template.html',
  113. chunks: ['admin/userManage', 'vendors']
  114. }),
  115. //admin-servicesManage
  116. new HtmlWebpackPlugin({
  117. title: '管理员-科技服务管理-专利',
  118. filename: 'admin/servicesManage/contract.html',
  119. template: './template/template.html',
  120. chunks: ['admin/servicesManage/contract', 'vendors']
  121. }),
  122. new HtmlWebpackPlugin({
  123. title: '管理员-科技服务管理-专利',
  124. filename: 'admin/servicesManage/patent.html',
  125. template: './template/template.html',
  126. chunks: ['admin/servicesManage/patent', 'vendors']
  127. }),
  128. new HtmlWebpackPlugin({
  129. title: '管理员-科技服务管理-软著',
  130. filename: 'admin/servicesManage/copyright.html',
  131. template: './template/template.html',
  132. chunks: ['admin/servicesManage/copyright', 'vendors']
  133. }),
  134. new HtmlWebpackPlugin({
  135. title: '管理员-科技服务管理-高企',
  136. filename: 'admin/servicesManage/highTech.html',
  137. template: './template/template.html',
  138. chunks: ['admin/servicesManage/highTech', 'vendors']
  139. }),
  140. new HtmlWebpackPlugin({
  141. title: '管理员-科技服务管理-高企信息',
  142. filename: 'admin/servicesManage/highTechInfo.html',
  143. template: './template/template.html',
  144. chunks: ['admin/servicesManage/highTechInfo', 'vendors']
  145. }),
  146. new HtmlWebpackPlugin({
  147. title: '管理员-科技服务管理-科技',
  148. filename: 'admin/servicesManage/technology.html',
  149. template: './template/template.html',
  150. chunks: ['admin/servicesManage/technology', 'vendors']
  151. }),
  152. //admin-demand
  153. new HtmlWebpackPlugin({
  154. title: '管理员-用户管理',
  155. filename: 'admin/demand.html',
  156. template: './template/template.html',
  157. chunks: ['admin/demand', 'vendors']
  158. }),
  159. //admin-achievement
  160. new HtmlWebpackPlugin({
  161. title: '管理员-用户管理',
  162. filename: 'admin/achievement.html',
  163. template: './template/template.html',
  164. chunks: ['admin/achievement', 'vendors']
  165. }),
  166. //admin-set
  167. new HtmlWebpackPlugin({
  168. title: '管理员-用户管理',
  169. filename: 'admin/set.html',
  170. template: './template/template.html',
  171. chunks: ['admin/set', 'vendors']
  172. }),
  173. //portal 门户
  174. new HtmlWebpackPlugin({
  175. title: '主页-需求搜索',
  176. filename: 'portal/search/demand.html',
  177. template: './template/template.html',
  178. chunks: ['portal/search/demand', 'vendors']
  179. }),
  180. new HtmlWebpackPlugin({
  181. title: '主页-科技成果搜索',
  182. filename: 'portal/search/achievement.html',
  183. template: './template/template.html',
  184. chunks: ['portal/search/achievement', 'vendors']
  185. })
  186. ];
  187. if (!isDev) {
  188. //这个使用uglifyJs压缩你的js代码
  189. plugins.unshift(new webpack.DefinePlugin({
  190. "process.env": {
  191. NODE_ENV: JSON.stringify("production")
  192. }
  193. }));
  194. plugins.unshift(new webpack.optimize.UglifyJsPlugin({
  195. minimize: true,
  196. compress: {
  197. warnings: true
  198. }
  199. }));
  200. }
  201. let staticHost = 'http://afts.hnzhiming.com';
  202. switch (argv.env.deploy) {
  203. case 'stage':
  204. staticHost = 'http://aftts.hnzhiming.com';
  205. break;
  206. case 'prod':
  207. staticHost = 'http://static.goafanti.com';
  208. break;
  209. default:
  210. break;
  211. }
  212. staticHost = staticHost + '/' + version + '/';
  213. theme['@icon-url'] = '"' + staticHost + 'css/iconfont/iconfont"'
  214. return {
  215. entry: isWatch ? entries.watch : entries.prod,
  216. output: {
  217. path: path.resolve(__dirname, './build/' + argv.env.deploy + '/' + version),
  218. filename: '[name].js',
  219. publicPath: staticHost,
  220. chunkFilename: 'chunks/[name].[hash:8].js'
  221. },
  222. module: require('./webpack/module.config.js')(theme),
  223. resolve: {
  224. extensions: ['.js', '.jsx']
  225. },
  226. plugins: plugins
  227. };
  228. })();