webpack.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. //把入口文件里面的数组打包成verdors.js
  19. // new ImageminPlugin({
  20. // disable: isDev,
  21. // test: 'img/**',
  22. // pngquant: {
  23. // quality: '75-75',
  24. // optimizationLevel: 9
  25. // }
  26. // }),
  27. new webpack.optimize.CommonsChunkPlugin({
  28. name: 'vendors'
  29. }),
  30. new ExtractTextPlugin({
  31. filename: "[name].css",
  32. disable: false,
  33. allChunks: true
  34. }),
  35. new webpack.ProvidePlugin({
  36. $: "jquery",
  37. jQuery: "jquery"
  38. }),
  39. new HtmlWebpackPlugin({
  40. title: '首页',
  41. filename: 'html/index.html',
  42. template: './template/index.html',
  43. chunks: ['index', 'vendors']
  44. }),
  45. new HtmlWebpackPlugin({
  46. title: '科技服务',
  47. filename: 'html/service.html',
  48. template: './template/service.html',
  49. chunks: ['service', 'vendors']
  50. }),
  51. new HtmlWebpackPlugin({
  52. title: '注册',
  53. filename: 'html/register.html',
  54. template: './template/register.html',
  55. chunks: ['register', 'vendors']
  56. }),
  57. new HtmlWebpackPlugin({
  58. title: '科技交易',
  59. filename: 'html/technologyTrading.html',
  60. template: './template/technologyTrading.html',
  61. chunks: ['technologyTrading', 'vendors']
  62. }),
  63. new HtmlWebpackPlugin({
  64. title: '科技智库',
  65. filename: 'html/thinkTank.html',
  66. template: './template/thinkTank.html',
  67. chunks: ['thinkTank', 'vendors']
  68. }),
  69. new HtmlWebpackPlugin({
  70. title: '科技智库',
  71. filename: 'html/technologyFinancial.html',
  72. template: './template/technologyFinancial.html',
  73. chunks: ['technologyFinancial', 'vendors']
  74. }),
  75. new HtmlWebpackPlugin({
  76. title: '科技交易-技术专利',
  77. filename: 'html/technologyTrading/achievement.html',
  78. template: './template/technologyTrading/achievement.html',
  79. chunks: ['technologyTrading/achievement', 'vendors']
  80. }),
  81. new HtmlWebpackPlugin({
  82. title: '科技交易-技术需求',
  83. filename: 'html/technologyTrading/demand.html',
  84. template: './template/technologyTrading/demand.html',
  85. chunks: ['technologyTrading/demand', 'vendors']
  86. }),
  87. ];
  88. if (!isDev) {
  89. //这个使用uglifyJs压缩你的js代码
  90. plugins.unshift(new webpack.DefinePlugin({
  91. "process.env": {
  92. NODE_ENV: JSON.stringify("production")
  93. }
  94. }));
  95. plugins.unshift(new webpack.optimize.UglifyJsPlugin({
  96. minimize: true,
  97. compress: {
  98. warnings: true
  99. }
  100. }));
  101. }
  102. //let staticHost = 'http://aftts.hnzhiming.com';
  103. //let staticHost = 'http://afts.hnzhiming.com';
  104. let staticHost = 'http://127.0.0.1';
  105. switch (argv.env.deploy) {
  106. case 'test':
  107. staticHost = 'http://static.jishutao.com';
  108. break;
  109. case 'stage':
  110. staticHost = 'http://aftts.hnzhiming.com';
  111. break;
  112. case 'prod':
  113. staticHost = 'http://s.jishutao.com';
  114. break;
  115. default:
  116. break;
  117. }
  118. staticHost = staticHost + '/portal/' + version + '/';
  119. return {
  120. entry: isWatch ? entries.watch : entries.prod,
  121. output: {
  122. path: path.resolve(__dirname, './build/' + argv.env.deploy + '/' + version),
  123. filename: '[name].js',
  124. publicPath: staticHost,
  125. chunkFilename: 'chunks/[name].[hash:8].js'
  126. },
  127. module: require('./webpack/module.config.js')(theme),
  128. resolve: {
  129. extensions: ['.js', '.jsx']
  130. },
  131. plugins: plugins,
  132. devServer: {
  133. disableHostCheck: true,
  134. //allowedHosts: ['aft.hnzhiming.com', 'afts.hnzhiming.com'],
  135. headers: {
  136. "Access-Control-Allow-Origin": "*"
  137. }
  138. }
  139. };
  140. })();