首页 > 解决方案 > 生产模式下的 webpack 4 无法编译打字稿

问题描述

按照自述文件从 webpack 3 迁移到 webpack 4 之后

将 webpack 设置为时,我的 typescript 应用程序出现复杂错误mode: production

错误:

Uncaught TypeError: Object(...) is not a function
    at Object.822 (Tag.tsx:65)

映射到这一行:

withExpertFeed(({removeAttribute}) => ({removeAttribute})),

这个 webpack 配置有效:

module.exports = merge(common(), {
    devtool: 'source-map',
    mode: 'development', // Set to development
    plugins: [
        }),
        new CopyWebpackPlugin([{
            from: 'public',
        }, ]),
        new ForkTsCheckerWebpackPlugin({
            checkSyntacticErrors: false,
            tsconfig: '../web-tsconfig.json',
        }),
        new HtmlWebpackPlugin({
            inject: true,
            template: path.resolve(__dirname, 'public/index.html'),
            filename: 'index.html',
            minify: {
                removeComments: true,
                collapseWhitespace: true,
                removeRedundantAttributes: true,
                useShortDoctype: true,
                removeEmptyAttributes: true,
                removeStyleLinkTypeAttributes: true,
                keepClosingSlash: true,
                minifyJS: true,
                minifyCSS: true,
                minifyURLs: true,
            },
        }),
    ],
    optimization: {
        minimizer: [
            new UglifyJSPlugin({
                uglifyOptions: {
                    output: {
                        ascii_only: true,
                    },
                },
                parallel: true,
                cache: true,
                sourceMap: true
            }),
        ]
    }
});

我设置时相同的 webpack 配置mode: production失败并出现上述错误

标签: typescriptwebpack

解决方案


推荐阅读