webpack-dll.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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://172.16.0.254';
  13. switch (argv.env.deploy) {
  14. case 'test':
  15. staticHost = 'http://statics.jishutao.com';
  16. break;
  17. case 'prod':
  18. staticHost = 'http://kedejs.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'),
  40. name: '[name]',
  41. context: dirVars.staticRootDir,
  42. /*
  43. 当前Dll的所有内容都会存放在这个参数指定变量名的一个全局变量下,注意与参数output.library保持一致
  44. 指定一个路径作为上下文环境,需要与DllReferencePlugin的context参数保持一致,建议统一设置为项目根目录
  45. 这个配置文件的含义是指将enty中的dll[]中的内容 打包进react.dll.js这个文件中
  46. */
  47. }),
  48. new ExtractTextPlugin({
  49. filename: "[name].css",
  50. disable: false,
  51. allChunks: true
  52. }), // 打包css/less的时候会用到ExtractTextPlugin
  53. new webpack.optimize.UglifyJsPlugin({
  54. minimize: true,
  55. compress: {
  56. warnings: false,
  57. },
  58. }),
  59. new webpack.DefinePlugin({
  60. "process.env": {
  61. NODE_ENV: JSON.stringify("production")
  62. }
  63. })
  64. ],
  65. module: require('./webpack/module.config.js')(theme),
  66. resolve: {
  67. extensions: ['.js', '.jsx']
  68. }
  69. }
  70. })();