-
Notifications
You must be signed in to change notification settings - Fork 512
Entry chunks for .css files also creating .js files #518
Comments
Sadly not with the current implementation, webpack 'natively' only understands JS and will emit a JS file with the code that gets added to the chunk by webpack into a separate |
This issue is unfortunate. |
@AnalogMemory @hackingbeauty I was able to get around this problem by using https://github.com/AnujRNair/webpack-extraneous-file-cleanup-plugin. I have a pull request in to clean up files specified only in particular files. |
To add to the conversation, I was able to successfully remove the redundant JS via these 2 Webpack plugins:
Check out the HtmlWebpackExcludeAssetsPlugin here: |
@hackingbeauty sadly this solution doesn't remove unwanted js files, just exclude them from generated html. And won't work without |
@sscaff1 why do we want to stick to a size of a file? Why don't use a filename instead? |
@hyzhak the size seemed weird to me too. I submitted a PR (which was accepted and published) to eliminate files from a particular path. That satisfied my use case. For example if I had webpack outputting the following directories |
If using the HtmlWebpackPlugin and HtmlWebpackExcludeAssetsPlugin solution above you can use rimraf as part of your build script to delete the files you don't want, something like - "build": "NODE_ENV=production yarn run clean && webpack -p && rimraf dist/js/style.*.js" Works for me... |
- This initial Webpack refactor patch aims for parity with the previous Rollup.js implementation. The configuration was largely derived from project Marvin. There are many enhancements possible with the new configuration but an effort to keep changes minimal where practical was made. For example, subsequent patches may diversify the library entry points offered, automatically vendor prefix all CSS, or inline image assets as data URIs. https://phabricator.wikimedia.org/source/marvin/browse/master/ - The unusual Rollup.js Babel configuration is simplified and consolidated at the project root. - An empty PostCSS configuration is included for later auto-vendor prefixing. - The JavaScript and CSS artifacts have been minimized in production builds. Notably, the JavaScript build product is now half what it was. - A superfluous entry, build/wikimedia-page-library-override.js, is now generated and may safely be ignored. This is noted in the readme. webpack-contrib/extract-text-webpack-plugin#518 - All demo URLs have been updated to reference webpack-dev-server outputs. - There are no anticipated client changes necessary but integrators should smoke test CSS and JavaScript functionality, especially on older devices. - The NPM clean script has been removed as this is part of the build process provided by Webpack and the "Clean for WebPack" plugin. - The build:watch NPM script is preserved to retain existing app developer workflows.
- This initial Webpack refactor patch aims for parity with the previous Rollup.js implementation. The configuration was largely derived from project Marvin. There are many enhancements possible with the new configuration but an effort to keep changes minimal where practical was made. For example, subsequent patches may diversify the library entry points offered, automatically vendor prefix all CSS, or inline image assets as data URIs. https://phabricator.wikimedia.org/source/marvin/browse/master/ - The unusual Rollup.js Babel configuration is simplified and consolidated at the project root. - An empty PostCSS configuration is included for later auto-vendor prefixing. - The JavaScript and CSS artifacts have been minimized in production builds. Notably, the JavaScript build product is now half what it was. - A superfluous entry, build/wikimedia-page-library-override.js, is now generated and may safely be ignored. This is noted in the readme. webpack-contrib/extract-text-webpack-plugin#518 - All demo URLs have been updated to reference webpack-dev-server outputs. - There are no anticipated client changes necessary but integrators should smoke test CSS and JavaScript functionality, especially on older devices. - The NPM clean script has been removed as this is part of the build process provided by Webpack and the "Clean for WebPack" plugin. - The build:watch NPM script is preserved to retain existing app developer workflows. App devs should verify that their processes are unaltered.
Why: Webpack 4 will soon have the ability to handle CSS inputs/outputs natively, but doesn't yet. As a result, when we add our CSS or Sass files as entry points and use the extract text webpack plugin, or the new webpack 4 compatible mini css extract plugin, we'll get bogus, extraneous JS files generated for each of our CSS assets. See [this issue](webpack-contrib/extract-text-webpack-plugin#518) for more details. This change addresses the need by: Using the `rimraf` package to remove the unnecessary files after build.
Why: Webpack 4 will soon have the ability to handle CSS inputs/outputs natively, but doesn't yet. As a result, when we add our CSS or Sass files as entry points and use the extract text webpack plugin, or the new webpack 4 compatible mini css extract plugin, we'll get bogus, extraneous JS files generated for each of our CSS assets. See [this issue](webpack-contrib/extract-text-webpack-plugin#518) for more details. This change addresses the need by: Using the `rimraf` package to remove the unnecessary files after build.
Are there plans to support this in the future/milestone? |
I would like to see this as well. |
Aaaa I see I am in the |
Why: Webpack 4 will soon have the ability to handle CSS inputs/outputs natively, but doesn't yet. As a result, when we add our CSS or Sass files as entry points and use the extract text webpack plugin, or the new webpack 4 compatible mini css extract plugin, we'll get bogus, extraneous JS files generated for each of our CSS assets. See [this issue](webpack-contrib/extract-text-webpack-plugin#518) for more details. This change addresses the need by: Using the `rimraf` package to remove the unnecessary files after build.
Why: Webpack 4 will soon have the ability to handle CSS inputs/outputs natively, but doesn't yet. As a result, when we add our CSS or Sass files as entry points and use the extract text webpack plugin, or the new webpack 4 compatible mini css extract plugin, we'll get bogus, extraneous JS files generated for each of our CSS assets. See [this issue](webpack-contrib/extract-text-webpack-plugin#518) for more details. This change addresses the need by: Using the `rimraf` package to remove the unnecessary files after build.
For those who work with mono repo this is an issue, because we don't want to important the styles in every application because it duplicates the css reference, that is why importing the common styles in the entry point is important and relevant IMO... For example: module.exports = {
entry: {
"assets-app": "./assets-app/src/index.js",
"pages-app": "./pages-app/src/index.js",
"styles": ["./common/styles.less", "./common/styles.scss"]
},
|
I faced the same issue of having a style only entry (css/sass/less) generating an extra .js file, and ended up creating a webpack plugin to remove the js file from the compilation. I published it on npm as webpack-fix-style-only-entries. You can find the source code on https://github.com/fqborges/webpack-fix-style-only-entries. :-) shamelessly promoting my package :-) |
@fqborges Your package seems to do the trick! |
@fqborges Well done! |
My config file is working fine. But I've just noticed it's generating extraneous files based on the entry points. The entry for
login
generates the correct .css file from the .scss file but also creates a login.js file (it essentially has an empty function inside it). Is there a way to prevent this?Currently using Webpack 2.6.0 and Extract Text Webpack Plugin 2.1.0
Here's what the extraneous login.js file contains:
The text was updated successfully, but these errors were encountered: