webpack2.1 Tree-shaking 无效?

// index.js
const a = require('./a')
a.a1();

//a.js
exports.a1 = function () {
    console.log('a1');
}

exports.a2 = function () {
    console.log('a2');
}

exports.a3 = function () {
    console.log('a3');
}
// webpack.config.js
var webpack = require('webpack');

module.exports = {
    entry: {"index":"./index.js"},
    output: {
        filename  : '[name].js',
    },
    module: {
        rules: [
        ]
    },  
    resolve: {
        extensions:['.js', '.json', 'scss'],
    },
};

执行 webpack 发现打包出来代码,还包括 a2, a3

阅读 4.2k
2 个回答

Tree-shaking 是基于 es6 modules 的静态分析的。你这个是 commonjs 的模块当然没有用了。关于Tree-shaking

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题