怎么关闭 rollup 的摇树?

我已经配置了关闭 摇树 但是还是把没有依赖的文件筛掉

export default {
  input: `${input}/index.ts`,
  external: ['vue', 'element-plus', 'calendar-ts', '@element-plus/icons-vue'],
  plugins: [
    clear({ targets: ['dist'] }),
    vue(),
    typescript({
      useTsconfigDeclarationDir: false,
      tsconfigOverride: {
        exclude: ["node_modules", "examples", "tests"]
      },
      abortOnError: false,
      clean: true
    })
  ],
  treeshake: false,
  output: {
    dir: `${output}/es`,
    format: "es",
    // preserveModules: true,
  }
}
阅读 1.9k
1 个回答

rollup.config.js

export default [
  {
    input: "src/index.js",
    external: ["lodash"],
    treeshake: false,
    output: {
      file: "dist/index.js",
      format: "umd",
      globals: {
        lodash: "_",
      },
    },
  },
];

src/index.js

import _ from "lodash";

console.log(_.add(1, 2));

打包后
dist/index.js

(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('lodash')) :
    typeof define === 'function' && define.amd ? define(['lodash'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global._));
})(this, (function (_) { 'use strict';

    console.log(_.add(1, 2));

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