-
Notifications
You must be signed in to change notification settings - Fork 12k
Add an option to remove reflect-metadata polyfills from prod bundle #6325
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
Comments
I ended up implementing this via the following hack:
works fine, but it's uglify and not obvious that this is what you should do to get rid of the polyfills. |
While the solution above works pretty well, be aware that polyfills might end up twice in your bundles - one time in the polyfills bundle, and the second time in the vendor bundle (because environment is part of vendor). I've discovered this using the |
Instead of doing this via different files, I'm wondering if this could also be achieved using Webpack ... |
Seems that patching the externals: {
'core-js/es6/reflect': 'reflect',
'core-js/es7/reflect': 'reflect'
}, Or even shorter: externals: /^core-js\/(es6|es7)\/reflect$/, Wrote a short NodeJS script which patches internal files on console.log( 'Modifying Angular CLI configuration ...' );
fs.readFile( './node_modules/@angular/cli/models/webpack-configs/production.js', 'utf-8', ( error, fileContent ) => {
// Add core-js reflect patch
console.log( ' -> Adding core-js reflect fix ...' );
const reflectPolyfillsFix = `externals: /^core-js\\/(es6|es7)\\/reflect$/,`;
if ( fileContent.indexOf( reflectPolyfillsFix ) === -1 ) {
const uniqueContentToReplace = 'return {';
fileContent = fileContent.replace( uniqueContentToReplace, `${ uniqueContentToReplace }\n ${ reflectPolyfillsFix }` );
console.log( ' Done.' )
} else {
console.log( ' Nothing to do.' );
}
// Write modified file
fs.writeFile( './node_modules/@angular/cli/models/webpack-configs/production.js', fileContent, 'utf-8', ( error ) => {
console.log( 'Done!' );
} );
} ); |
this has been implemented in v7 |
Hooray! :) |
We are not using angular cli for build.. is there a way we can exclude these polyfills only for production using webpack? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions.
Desired functionality.
reflect-metadata is a sizible chunk of code that slows down the critical path in production mode. It's only needed in the JIT (dev) mode (however we want to drop the need for in from core as well).
Currently there is no way to include the polyfill only for dev bundles. I tried using
environment.ts
but that gets loaded too late after the reflect api is already used by the app code.It would be great to have a way to either strip the polyfill or have an alternative entry path for production polyfills.
The text was updated successfully, but these errors were encountered: