webpack.config.js 3.7 KB

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