如何禁用类名称的Webpack压缩 [英] How to disable webpack minification for classes names
问题描述
我使用jasmine
,karma
和webpack
来测试我的模块. Webpack在开始测试之前会对我的测试文件进行预处理.
I use jasmine
, karma
and webpack
to test my module. The webpack preprocesses my tests files before initiating tests.
在我的测试中,我有要测试的class Name{...}
.我创建一个新的Name
实例,然后在测试中expect(myInstance.constructor.name).toBe("Name")
In my tests I have the class Name{...}
to be tested. I create new Name
instance and then, in my tests I expect(myInstance.constructor.name).toBe("Name")
class Name{}
const myInstance = new Name();
describe("The object",function(){
it("should be the instance of Name class",function(){
expect(myInstance.constructor.name).toBe("Name"); // Expected 't' to be 'Name'.
})
});
但是它返回失败的测试.我发现Webpack将我的Name
类解析为捆绑文件中的t
类,并且myInstance.constructor.name
等于"t"
.
But it returns failed tests. I figured out that my Name
class is parsed by webpack to the t
class in the bundled file and myInstance.constructor.name
equals "t"
.
我可以阻止webpack更改类/构造函数的名称吗?
Can I prevent webpack to change the names of classes/constructors?
推荐答案
为开发和生产分别构建一个构建设置,无论何时在开发模式下(您可以在webpack配置对象中提到),请勿应用缩小插件(可能在您的webpack配置中).
Have a build setup for development and production separately, whenever in development mode(which you can mention in the webpack config object), don't apply minification plugin(might be there in your webpack config).
帮助链接:
- Bundling Modes
- Minification pluin
您可以使用缩小插件提供的'keep_classnames'选项来保持类名不变.
You can use 'keep_classnames' option provided by the minification plugin to keep the class names intact.
这篇关于如何禁用类名称的Webpack压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!