我的 terser-webpack-plugin 有问题,我无法缩小我的包,错误是
我有“terser-webpack-plugin”的版本:“4.2.3”,“webpack”:“^4.33.0”,“clean-webpack-plugin”:“^3.0.0”,“dotenv-webpack” ": "^1.7.0" 和 React 17.0.0
在这里你可以看到我的webpack配置
const HtmlWebpackPlugin = require('html-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { EnvironmentPlugin, ProgressPlugin } = require('webpack');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const modeConfig = (env, target) => require(`./build-utils/webpack.${env}`)(target);
const presetConfig = require('./build-utils/loadPresets');
const targetUtils = require('./build-utils/targetUtils');
module.exports = ({ mode, presets, target } = { mode: 'production', presets: [] }) => {
return webpackMerge(
{
mode, // minify the code in production mode
entry: './src/index.tsx',
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
options: {
configFileName: 'tsconfig.build.json',
},
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.json', '.js'],
plugins: [new TsconfigPathsPlugin()],
},
plugins: [
new CleanWebpackPlugin(),
new Dotenv({ path: targetUtils.getEnvFile(target), systemvars: true }),
new ProgressPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(rootDir, 'index.html'),
mode,
}),
new EnvironmentPlugin(process.env),
],
externals: targetUtils.getExternals(target),
node: {
fs: 'empty',
},
},
modeConfig(mode, target),
presetConfig({ mode, presets }),
);
};
const targetUtils = require('./targetUtils');
const TerserJSPlugin = require('terser-webpack-plugin');
module.exports = target => ({
optimization: {
minimize: true,
minimizer: [
new TerserJSPlugin({
extractComments: false,
terserOptions: {
compress: {
drop_console: true,
},
},
}),
],
},
stats: {
warnings: false,
},
resolve: {
alias: targetUtils.getAlias(target),
},
});```
I did a yarn build without going through the Terser and it compiles without problems until the terser enters configuration, I don't know if it is a dependency problem or some extra config that I need with the Terser.
change libraries, change configurations in my webpack
11个月前,我有一个问题想要回答。我通过使用新的加载器来支持 Webpack 5 和 TS-LOADER 以及 Webpack 5 的其他更新解决了这个问题。我能够解决它。