webpack-dll.config.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.1.187';
  13. switch (argv.env.deploy) {
  14. case 'test':
  15. staticHost = 'http://statics.jishutao.com';
  16. break;
  17. case 'prod':
  18. staticHost = 'http://js.junbangjishu.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. 'jquery/dist/jquery.min.js',
  35. 'bootstrap/dist/css/bootstrap.css',
  36. ],
  37. },
  38. plugins: [
  39. new webpack.DllPlugin({
  40. path: path.resolve(dllContext, 'manifest.json'), // 本Dll文件中各模块的索引,供DllReferencePlugin读取使用
  41. name: '[name]', // 当前Dll的所有内容都会存放在这个参数指定变量名的一个全局变量下,注意与参数output.library保持一致
  42. context: dirVars.staticRootDir, // 指定一个路径作为上下文环境,需要与DllReferencePlugin的context参数保持一致,建议统一设置为项目根目录
  43. }),
  44. new ExtractTextPlugin({
  45. filename: "[name].css",
  46. disable: false,
  47. allChunks: true
  48. }), // 打包css/less的时候会用到ExtractTextPlugin
  49. new webpack.optimize.UglifyJsPlugin({
  50. minimize: true,
  51. compress: {
  52. warnings: false,
  53. },
  54. }),
  55. new webpack.DefinePlugin({
  56. "process.env": {
  57. NODE_ENV: JSON.stringify("production")
  58. }
  59. })
  60. ],
  61. module: require('./webpack/module.config.js')(theme),
  62. resolve: {
  63. extensions: ['.js', '.jsx']
  64. }
  65. }
  66. })();