How to disable webpack minification for classes names

我怕爱的太早我们不能终老 提交于 2020-05-29 08:27:28

问题


I use jasmine, karma and webpack to test my module. The webpack preprocesses my tests files before initiating tests.

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'.
  })
});

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".

Can I prevent webpack to change the names of classes/constructors?


回答1:


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).

Help links:

  1. Bundling Modes
  2. Minification pluin

You can use 'keep_classnames' option provided by the minification plugin to keep the class names intact.



来源:https://stackoverflow.com/questions/50903065/how-to-disable-webpack-minification-for-classes-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!