Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Web包删除typescript生产生成中的断言 形势_Typescript_Webpack_Assert - Fatal编程技术网

使用Web包删除typescript生产生成中的断言 形势

使用Web包删除typescript生产生成中的断言 形势,typescript,webpack,assert,Typescript,Webpack,Assert,我使用的是TypeScript 3.9和webpack 4.46 assert 2.0.0的导入方式如下: import { strict as assert } from 'assert'; 我只使用了assert函数,例如: assert(i < j); Webpack似乎不喜欢加载程序。我猜使用说明文件是为早期的网页准备的 我试着用另一种方式来配置它(参见下面的webpack.config.js), 但这并没有起作用(构建的代码中仍然有断言)。 也许我猜错了(我不是网页专家) 类

我使用的是TypeScript 3.9和webpack 4.46

assert 2.0.0的导入方式如下:

import { strict as assert } from 'assert';
我只使用了
assert
函数,例如:

assert(i < j);
Webpack似乎不喜欢
加载程序
。我猜使用说明文件是为早期的网页准备的

我试着用另一种方式来配置它(参见下面的webpack.config.js), 但这并没有起作用(构建的代码中仍然有断言)。 也许我猜错了(我不是网页专家)

类型脚本插件unassert 我看了看,但有两件事并没有让我放心:

  • 每周只下载7次
  • 文件不清楚。例如:
这个插件消除了官方页面上引入的所有assert和assertesdefine调用

其他所有断言函数呢?哪个‘官方网页’

也许它工作得很好,这正是我想要的,但我不被鼓励

断言加号 我看了一眼,但一句评论让我气馁,上面说:

由于环境变量而停用断言时,函数不会被删除,只是函数的内容返回void

如果这是对的,那它就不能满足我的需要

所以。。 如果有人能告诉我,消除断言的标准路径是什么,我将非常感激

webpack.config.js 以下是我的
webpack.config.js
的精髓:

{
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: ['ts-loader'],
                exclude: /node_modules/
            },
            /* I tried this, but it didn't get rid of the assertions:
            {
                test: /\.js$/,
                use: ["webpack-unassert-loader"]
            },
            */
        ]
    },
        resolve: {
            extensions: [ '.ts', '.tsx', ".js", ".json", ".css"]
        },
        optimization: {
            minimize: getMinimize(env),
                minimizer: [new TerserPlugin({
                    terserOptions: {
                        compress: {
                            pure_funcs: [
                                'console.log',
                                'console.info',
                                // I tried this, just as a guess! But it didn't get
                                // rid of the assertions:
                                'assert',
                            ]
                        },
                    }
                })],
        },
}
{
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: ['ts-loader'],
                exclude: /node_modules/
            },
            /* I tried this, but it didn't get rid of the assertions:
            {
                test: /\.js$/,
                use: ["webpack-unassert-loader"]
            },
            */
        ]
    },
        resolve: {
            extensions: [ '.ts', '.tsx', ".js", ".json", ".css"]
        },
        optimization: {
            minimize: getMinimize(env),
                minimizer: [new TerserPlugin({
                    terserOptions: {
                        compress: {
                            pure_funcs: [
                                'console.log',
                                'console.info',
                                // I tried this, just as a guess! But it didn't get
                                // rid of the assertions:
                                'assert',
                            ]
                        },
                    }
                })],
        },
}