webpack.config.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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 ImageminPlugin = require('imagemin-webpack-plugin').default;
  10. let theme = {
  11. '@primary-color': '#58a3ff',
  12. '@link-color': '#58a3ff'
  13. };
  14. let isWatch = argv.env.watch == 'watch';
  15. let isDev = isWatch || argv.env.deploy == 'dev';
  16. module.exports = (function () {
  17. let plugins = [
  18. new webpack.optimize.CommonsChunkPlugin({
  19. name: 'vendors'
  20. }),
  21. new ExtractTextPlugin({
  22. filename: "[name].css",
  23. disable: false,
  24. allChunks: true
  25. }),
  26. new webpack.ProvidePlugin({
  27. $: "jquery",
  28. jQuery: "jquery"
  29. }),
  30. new HtmlWebpackPlugin({
  31. title: '首页',
  32. filename: 'html/index.html',
  33. template: './template/index.html',
  34. chunks: ['index', 'vendors']
  35. }),
  36. new HtmlWebpackPlugin({
  37. title: '搜索页',
  38. filename: 'html/index.html',
  39. template: './template/search.html',
  40. chunks: ['search', 'vendors']
  41. }),
  42. // new HtmlWebpackPlugin({
  43. // title: '支付跳转页面',
  44. // filename: 'html/toPayment.html',
  45. // template: './template/toPayment.html',
  46. // chunks: ['toPayment', 'vendors']
  47. // }),
  48. new HtmlWebpackPlugin({
  49. title: '关于公司',
  50. filename: 'html/aboutUs.html',
  51. template: './template/aboutUs.html',
  52. chunks: ['aboutUs', 'vendors']
  53. }),
  54. // new HtmlWebpackPlugin({
  55. // title: '关于公司APP',
  56. // filename: 'html/APPaboutUs.html',
  57. // template: './template/APPaboutUs.html',
  58. // chunks: ['APPaboutUs', 'vendors']
  59. // }),
  60. new HtmlWebpackPlugin({
  61. title: '联系我们',
  62. filename: 'html/contactUs.html',
  63. template: './template/contactUs.html',
  64. chunks: ['contactUs', 'vendors']
  65. }),
  66. // new HtmlWebpackPlugin({
  67. // title: '科技服务',
  68. // filename: 'html/service.html',
  69. // template: './template/service.html',
  70. // chunks: ['service', 'vendors']
  71. // }),
  72. new HtmlWebpackPlugin({
  73. title: '注册',
  74. filename: 'html/register.html',
  75. template: './template/register.html',
  76. chunks: ['register', 'vendors']
  77. }),
  78. // new HtmlWebpackPlugin({
  79. // title: '会员',
  80. // filename: 'html/member.html',
  81. // template: './template/member.html',
  82. // chunks: ['member', 'vendors']
  83. // }),
  84. // new HtmlWebpackPlugin({
  85. // title: '科技交易',
  86. // filename: 'html/technologyTrading.html',
  87. // template: './template/technologyTrading.html',
  88. // chunks: ['technologyTrading', 'vendors']
  89. // }),
  90. new HtmlWebpackPlugin({
  91. title: '科技智库',
  92. filename: 'html/thinkTank.html',
  93. template: './template/thinkTank.html',
  94. chunks: ['thinkTank', 'vendors']
  95. }),
  96. // new HtmlWebpackPlugin({
  97. // title: '科技金融',
  98. // filename: 'html/financialIndex.html',
  99. // template: './template/financialIndex.html',
  100. // chunks: ['financialIndex', 'vendors']
  101. // }),
  102. // new HtmlWebpackPlugin({
  103. // title: '科技交易-技术专利',
  104. // filename: 'html/technologyTrading/achievement.html',
  105. // template: './template/technologyTrading/achievement.html',
  106. // chunks: ['technologyTrading/achievement', 'vendors']
  107. // }),
  108. // new HtmlWebpackPlugin({
  109. // title: '科技交易-技术需求',
  110. // filename: 'html/technologyTrading/demand.html',
  111. // template: './template/technologyTrading/demand.html',
  112. // chunks: ['technologyTrading/demand', 'vendors']
  113. // }),
  114. new HtmlWebpackPlugin({
  115. title: '科技交易-技术专利详情',
  116. filename: 'html/technologyTrading/achievementDetail.html',
  117. template: './template/technologyTrading/achievementDetail.html',
  118. chunks: ['technologyTrading/achievementDetail', 'vendors']
  119. }),
  120. new HtmlWebpackPlugin({
  121. title: '科技交易-技术需求详情',
  122. filename: 'html/technologyTrading/demandDetail.html',
  123. template: './template/technologyTrading/demandDetail.html',
  124. chunks: ['technologyTrading/demandDetail', 'vendors']
  125. }),
  126. // new HtmlWebpackPlugin({
  127. // title: '在线评估',
  128. // filename: 'html/technologyTrading/assessMent.html',
  129. // template: './template/technologyTrading/assessMent.html',
  130. // chunks: ['technologyTrading/assessMent', 'vendors']
  131. // }),
  132. // new HtmlWebpackPlugin({
  133. // title: '科技交易-技术成果下单页面',
  134. // filename: 'html/technologyTrading/achievementOrder.html',
  135. // template: './template/technologyTrading/achievementOrder.html',
  136. // chunks: ['technologyTrading/achievementOrder', 'vendors']
  137. // }),
  138. // new HtmlWebpackPlugin({
  139. // title: '科技交易-技术需求下单页面',
  140. // filename: 'html/technologyTrading/demandOrder.html',
  141. // template: './template/technologyTrading/demandOrder.html',
  142. // chunks: ['technologyTrading/demandOrder', 'vendors']
  143. // }),
  144. new HtmlWebpackPlugin({
  145. title: '智库咨询-智政详情',
  146. filename: 'html/thinkTank/policyDetail.html',
  147. template: './template/thinkTank/policyDetail.html',
  148. chunks: ['thinkTank/policyDetail', 'vendors']
  149. }),
  150. new HtmlWebpackPlugin({
  151. title: '智库咨询-智政列表',
  152. filename: 'html/thinkTank/policyList.html',
  153. template: './template/thinkTank/policyList.html',
  154. chunks: ['thinkTank/policyList', 'vendors']
  155. }),
  156. new HtmlWebpackPlugin({
  157. title: '智库咨询-智者详情',
  158. filename: 'html/thinkTank/thinkerDetail.html',
  159. template: './template/thinkTank/thinkerDetail.html',
  160. chunks: ['thinkTank/thinkerDetail', 'vendors']
  161. }),
  162. // new HtmlWebpackPlugin({
  163. // title: '科技金融-投资机构',
  164. // filename: 'html/financial/investmentInstitution.html',
  165. // template: './template/financial/investmentInstitution.html',
  166. // chunks: ['financial/investmentInstitution', 'vendors']
  167. // }),
  168. // new HtmlWebpackPlugin({
  169. // title: '科技金融-投资机构',
  170. // filename: 'html/financial/investmentDetail.html',
  171. // template: './template/financial/investmentDetail.html',
  172. // chunks: ['financial/investmentDetail', 'vendors']
  173. // }),
  174. // new HtmlWebpackPlugin({
  175. // title: '科技服务-高新认定',
  176. // filename: 'html/service/highTechCognizance.html',
  177. // template: './template/service/highTechCognizance.html',
  178. // chunks: ['service/highTechCognizance', 'vendors']
  179. // }),
  180. // new HtmlWebpackPlugin({
  181. // title: '科技服务-知识产权',
  182. // filename: 'html/service/propertyRight.html',
  183. // template: './template/service/propertyRight.html',
  184. // chunks: ['service/propertyRight', 'vendors']
  185. // }),
  186. // new HtmlWebpackPlugin({
  187. // title: '科技服务-高新认定',
  188. // filename: 'html/service/projectDetails.html',
  189. // template: './template/service/projectDetails.html',
  190. // chunks: ['service/projectDetails', 'vendors']
  191. // }),
  192. // new HtmlWebpackPlugin({
  193. // title: '科技服务-服务意向',
  194. // filename: 'html/service/purpose.html',
  195. // template: './template/service/purpose.html',
  196. // chunks: ['service/purpose', 'vendors']
  197. // }),
  198. //newsApp
  199. new HtmlWebpackPlugin({
  200. title: '新闻详情',
  201. filename: 'html/news/newsDetailApp.html',
  202. template: './template/news/newsDetailApp.html',
  203. chunks: ['news/newsDetailApp', 'vendors']
  204. }),
  205. // new HtmlWebpackPlugin({
  206. // title: '高企认定',
  207. // filename: 'html/news/appCognizance.html',
  208. // template: './template/news/appCognizance.html',
  209. // chunks: ['news/appCognizance', 'vendors']
  210. // }),
  211. new HtmlWebpackPlugin({
  212. title: '注册协议',
  213. filename: 'html/news/agreement.html',
  214. template: './template/news/agreement.html',
  215. chunks: ['news/agreement', 'vendors']
  216. }),
  217. /* 2018-6 改版后科技需求 */
  218. new HtmlWebpackPlugin({
  219. title: '科技需求',
  220. filename: 'html/newMenu/demand.html',
  221. template: './template/newMenu/demand.html',
  222. chunks: ['newMenu/demand', 'vendors']
  223. }),
  224. new HtmlWebpackPlugin({
  225. title: '科技成果',
  226. filename: 'html/newMenu/achievement.html',
  227. template: './template/newMenu/achievement.html',
  228. chunks: ['newMenu/achievement', 'vendors']
  229. }),
  230. new HtmlWebpackPlugin({
  231. title: '科技成果列表',
  232. filename: 'html/newMenu/achievementList.html',
  233. template: './template/newMenu/achievementList.html',
  234. chunks: ['newMenu/achievementList', 'vendors']
  235. }),
  236. new HtmlWebpackPlugin({
  237. title: '科技需求列表',
  238. filename: 'html/newMenu/demandList.html',
  239. template: './template/newMenu/demandList.html',
  240. chunks: ['newMenu/demandList', 'vendors']
  241. }),
  242. new HtmlWebpackPlugin({
  243. title: '科技服务',
  244. filename: 'html/newMenu/services.html',
  245. template: './template/newMenu/services.html',
  246. chunks: ['newMenu/services', 'vendors']
  247. }),
  248. new HtmlWebpackPlugin({
  249. title: '科技服务列表',
  250. filename: 'html/newMenu/serviceList.html',
  251. template: './template/newMenu/serviceList.html',
  252. chunks: ['newMenu/serviceList', 'vendors']
  253. }),
  254. new HtmlWebpackPlugin({
  255. title: '科技服务详情',
  256. filename: 'html/newMenu/serviceDetails.html',
  257. template: './template/newMenu/serviceDetails.html',
  258. chunks: ['newMenu/serviceDetails', 'vendors']
  259. }),
  260. new HtmlWebpackPlugin({
  261. title: '购物车',
  262. filename: 'html/newMenu/shopList.html',
  263. template: './template/newMenu/shopList.html',
  264. chunks: ['newMenu/shopList', 'vendors']
  265. }),
  266. new HtmlWebpackPlugin({
  267. title: '专利列表',
  268. filename: 'html/newMenu/patentList.html',
  269. template: './template/newMenu/patentList.html',
  270. chunks: ['newMenu/patentList', 'vendors']
  271. }),
  272. new HtmlWebpackPlugin({
  273. title: '知识产权交易首页',
  274. filename: 'html/newMenu/tradingIndex.html',
  275. template: './template/newMenu/tradingIndex.html',
  276. chunks: ['newMenu/tradingIndex', 'vendors']
  277. }),
  278. new HtmlWebpackPlugin({
  279. title: '知识产权申请首页',
  280. filename: 'html/newMenu/patent.html',
  281. template: './template/newMenu/patent.html',
  282. chunks: ['newMenu/patent', 'vendors']
  283. }),
  284. new HtmlWebpackPlugin({
  285. title: '公司简介',
  286. filename: 'html/newMenu/companyProfile.html',
  287. template: './template/newMenu/companyProfile.html',
  288. chunks: ['newMenu/companyProfile', 'vendors']
  289. }),
  290. new HtmlWebpackPlugin({
  291. title: '高企认定',
  292. filename: 'html/newMenu/continueHigh.html',
  293. template: './template/newMenu/landingPage/continueHigh.html',
  294. chunks: ['newMenu/continueHigh', 'vendors']
  295. }),
  296. new HtmlWebpackPlugin({
  297. title: '实用新型专利',
  298. filename: 'html/newMenu/practicalPatent.html',
  299. template: './template/newMenu/landingPage/practicalPatent.html',
  300. chunks: ['newMenu/practicalPatent', 'vendors']
  301. }),
  302. new HtmlWebpackPlugin({
  303. title: '军工认证',
  304. filename: 'html/newMenu/militaryProject.html',
  305. template: './template/newMenu/landingPage/militaryProject.html',
  306. chunks: ['newMenu/militaryProject', 'vendors']
  307. }),
  308. // new HtmlWebpackPlugin({
  309. // title: '高企认定App',
  310. // filename: 'html/newMenu/continueHighApp.html',
  311. // template: './template/newMenu/landingPage/continueHighApp.html',
  312. // chunks: ['newMenu/continueHighApp', 'vendors']
  313. // }),
  314. // new HtmlWebpackPlugin({
  315. // title: '实用新型专利App',
  316. // filename: 'html/newMenu/practicalPatentApp.html',
  317. // template: './template/newMenu/landingPage/practicalPatentApp.html',
  318. // chunks: ['newMenu/practicalPatentApp', 'vendors']
  319. // }),
  320. // new HtmlWebpackPlugin({
  321. // title: '军工认证App',
  322. // filename: 'html/newMenu/militaryProjectApp.html',
  323. // template: './template/newMenu/landingPage/militaryProjectApp.html',
  324. // chunks: ['newMenu/militaryProjectApp', 'vendors']
  325. // }),
  326. new HtmlWebpackPlugin({
  327. title: '知识产权维权',
  328. filename: 'html/newMenu/safeguarding.html',
  329. template: './template/newMenu/safeguarding.html',
  330. chunks: ['newMenu/safeguarding', 'vendors']
  331. }),
  332. //app
  333. // new HtmlWebpackPlugin({
  334. // title: '评估',
  335. // filename: 'html/newMenu/app/assessment.html',
  336. // template: './template/newMenu/app/assessment.html',
  337. // chunks: ['newMenu/app/assessment', 'vendors']
  338. // }),
  339. // new HtmlWebpackPlugin({
  340. // title: '托管',
  341. // filename: 'html/newMenu/app/trusteeship.html',
  342. // template: './template/newMenu/app/trusteeship.html',
  343. // chunks: ['newMenu/app/trusteeship', 'vendors']
  344. // }),
  345. // new HtmlWebpackPlugin({
  346. // title: 'app维权',
  347. // filename: 'html/newMenu/app/safeguardApp.html',
  348. // template: './template/newMenu/app/safeguardApp.html',
  349. // chunks: ['newMenu/app/safeguardApp', 'vendors']
  350. // })
  351. ];
  352. if (!isDev) {
  353. //这个使用uglifyJs压缩你的js代码
  354. plugins.unshift(new webpack.DefinePlugin({
  355. "process.env": {
  356. NODE_ENV: JSON.stringify("production")
  357. }
  358. }));
  359. plugins.unshift(new webpack.optimize.UglifyJsPlugin({
  360. minimize: true,
  361. compress: {
  362. warnings: true
  363. }
  364. }));
  365. }
  366. let staticHost = 'http://192.168.0.190';
  367. switch (argv.env.deploy) {
  368. case 'test':
  369. staticHost = 'http://statics.jishutao.com';
  370. break;
  371. case 'prod':
  372. staticHost = 'http://ss.jishutao.com';
  373. break;
  374. default:
  375. break;
  376. }
  377. staticHost = staticHost + '/portal/' + version + '/';
  378. return {
  379. entry: isWatch ? entries.watch : entries.prod,
  380. output: {
  381. path: path.resolve(__dirname, './build/' + argv.env.deploy + '/' + version),
  382. filename: '[name].js',
  383. publicPath: staticHost,
  384. chunkFilename: 'chunks/[name].[hash:8].js'
  385. },
  386. module: require('./webpack/module.config.js')(theme),
  387. resolve: {
  388. extensions: ['.js', '.jsx'],
  389. alias:{
  390. 'js':__dirname+'/src/js',
  391. 'css':__dirname+'/src/css',
  392. 'imgs':__dirname+'/img'
  393. }
  394. },
  395. plugins: plugins,
  396. devServer: {
  397. disableHostCheck: true,
  398. host: '192.168.0.190',
  399. port: 80,
  400. allowedHosts: ['127.0.0.1','192.168.0.99'],
  401. headers: {
  402. "Access-Control-Allow-Origin": "*"
  403. }
  404. }
  405. };
  406. })();