webpack.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. ];
  46. if (!isDev) {
  47. //这个使用uglifyJs压缩你的js代码
  48. plugins.unshift(new webpack.DefinePlugin({
  49. "process.env": {
  50. NODE_ENV: JSON.stringify("production")
  51. }
  52. }));
  53. plugins.unshift(new webpack.optimize.UglifyJsPlugin({
  54. minimize: true,
  55. compress: {
  56. warnings: true
  57. }
  58. }));
  59. }
  60. //let staticHost = 'http://aftts.hnzhiming.com';
  61. //let staticHost = 'http://afts.hnzhiming.com';
  62. let staticHost = 'http://127.0.0.1';
  63. switch (argv.env.deploy) {
  64. case 'test':
  65. staticHost = 'http://afts.hnzhiming.com';
  66. break;
  67. case 'stage':
  68. staticHost = 'http://aftts.hnzhiming.com';
  69. break;
  70. case 'prod':
  71. staticHost = 'http://s.jishutao.com';
  72. break;
  73. default:
  74. break;
  75. }
  76. staticHost = staticHost + '/portal/' + version + '/';
  77. return {
  78. entry: isWatch ? entries.watch : entries.prod,
  79. output: {
  80. path: path.resolve(__dirname, './build/' + argv.env.deploy + '/' + version),
  81. filename: '[name].js',
  82. publicPath: staticHost,
  83. chunkFilename: 'chunks/[name].[hash:8].js'
  84. },
  85. module: require('./webpack/module.config.js')(theme),
  86. resolve: {
  87. extensions: ['.js', '.jsx']
  88. },
  89. plugins: plugins,
  90. devServer: {
  91. disableHostCheck: true,
  92. //allowedHosts: ['aft.hnzhiming.com', 'afts.hnzhiming.com'],
  93. headers: {
  94. "Access-Control-Allow-Origin": "*"
  95. }
  96. }
  97. };
  98. })();