1

lodash-es使用 ES6 导入语法时,我无法进行 tree-shaking 。例如,以下似乎包括所有 lodash:

import { isArray} from 'lodash-es';

我正在使用以下 lodash 配置:

import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import pkg from './package.json';

const extensions = [
  '.js', '.jsx', '.ts', '.tsx',
];

const name = 'RollupTypeScriptBabel';

export default {
  input: './src/index.ts',

  // Specify here external modules which you don't want to include in your bundle (for instance: 'lodash', 'moment' etc.)
  // https://rollupjs.org/guide/en#external-e-external
  external: [],

  plugins: [
    // Allows node_modules resolution
    resolve({ extensions }),

    // Allow bundling cjs modules. Rollup doesn't understand cjs
    commonjs(),

    // Compile TypeScript/JavaScript files
    babel({ extensions, include: ['src/**/*'] }),
  ],

  output: [{
    file: pkg.main,
    format: 'cjs',
  }, {
    file: pkg.module,
    format: 'es',
  }]
};

如果有人想尝试一下,我会设置一个测试仓库:https ://github.com/jclangst/rollup-typescript-babel 。

我已经尝试了所有方法,包括其他 ES6 兼容库lodash-es,但没有任何效果。我做错了什么阻止摇晃树?

4

0 回答 0