小编use*_*473的帖子

Webpack 树抖动仍然捆绑未使用的导出

我正在尝试测试 Webpack 的摇树功能,但它似乎不起作用。

这是我的文件:

  • index.ts
import { good } from './exports';
console.log(good);
Run Code Online (Sandbox Code Playgroud)
  • exports.ts
export const good = 'good';
export const secret = 'iamasecret';
Run Code Online (Sandbox Code Playgroud)
  • tsconfig.json
{}
Run Code Online (Sandbox Code Playgroud)
  • webpack.config.ts
import { Configuration } from 'webpack';
import  * as TerserPlugin from "terser-webpack-plugin";
const config: Configuration = {
    mode: 'production',
    entry: './index.ts',
    module: {
        rules: [
          {
            test: /\.tsx?$/,
            use: 'ts-loader',
            exclude: /node_modules/,
          },
        ],
      },
      resolve: {
        extensions: [ '.tsx', '.ts', '.js' ]
      },
      optimization: {
        usedExports: true,
        minimizer: [new TerserPlugin()],
      }
}
export …
Run Code Online (Sandbox Code Playgroud)

bundler typescript webpack tree-shaking

5
推荐指数
1
解决办法
1946
查看次数

标签 统计

bundler ×1

tree-shaking ×1

typescript ×1

webpack ×1