webpack.config.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. ];
  70. if (!isDev) {
  71. //这个使用uglifyJs压缩你的js代码
  72. plugins.unshift(new webpack.DefinePlugin({
  73. "process.env": {
  74. NODE_ENV: JSON.stringify("production")
  75. }
  76. }));
  77. plugins.unshift(new webpack.optimize.UglifyJsPlugin({
  78. minimize: true,
  79. compress: {
  80. warnings: true
  81. }
  82. }));
  83. }
  84. //let staticHost = 'http://aftts.hnzhiming.com';
  85. //let staticHost = 'http://afts.hnzhiming.com';
  86. let staticHost = 'http://127.0.0.1';
  87. switch (argv.env.deploy) {
  88. case 'test':
  89. staticHost = 'http://static.jishutao.com';
  90. break;
  91. case 'stage':
  92. staticHost = 'http://aftts.hnzhiming.com';
  93. break;
  94. case 'prod':
  95. staticHost = 'http://s.jishutao.com';
  96. break;
  97. default:
  98. break;
  99. }
  100. staticHost = staticHost + '/portal/' + version + '/';
  101. return {
  102. entry: isWatch ? entries.watch : entries.prod,
  103. output: {
  104. path: path.resolve(__dirname, './build/' + argv.env.deploy + '/' + version),
  105. filename: '[name].js',
  106. publicPath: staticHost,
  107. chunkFilename: 'chunks/[name].[hash:8].js'
  108. },
  109. module: require('./webpack/module.config.js')(theme),
  110. resolve: {
  111. extensions: ['.js', '.jsx']
  112. },
  113. plugins: plugins,
  114. devServer: {
  115. disableHostCheck: true,
  116. //allowedHosts: ['aft.hnzhiming.com', 'afts.hnzhiming.com'],
  117. headers: {
  118. "Access-Control-Allow-Origin": "*"
  119. }
  120. }
  121. };
  122. })();