webpack.config.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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/toPayment.html',
  39. template: './template/toPayment.html',
  40. chunks: ['toPayment', 'vendors']
  41. }),
  42. new HtmlWebpackPlugin({
  43. title: '科技服务',
  44. filename: 'html/service.html',
  45. template: './template/service.html',
  46. chunks: ['service', 'vendors']
  47. }),
  48. new HtmlWebpackPlugin({
  49. title: '注册',
  50. filename: 'html/register.html',
  51. template: './template/register.html',
  52. chunks: ['register', 'vendors']
  53. }),
  54. new HtmlWebpackPlugin({
  55. title: '会员',
  56. filename: 'html/member.html',
  57. template: './template/member.html',
  58. chunks: ['member', 'vendors']
  59. }),
  60. new HtmlWebpackPlugin({
  61. title: '科技交易',
  62. filename: 'html/technologyTrading.html',
  63. template: './template/technologyTrading.html',
  64. chunks: ['technologyTrading', 'vendors']
  65. }),
  66. new HtmlWebpackPlugin({
  67. title: '科技智库',
  68. filename: 'html/thinkTank.html',
  69. template: './template/thinkTank.html',
  70. chunks: ['thinkTank', 'vendors']
  71. }),
  72. new HtmlWebpackPlugin({
  73. title: '科技金融',
  74. filename: 'html/financialIndex.html',
  75. template: './template/financialIndex.html',
  76. chunks: ['financialIndex', 'vendors']
  77. }),
  78. new HtmlWebpackPlugin({
  79. title: '科技交易-技术专利',
  80. filename: 'html/technologyTrading/achievement.html',
  81. template: './template/technologyTrading/achievement.html',
  82. chunks: ['technologyTrading/achievement', 'vendors']
  83. }),
  84. new HtmlWebpackPlugin({
  85. title: '科技交易-技术需求',
  86. filename: 'html/technologyTrading/demand.html',
  87. template: './template/technologyTrading/demand.html',
  88. chunks: ['technologyTrading/demand', 'vendors']
  89. }),
  90. new HtmlWebpackPlugin({
  91. title: '科技交易-技术专利详情',
  92. filename: 'html/technologyTrading/achievementDetail.html',
  93. template: './template/technologyTrading/achievementDetail.html',
  94. chunks: ['technologyTrading/achievementDetail', 'vendors']
  95. }),
  96. new HtmlWebpackPlugin({
  97. title: '科技交易-技术需求详情',
  98. filename: 'html/technologyTrading/demandDetail.html',
  99. template: './template/technologyTrading/demandDetail.html',
  100. chunks: ['technologyTrading/demandDetail', 'vendors']
  101. }),
  102. new HtmlWebpackPlugin({
  103. title: '科技交易-技术成果下单页面',
  104. filename: 'html/technologyTrading/achievementOrder.html',
  105. template: './template/technologyTrading/achievementOrder.html',
  106. chunks: ['technologyTrading/achievementOrder', 'vendors']
  107. }),
  108. new HtmlWebpackPlugin({
  109. title: '科技交易-技术需求下单页面',
  110. filename: 'html/technologyTrading/demandOrder.html',
  111. template: './template/technologyTrading/demandOrder.html',
  112. chunks: ['technologyTrading/demandOrder', 'vendors']
  113. }),
  114. new HtmlWebpackPlugin({
  115. title: '智库咨询-智政详情',
  116. filename: 'html/thinkTank/policyDetail.html',
  117. template: './template/thinkTank/policyDetail.html',
  118. chunks: ['thinkTank/policyDetail', 'vendors']
  119. }),
  120. new HtmlWebpackPlugin({
  121. title: '智库咨询-智政列表',
  122. filename: 'html/thinkTank/policyList.html',
  123. template: './template/thinkTank/policyList.html',
  124. chunks: ['thinkTank/policyList', 'vendors']
  125. }),
  126. new HtmlWebpackPlugin({
  127. title: '智库咨询-智者详情',
  128. filename: 'html/thinkTank/thinkerDetail.html',
  129. template: './template/thinkTank/thinkerDetail.html',
  130. chunks: ['thinkTank/thinkerDetail', 'vendors']
  131. }),
  132. new HtmlWebpackPlugin({
  133. title: '科技金融-投资机构',
  134. filename: 'html/financial/investmentInstitution.html',
  135. template: './template/financial/investmentInstitution.html',
  136. chunks: ['financial/investmentInstitution', 'vendors']
  137. }),
  138. new HtmlWebpackPlugin({
  139. title: '科技金融-投资机构',
  140. filename: 'html/financial/investmentDetail.html',
  141. template: './template/financial/investmentDetail.html',
  142. chunks: ['financial/investmentDetail', 'vendors']
  143. }),
  144. new HtmlWebpackPlugin({
  145. title: '科技服务-高新认定',
  146. filename: 'html/service/highTechCognizance.html',
  147. template: './template/service/highTechCognizance.html',
  148. chunks: ['service/highTechCognizance', 'vendors']
  149. }),
  150. new HtmlWebpackPlugin({
  151. title: '科技服务-知识产权',
  152. filename: 'html/service/propertyRight.html',
  153. template: './template/service/propertyRight.html',
  154. chunks: ['service/propertyRight', 'vendors']
  155. }),
  156. //newsApp
  157. new HtmlWebpackPlugin({
  158. title: '新闻详情',
  159. filename: 'html/news/newsDetailApp.html',
  160. template: './template/news/newsDetailApp.html',
  161. chunks: ['news/newsDetailApp', 'vendors']
  162. }),
  163. ];
  164. if (!isDev) {
  165. //这个使用uglifyJs压缩你的js代码
  166. plugins.unshift(new webpack.DefinePlugin({
  167. "process.env": {
  168. NODE_ENV: JSON.stringify("production")
  169. }
  170. }));
  171. plugins.unshift(new webpack.optimize.UglifyJsPlugin({
  172. minimize: true,
  173. compress: {
  174. warnings: true
  175. }
  176. }));
  177. }
  178. //let staticHost = 'http://aftts.hnzhiming.com';
  179. //let staticHost = 'http://afts.hnzhiming.com';
  180. let staticHost = 'http://127.0.0.1';
  181. switch (argv.env.deploy) {
  182. case 'test':
  183. staticHost = 'http://static.jishutao.com';
  184. break;
  185. case 'stage':
  186. staticHost = 'http://afts.hnzhiming.com';
  187. break;
  188. case 'prod':
  189. staticHost = 'http://s.jishutao.com';
  190. break;
  191. default:
  192. break;
  193. }
  194. staticHost = staticHost + '/portal/' + version + '/';
  195. return {
  196. entry: isWatch ? entries.watch : entries.prod,
  197. output: {
  198. path: path.resolve(__dirname, './build/' + argv.env.deploy + '/' + version),
  199. filename: '[name].js',
  200. publicPath: staticHost,
  201. chunkFilename: 'chunks/[name].[hash:8].js'
  202. },
  203. module: require('./webpack/module.config.js')(theme),
  204. resolve: {
  205. extensions: ['.js', '.jsx']
  206. },
  207. plugins: plugins,
  208. devServer: {
  209. disableHostCheck: true,
  210. //allowedHosts: ['aft.hnzhiming.com', 'afts.hnzhiming.com'],
  211. headers: {
  212. "Access-Control-Allow-Origin": "*"
  213. }
  214. }
  215. };
  216. })();