-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Excluding files in bundled javascript #11844
Comments
Can you provide some examples of packages which exhibit this issue? |
hi, I provided a link of an example with Webpack and highlight.js, but I should check out highlight.js if that library is fixed or not as that blog is from 2016 (and is how I knew of this Webpack feature and the potential problem with it) require(`
['@angular/common/locales/' + locale + '.js', '@angular/common/locales/extra/' + locale +
'.js'],
function (localeData, extraData) {
registerLocaleData(localeData.default, locale, extraData.default);
}
) I noticed doing something like this included all locales of Angular and I could not configure angular-cli to only include a few languages, so I created this ticket. |
I think this is related to SheetJS/sheetjs#438 |
Same here. We're using faker in some sub module that shouldn't end up in the prod build and faker + faker-uuid is taking ~40% of the final bundle 😭 |
@maxime1992 did you find a solution or did you just define angular fileReplacements for that submodule like this? ...
fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
},
{
"replace": "src/app/submodule/submodule.module.ts",
"with": "src/app/submodule/submodule.prod.module.ts"
},
], Also how could I replace node_modules entry like this? |
@MattiJarvinen-BA I did not find any... |
Would also be useful for Chart.js, as it includes the whole of Moment, even though it is technically an optional dependency with v2.8: chartjs/Chart.js#5978 |
If the import/require statement is within developer controlled code, then Webpack magic comments (docs) could be used to include/exclude files (among other capabilities). Alternatively and recommended, only the files needed should be imported without any dynamic expressions. For a non-Webpack specific method, the tsconfig |
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
)Command (mark with an
x
)Versions
Any Angular Cli
Repro steps
Webpack has a nice feature to generate code for dynamic requires, for example: require('@angular/' + lib); would write code and bundle all @angular packages together. The downside of this feature is that it often includes too much at the same time.
There are quite a few node.js libraries that do something like require('./i18n/' + language + '.js') to load the correct i18n. That works nice on a node.js server, but if used with Webpack the bundled output will contain all languages.
As a solution you would need to modify the Webpack configuration to exclude all languages you do not use. However since the Webpack config can not be altered without 'ng eject' there is no way for me to exclude javascript from bundling.
Desired functionality
Being able to exclude files from the bundled files to reduce filesize without having to call ng eject.
Mention any other details that might be useful
Example blog: https://bjacobel.com/2016/12/04/highlight-bundle-size/
The text was updated successfully, but these errors were encountered: