删除生产分发文件中的一些代码行? [英] Remove some code lines in production distribution files?
问题描述
我正在使用Babel
和Webpack
从ES6
生成ES5
代码.有一些验证可以减少我在编码时所犯的错误.
I'm using Babel
and Webpack
to generate ES5
code from ES6
. There are some validations that is used to reduce the mistakes i do while coding.
class Logger {
/**
* @param {LogModel} info
* {LogTypes} type
* {String} message
* {Date} date
*/
static log(info) {
if(info instanceof LogModel)
throw new Error("not a instance of LogModel");
notify(info);
}
}
在log
函数中,我验证参数是否为LogModel
类的实例.这只是为了防止错误.我不希望if条件在生产中,因为if条件太多会使应用程序变慢.
In log
function, I validate whether the argument is a instance of LogModel
class. This is just to prevent mistakes. I don't want that if condition to be in the production because too many if condition going to slow the application. Is it possible to generate development release with validations and production release without those validations with Babel
and Webpack
?
推荐答案
您可以使用声明包以强制执行您的代码,然后使用 webpack-unassert-loader 或 webpack-strip-assert 剥离生产代码的断言.
You can use the assert package to enforce your code, then use webpack-unassert-loader or webpack-strip-assert to strip your assertions for production code.
var assert = require('assert').ok;
class Logger {
/**
* @param {LogModel} info
* {LogTypes} type
* {String} message
* {Date} date
*/
static log(info) {
assert(info instanceof LogModel, "Param must be an instance of LogModel");
notify(info);
}
}
这篇关于删除生产分发文件中的一些代码行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!