webpack-dll.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const webpack = require('webpack');
  2. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  3. const dirVars = require('./webpack/dir.config.js');
  4. var path = require('path');
  5. const version = require('./package.json').version;
  6. const argv = require('yargs').argv;
  7. let theme = {
  8. '@primary-color': '#58a3ff',
  9. '@link-color': '#58a3ff'
  10. };
  11. module.exports = (function () {
  12. let staticHost = 'http://192.168.0.188:8088';
  13. switch (argv.env.deploy) {
  14. case 'test':
  15. staticHost = 'http://statics.jishutao.com';
  16. break;
  17. case 'prod':
  18. staticHost = 'http://ss.jishutao.com';
  19. break;
  20. default:
  21. break;
  22. }
  23. staticHost = staticHost + '/client/' + version + '/';
  24. theme['@icon-url'] = '"' + staticHost + 'css/iconfont/iconfont"'
  25. var dllContext = path.resolve(dirVars.dllDir, './' + argv.env.deploy);
  26. return {
  27. output: {
  28. path: dllContext,
  29. filename: '[name].js',
  30. library: '[name]', // 当前Dll的所有内容都会存放在这个参数指定变量名的一个全局变量下,注意与DllPlugin的name参数保持一致
  31. },
  32. entry: {
  33. dll: [
  34. 'react', 'react-dom', 'antd', 'jquery/src/ajax/xhr.js', 'jquery/src/ajax', 'antd/lib/style'
  35. ],
  36. },
  37. plugins: [
  38. new webpack.DllPlugin({
  39. path: path.resolve(dllContext, 'manifest.json'), // 本Dll文件中各模块的索引,供DllReferencePlugin读取使用
  40. name: '[name]', // 当前Dll的所有内容都会存放在这个参数指定变量名的一个全局变量下,注意与参数output.library保持一致
  41. context: dirVars.staticRootDir, // 指定一个路径作为上下文环境,需要与DllReferencePlugin的context参数保持一致,建议统一设置为项目根目录
  42. }),
  43. new ExtractTextPlugin({
  44. filename: "[name].css",
  45. disable: false,
  46. allChunks: true
  47. }), // 打包css/less的时候会用到ExtractTextPlugin
  48. new webpack.optimize.UglifyJsPlugin({
  49. minimize: true,
  50. compress: {
  51. warnings: false,
  52. },
  53. }),
  54. new webpack.DefinePlugin({
  55. "process.env": {
  56. NODE_ENV: JSON.stringify("production")
  57. }
  58. })
  59. ],
  60. module: require('./webpack/module.config.js')(theme),
  61. resolve: {
  62. extensions: ['.js', '.jsx']
  63. }
  64. }
  65. })();