webpack.config.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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 CopyWebpackPlugin = require('copy-webpack-plugin')
  6. const HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plugin')
  7. const WebpackDevServer = require('webpack-dev-server')
  8. const entries = require('./webpack/entry.config.js')
  9. const version = require('./package.json').version
  10. const argv = require('yargs').argv
  11. const dirVars = require('./webpack/dir.config.js')
  12. let theme = {
  13. '@primary-color': '#58a3ff',
  14. '@link-color': '#58a3ff',
  15. }
  16. let isWatch = argv.env.watch == 'watch'
  17. let isDev = isWatch || argv.env.deploy == 'dev'
  18. process.traceDeprecation = true
  19. process.noDeprecation = true
  20. module.exports = (function () {
  21. let jumlApi = ''
  22. switch (argv.env.deploy) {
  23. case 'dev':
  24. jumlApi = 'http://sb.jishutao.com'
  25. break
  26. case 'test':
  27. jumlApi = 'http://uat.jishutao.com'
  28. break
  29. case 'prod':
  30. jumlApi = 'http://bm.jishutao.com'
  31. break
  32. default:
  33. break
  34. }
  35. let plugins = [
  36. //把入口文件里面的数组打包成verdors.js
  37. new webpack.optimize.CommonsChunkPlugin({
  38. name: 'vendors',
  39. }),
  40. /* 配置好Dll */
  41. new webpack.DllReferencePlugin({
  42. context: dirVars.staticRootDir, // 指定一个路径作为上下文环境,需要与DllPlugin的context参数保持一致,建议统一设置为项目根目录
  43. manifest: require('./dll/' + argv.env.deploy + '/manifest.json'), // 指定manifest.json
  44. }),
  45. // 把dll文件复制到打包后的文件中
  46. new CopyWebpackPlugin([
  47. {
  48. from: path.resolve('./dll/' + argv.env.deploy),
  49. to: (__dirname, './dll/'),
  50. ignore: ['.*'],
  51. },
  52. ]),
  53. // 将 dll.js 插入HTML里
  54. new HtmlWebpackIncludeAssetsPlugin({
  55. assets: [(__dirname, 'dll/dll.js'), (__dirname, 'dll/dll.css')],
  56. append: false,
  57. }),
  58. new ExtractTextPlugin({
  59. filename: '[name].css',
  60. disable: false,
  61. allChunks: true,
  62. }),
  63. //定义全局变量区分本地测试生产做跳转
  64. new webpack.DefinePlugin({
  65. jumpUrl: `'${jumlApi}'`,
  66. }),
  67. //user
  68. new HtmlWebpackPlugin({
  69. title: '用户首页',
  70. filename: 'user/index.html',
  71. template: './template/template.html',
  72. chunks: ['user/index', 'vendors'],
  73. }),
  74. new HtmlWebpackPlugin({
  75. title: '用户登录',
  76. filename: 'user/login.html',
  77. template: './template/template.html',
  78. chunks: ['user/login', 'vendors'],
  79. }),
  80. new HtmlWebpackPlugin({
  81. title: '用户注册',
  82. filename: 'user/signIn.html',
  83. template: './template/template.html',
  84. chunks: ['user/signIn', 'vendors'],
  85. }),
  86. new HtmlWebpackPlugin({
  87. title: '个人用户认证',
  88. filename: 'user/certify.html',
  89. template: './template/template.html',
  90. chunks: ['user/certify', 'vendors'],
  91. }),
  92. new HtmlWebpackPlugin({
  93. title: '团体用户认证',
  94. filename: 'user/groupCertify.html',
  95. template: './template/template.html',
  96. chunks: ['user/groupCertify', 'vendors'],
  97. }),
  98. new HtmlWebpackPlugin({
  99. title: '用户详情',
  100. filename: 'user/subscriberDetail.html',
  101. template: './template/template.html',
  102. chunks: ['user/subscriberDetail', 'vendors'],
  103. }),
  104. //user-account
  105. new HtmlWebpackPlugin({
  106. title: '用户中心-首页',
  107. filename: 'user/account/index.html',
  108. template: './template/template.html',
  109. chunks: ['user/account/index', 'vendors'],
  110. }),
  111. new HtmlWebpackPlugin({
  112. title: '用户中心-设置',
  113. filename: 'user/account/set.html',
  114. template: './template/template.html',
  115. chunks: ['user/account/set', 'vendors'],
  116. }),
  117. new HtmlWebpackPlugin({
  118. title: '管理员-客服管理',
  119. filename: 'admin/customerService.html',
  120. template: './template/template.html',
  121. chunks: ['admin/customerService', 'vendors'],
  122. }),
  123. //admin-set
  124. new HtmlWebpackPlugin({
  125. title: '管理员-用户管理',
  126. filename: 'admin/set.html',
  127. template: './template/template.html',
  128. chunks: ['admin/set', 'vendors'],
  129. }),
  130. new HtmlWebpackPlugin({
  131. title: '用户中心-科技服务',
  132. filename: 'user/account/services.html',
  133. template: './template/template.html',
  134. chunks: ['user/account/services', 'vendors'],
  135. }),
  136. new HtmlWebpackPlugin({
  137. title: '用户中心-科技服务',
  138. filename: 'user/account/achievement.html',
  139. template: './template/template.html',
  140. chunks: ['user/account/achievement', 'vendors'],
  141. }),
  142. new HtmlWebpackPlugin({
  143. title: '用户中心-科技服务',
  144. filename: 'user/account/demand.html',
  145. template: './template/template.html',
  146. chunks: ['user/account/demand', 'vendors'],
  147. }),
  148. //admin
  149. new HtmlWebpackPlugin({
  150. title: '管理员-首页',
  151. filename: 'admin/index.html',
  152. template: './template/template.html',
  153. chunks: ['admin/index', 'vendors'],
  154. }),
  155. new HtmlWebpackPlugin({
  156. title: '管理员-登录',
  157. filename: 'admin/login.html',
  158. template: './template/template.html',
  159. chunks: ['admin/login', 'vendors'],
  160. }),
  161. new HtmlWebpackPlugin({
  162. title: '管理员-用户管理',
  163. filename: 'admin/userManage.html',
  164. template: './template/template.html',
  165. chunks: ['admin/userManage', 'vendors'],
  166. }),
  167. //admin-servicesManage
  168. new HtmlWebpackPlugin({
  169. title: '管理员-科技服务管理-专利',
  170. filename: 'admin/servicesManage/contract.html',
  171. template: './template/template.html',
  172. chunks: ['admin/servicesManage/contract', 'vendors'],
  173. }),
  174. new HtmlWebpackPlugin({
  175. title: '管理员-科技服务管理-专利',
  176. filename: 'admin/servicesManage/patent.html',
  177. template: './template/template.html',
  178. chunks: ['admin/servicesManage/patent', 'vendors'],
  179. }),
  180. new HtmlWebpackPlugin({
  181. title: '管理员-科技服务管理-软著',
  182. filename: 'admin/servicesManage/copyright.html',
  183. template: './template/template.html',
  184. chunks: ['admin/servicesManage/copyright', 'vendors'],
  185. }),
  186. new HtmlWebpackPlugin({
  187. title: '管理员-科技服务管理-高企',
  188. filename: 'admin/servicesManage/highTech.html',
  189. template: './template/template.html',
  190. chunks: ['admin/servicesManage/highTech', 'vendors'],
  191. }),
  192. new HtmlWebpackPlugin({
  193. title: '管理员-科技服务管理-高企信息',
  194. filename: 'admin/servicesManage/highTechInfo.html',
  195. template: './template/template.html',
  196. chunks: ['admin/servicesManage/highTechInfo', 'vendors'],
  197. }),
  198. new HtmlWebpackPlugin({
  199. title: '管理员-科技服务管理-科技',
  200. filename: 'admin/servicesManage/technology.html',
  201. template: './template/template.html',
  202. chunks: ['admin/servicesManage/technology', 'vendors'],
  203. }),
  204. new HtmlWebpackPlugin({
  205. title: '管理员-科技服务管理-项目单',
  206. filename: 'admin/servicesManage/projectOrder.html',
  207. template: './template/template.html',
  208. chunks: ['admin/servicesManage/projectOrder', 'vendors'],
  209. }),
  210. //admin-demand
  211. new HtmlWebpackPlugin({
  212. title: '管理员-用户管理',
  213. filename: 'admin/demand.html',
  214. template: './template/template.html',
  215. chunks: ['admin/demand', 'vendors'],
  216. }),
  217. //admin-achievement
  218. new HtmlWebpackPlugin({
  219. title: '管理员-用户管理',
  220. filename: 'admin/achievement.html',
  221. template: './template/template.html',
  222. chunks: ['admin/achievement', 'vendors'],
  223. }),
  224. new HtmlWebpackPlugin({
  225. title: '管理员-用户管理',
  226. filename: 'admin/customer.html',
  227. template: './template/template.html',
  228. chunks: ['admin/customer', 'vendors'],
  229. }),
  230. //admin-set
  231. new HtmlWebpackPlugin({
  232. title: '管理员-用户管理',
  233. filename: 'admin/set.html',
  234. template: './template/template.html',
  235. chunks: ['admin/set', 'vendors'],
  236. }),
  237. //admin-idea
  238. new HtmlWebpackPlugin({
  239. title: '管理员-财务管理',
  240. filename: 'admin/idea.html',
  241. template: './template/template.html',
  242. chunks: ['admin/idea', 'vendors'],
  243. }),
  244. //admin-userOrder
  245. new HtmlWebpackPlugin({
  246. title: '管理员-用户订单管理',
  247. filename: 'admin/userOrder.html',
  248. template: './template/template.html',
  249. chunks: ['admin/userOrder', 'vendors'],
  250. }),
  251. new HtmlWebpackPlugin({
  252. title: '管理员-订单管理',
  253. filename: 'admin/order.html',
  254. template: './template/template.html',
  255. chunks: ['admin/order', 'vendors'],
  256. }),
  257. new HtmlWebpackPlugin({
  258. title: '管理员-法务系统',
  259. filename: 'admin/legalAffairs.html',
  260. template: './template/template.html',
  261. chunks: ['admin/legalAffairs', 'vendors'],
  262. }),
  263. new HtmlWebpackPlugin({
  264. title: '管理员-平台管理',
  265. filename: 'admin/operate.html',
  266. template: './template/template.html',
  267. chunks: ['admin/operate', 'vendors'],
  268. }), //statistics
  269. new HtmlWebpackPlugin({
  270. title: '管理员-数据统计',
  271. filename: 'admin/statistics.html',
  272. template: './template/template.html',
  273. chunks: ['admin/statistics', 'vendors'],
  274. }),
  275. new HtmlWebpackPlugin({
  276. title: '管理员-项目管理',
  277. filename: 'admin/project.html',
  278. template: './template/template.html',
  279. chunks: ['admin/project', 'vendors'],
  280. }),
  281. new HtmlWebpackPlugin({
  282. title: '管理员-人事管理',
  283. filename: 'admin/personnel.html',
  284. template: './template/template.html',
  285. chunks: ['admin/personnel', 'vendors'],
  286. }),
  287. new HtmlWebpackPlugin({
  288. title: '管理员-科技服务管理-科技评估信息',
  289. filename: 'user/account/evaluateInfo.html',
  290. template: './template/template.html',
  291. chunks: ['user/account/evaluateInfo', 'vendors'],
  292. }),
  293. //portal 门户
  294. // new HtmlWebpackPlugin({
  295. // title: '主页-需求搜索',
  296. // filename: 'portal/search/demand.html',
  297. // template: './template/template.html',
  298. // chunks: ['portal/search/demand', 'vendors']
  299. // }),
  300. // new HtmlWebpackPlugin({
  301. // title: '主页-科技成果搜索',
  302. // filename: 'portal/search/achievement.html',
  303. // template: './template/template.html',
  304. // chunks: ['portal/search/achievement', 'vendors']
  305. // }),
  306. // new HtmlWebpackPlugin({
  307. // title: '主页-行家搜索',
  308. // filename: 'portal/search/subscriberUser.html',
  309. // template: './template/template.html',
  310. // chunks: ['portal/search/subscriberUser', 'vendors']
  311. // }),
  312. // new HtmlWebpackPlugin({
  313. // title: '主页-伙伴搜索',
  314. // filename: 'portal/search/subscriberOrg.html',
  315. // template: './template/template.html',
  316. // chunks: ['portal/search/subscriberOrg', 'vendors']
  317. // })
  318. ]
  319. if (!isDev) {
  320. //这个使用uglifyJs压缩你的js代码
  321. plugins.unshift(
  322. new webpack.DefinePlugin({
  323. 'process.env': {
  324. NODE_ENV: JSON.stringify('production'),
  325. },
  326. })
  327. )
  328. plugins.unshift(
  329. new webpack.optimize.UglifyJsPlugin({
  330. minimize: true,
  331. compress: {
  332. warnings: true,
  333. },
  334. })
  335. )
  336. }
  337. //let staticHost = 'http://afts.hnzhiming.com';
  338. let staticHost = 'http://172.16.0.74:80'
  339. // let staticHost = "http://192.168.0.106";
  340. // let staticHost = "http://192.168.0.103";
  341. switch (argv.env.deploy) {
  342. case 'test':
  343. staticHost = 'http://static.jishutao.com'
  344. break
  345. case 'prod':
  346. staticHost = 'http://s.jishutao.com'
  347. break
  348. default:
  349. break
  350. }
  351. staticHost = staticHost + '/' + version + '/'
  352. theme['@icon-url'] = '"' + staticHost + 'css/iconfont/iconfont"'
  353. return {
  354. //devtool:"source-map",
  355. entry: isWatch ? entries.watch : entries.prod,
  356. output: {
  357. path: path.resolve(
  358. __dirname,
  359. './build/' + argv.env.deploy + '/' + version
  360. ),
  361. filename: '[name].js',
  362. publicPath: staticHost,
  363. chunkFilename: 'chunks/[name].[hash:8].js',
  364. },
  365. module: require('./webpack/module.config.js')(theme),
  366. resolve: {
  367. alias: {
  368. '@': __dirname + '/js/component',
  369. },
  370. extensions: ['.js', '.jsx'],
  371. },
  372. plugins: plugins,
  373. // devServer: {
  374. // disableHostCheck: true,
  375. // allowedHosts: ['bm.kedexinxi.com'],
  376. // headers: {
  377. // "Access-Control-Allow-Origin": "*"
  378. // }
  379. // }
  380. devServer: {
  381. disableHostCheck: true,
  382. host: '172.16.0.74',
  383. port: 80,
  384. allowedHosts: ['127.0.0.1', '192.168.0.20', '192.168.0.99'],
  385. headers: {
  386. 'Access-Control-Allow-Origin': '*',
  387. },
  388. },
  389. }
  390. })()