-
-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Having nameCache controls #256
Comments
You can't use |
Yeah, but maybe for someone |
@levani132 Yes, it is possible to implement, but you should do choose |
Yes, we won't be able to use both. Though I hope in my desired build flow this won't cause too much performance issues. My project has like 30 modules and I will be able to build them independently, so basically, if the build time becomes 12 times slower with my 12 threads pc, it will become 30 times faster to build separate modules. By the way I haven't yet tested it but I have my own fork in my work PC where I'm playing around with this option and if I succeed I will bring that fork here on github and create a PR. |
@levani132 Yes, feel free to send a PR |
hm, |
Yeah, I see, but I can't wait until webpack 5 will be finally released (Also I'm trying to use nameCache in angular, so I will have to wait for angular to add webpack 5). So I managed to do what I wanted to do in webpack 4, but there's a little problem, Angular also uses optimization flag which converts some variables. If I disable Angular optimizations I achieve what I want (having cached everything that is mangled) but bundle size increases about 2-3 times. So now I'm researching what angular's optimization flag does to somehow make it cache things too maybe. After I succeed I'll test the functionality and send PR here too. |
terser-webpack-plugin/src/utils.js Line 298 in c5a9d41
In order for parallel and nameCache to be used together, we can update nameCache every time we call terser's minify, and then save the nameCache to a file after the webpack is packaged, and everything will work fine the second time. |
But this leads to the cost that the modified code may need to be packaged twice to work properly. |
If you want namecache and parallel to be used together and you don't want to package twice after each change, you can only make namecache a concurrenthashmap. |
@masx200 yeah, you can't use |
IMHO, opening an issue in the terser repo would not help.
For big web apps, mangle properties could reduce the bundles' size magnificently, like what google compile closure does for Google Docs. More build time vs Smaller bundles' size.
Is there any way, like utilizing the module graph to find out which bundles can be processed simultaneously without causing naming conflicts? @alexander-akait |
I don't think we really can solve it here... Files are in different threads, something like |
Feature Proposal
What about adding nameCache option? I haven't used it before, but as documentation suggests we should be able to tell terser to use js object (or it would be more correct to call it dictionary) to map names (as I guess variables, classes, functions) to predefined, new, minified names instead of just renaming them to alphabetically smallest, nonempty, available string.
To say it simply, I'm asking to bring this somehow possible in webpack plugin too:
And this code in my opinion also saves new names cache to same file too. I think this is impossible now in terser webpack plugin.
Feature Request: Add ability/option to bind json file as name cache.
Feature Use Case
<! -- problem -->
Easiest use case would be, I need to build application (currently in angular) which has more than two files bundled (let's assume 3). First and second files both have dependency on third.
Now if I build only first file, after minification first minified file will have for example
console.log(thirdModule.thirdModuleVariable)
transformed intoconsole.log(thirdModule.a)
.But if I only build second file or if I build whole project thirdModule's thirdModuleVariable may become b.
</!-- problem -->
What I want in the end is that in angular application I have appModule => [firstLazyModule, secondLazyModule, thirdLazyModule]. Now I will build whole app, then I will comment out other two modules and build only appModule => [firstLazyModule] (because building all three of them takes too long and I have only changed code in firstLazyModule, after building app with only one module, I will take generated module bundle and I will replace corresponding module file in the firstly generated directory with this new module bundle file.
This whole thing works if I don't use terser plugin, but doesn't work with terser because of the problem I have provided. If I'll have nameCache file in the project, each time I build app it will generate and use in next builds same minified variable names and replacing modules will still work.
I hope we can work this out. Thank you in advance.
The text was updated successfully, but these errors were encountered: