webpack.config.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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/channelList.html',
  266. template: './template/template.html',
  267. chunks: ['admin/channelList', 'vendors'],
  268. }),
  269. new HtmlWebpackPlugin({
  270. title: '管理员-查询管理',
  271. filename: 'admin/povertyInquiry.html',
  272. template: './template/template.html',
  273. chunks: ['admin/povertyInquiry', 'vendors'],
  274. }),
  275. new HtmlWebpackPlugin({
  276. title: '管理员-平台管理',
  277. filename: 'admin/operate.html',
  278. template: './template/template.html',
  279. chunks: ['admin/operate', 'vendors'],
  280. }),
  281. new HtmlWebpackPlugin({
  282. title: '管理员-阿米巴',
  283. filename: 'admin/amiba.html',
  284. template: './template/template.html',
  285. chunks: ['admin/amiba', 'vendors'],
  286. }),
  287. //statistics
  288. new HtmlWebpackPlugin({
  289. title: '管理员-数据统计',
  290. filename: 'admin/statistics.html',
  291. template: './template/template.html',
  292. chunks: ['admin/statistics', 'vendors'],
  293. }),
  294. new HtmlWebpackPlugin({
  295. title: '管理员-项目管理',
  296. filename: 'admin/project.html',
  297. template: './template/template.html',
  298. chunks: ['admin/project', 'vendors'],
  299. }),
  300. new HtmlWebpackPlugin({
  301. title: '管理员-人事管理',
  302. filename: 'admin/personnel.html',
  303. template: './template/template.html',
  304. chunks: ['admin/personnel', 'vendors'],
  305. }),
  306. new HtmlWebpackPlugin({
  307. title: '管理员-科技服务管理-科技评估信息',
  308. filename: 'user/account/evaluateInfo.html',
  309. template: './template/template.html',
  310. chunks: ['user/account/evaluateInfo', 'vendors'],
  311. }),
  312. new HtmlWebpackPlugin({
  313. title: '管理员-标准管理',
  314. filename: 'admin/standard.html',
  315. template: './template/template.html',
  316. chunks: ['admin/standard', 'vendors'],
  317. }),
  318. //portal 门户
  319. // new HtmlWebpackPlugin({
  320. // title: '主页-需求搜索',
  321. // filename: 'portal/search/demand.html',
  322. // template: './template/template.html',
  323. // chunks: ['portal/search/demand', 'vendors']
  324. // }),
  325. // new HtmlWebpackPlugin({
  326. // title: '主页-科技成果搜索',
  327. // filename: 'portal/search/achievement.html',
  328. // template: './template/template.html',
  329. // chunks: ['portal/search/achievement', 'vendors']
  330. // }),
  331. // new HtmlWebpackPlugin({
  332. // title: '主页-行家搜索',
  333. // filename: 'portal/search/subscriberUser.html',
  334. // template: './template/template.html',
  335. // chunks: ['portal/search/subscriberUser', 'vendors']
  336. // }),
  337. // new HtmlWebpackPlugin({
  338. // title: '主页-伙伴搜索',
  339. // filename: 'portal/search/subscriberOrg.html',
  340. // template: './template/template.html',
  341. // chunks: ['portal/search/subscriberOrg', 'vendors']
  342. // })
  343. ]
  344. if (!isDev) {
  345. //这个使用uglifyJs压缩你的js代码
  346. plugins.unshift(
  347. new webpack.DefinePlugin({
  348. 'process.env': {
  349. NODE_ENV: JSON.stringify('production'),
  350. },
  351. })
  352. )
  353. plugins.unshift(
  354. new webpack.optimize.UglifyJsPlugin({
  355. minimize: true,
  356. compress: {
  357. warnings: true,
  358. },
  359. })
  360. )
  361. }
  362. //let staticHost = 'http://afts.hnzhiming.com';
  363. let staticHost = 'http://172.16.1.187:80'
  364. // let staticHost = "http://192.168.0.106";
  365. // let staticHost = "http://192.168.0.103";
  366. switch (argv.env.deploy) {
  367. case 'test':
  368. staticHost = '//static.jishutao.com'
  369. break
  370. case 'prod':
  371. staticHost = '//s.jishutao.com'
  372. break
  373. default:
  374. break
  375. }
  376. staticHost = staticHost + '/' + version + '/'
  377. theme['@icon-url'] = '"' + staticHost + 'css/iconfont/iconfont"'
  378. return {
  379. //devtool:"source-map",
  380. entry: isWatch ? entries.watch : entries.prod,
  381. output: {
  382. path: path.resolve(
  383. __dirname,
  384. './build/' + argv.env.deploy + '/' + version
  385. ),
  386. filename: '[name].js',
  387. publicPath: staticHost,
  388. chunkFilename: 'chunks/[name].[hash:8].js',
  389. },
  390. module: require('./webpack/module.config.js')(theme),
  391. resolve: {
  392. alias: {
  393. '@': __dirname + '/js/component',
  394. },
  395. extensions: ['.js', '.jsx'],
  396. },
  397. plugins: plugins,
  398. // devServer: {
  399. // disableHostCheck: true,
  400. // allowedHosts: ['bm.kedexinxi.com'],
  401. // headers: {
  402. // "Access-Control-Allow-Origin": "*"
  403. // }
  404. // }
  405. devServer: {
  406. disableHostCheck: true,
  407. host: '172.16.1.187',
  408. port: 80,
  409. allowedHosts: ['127.0.0.1', '192.168.0.20', '192.168.0.99'],
  410. headers: {
  411. 'Access-Control-Allow-Origin': '*',
  412. },
  413. },
  414. }
  415. })()