Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 atool-build打包dva 项目生成的文件比较大,有优化方案吗? #253

Closed
xflife opened this issue Feb 8, 2017 · 1 comment

Comments

@xflife
Copy link

xflife commented Feb 8, 2017

下图是我的 webpack.config.js

const webpack = require('atool-build/lib/webpack');

module.exports = function (webpackConfig, env) {
  webpackConfig.babel.plugins.push('transform-runtime');
  //babel-plugin-import 是用来按需加载 antd 的脚本和样式的
  webpackConfig.babel.plugins.push(['import', {
    libraryName: 'antd',
    style: 'css',
  }]);

  // Support hmr
  if (env === 'development') {
    webpackConfig.devtool = '#eval';
    webpackConfig.babel.plugins.push('dva-hmr');
  } else {
    webpackConfig.babel.plugins.push('dev-expression');
    webpackConfig.plugins.some(function(plugin, i) {
      if (plugin instanceof webpack.optimize.UglifyJsPlugin) {
        webpackConfig.plugins.splice(i, 1);
        return true;
      }
    });
    var os = require('os');
    var options = {
      workers: os.cpus().length,
      output: {
        ascii_only: true,
      },
      compress: {
        warnings: false,
      },
      sourceMap: false
    }
    var UglifyJsParallelPlugin = require('webpack-uglify-parallel');
    webpackConfig.plugins.push(
      new UglifyJsParallelPlugin(options)
    );
  }
  // Don't extract common.js and common.css
  webpackConfig.plugins = webpackConfig.plugins.filter(function (plugin) {
    return !(plugin instanceof webpack.optimize.CommonsChunkPlugin);
  });

  // Support CSS Modules
  // Parse all less files as css module.
  webpackConfig.module.loaders.forEach(function (loader, index) {
    if (typeof loader.test === 'function' && loader.test.toString().indexOf('\\.less$') > -1) {
      loader.include = /node_modules/;
      loader.test = /\.less$/;
    }
    if (loader.test.toString() === '/\\.module\\.less$/') {
      loader.exclude = /node_modules/;
      loader.test = /\.less$/;
    }
    if (typeof loader.test === 'function' && loader.test.toString().indexOf('\\.css$') > -1) {
      loader.include = /node_modules/;
      loader.test = /\.css$/;
    }
    if (loader.test.toString() === '/\\.module\\.css$/') {
      loader.exclude = /node_modules/;
      loader.test = /\.css$/;
    }
  });


  webpackConfig.module.loaders.push({
    test   : /\.woff/,
    loader : 'url?prefix=font/&limit=10000&mimetype=application/font-woff'
  })
  webpackConfig.module.loaders.push({
    test   : /\.ttf/,
    loader : 'file?prefix=font/'
  })
  webpackConfig.module.loaders.push({
    test   : /\.eot/,
    loader : 'file?prefix=font/'
  })
  webpackConfig.module.loaders.push({
    test   : /\.svg/,
    loader : 'file?prefix=font/'
  })
  
  return webpackConfig;
};
@soda-x
Copy link

soda-x commented Feb 23, 2017

问题有点宽泛 - 请查看个人 blog soda-x/blog#1

@soda-x soda-x closed this as completed Apr 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants