-
-
Notifications
You must be signed in to change notification settings - Fork 384
Vue + vue-loader 15 + webpack 4 + mini-css-e-p creates multiple css files #113
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
@amir20 very interesting, can you create minimum reproducible test repo? |
@evilebottnawi I was able to reproduce this by creating a really simple Vue application. Here is the repo: https://github.com/amir20/vue-mini-css. There are three entry points. One CSS file and two other javascript files.
After doing I have done some research since then and I am pretty sure the fix requires fixing the test in |
@amir20 how about this https://github.com/thecrypticace/webpack-css-chunks-test/blob/master/webpack.config.js#L61, looks some people extract css from vue doing this setup |
I saw that as well. My goal was to create one css file. That creates two. I imagine I could put the two rules together, but does it make sense to go through all these configurations to do this? I imagine having a bunch of vue files with css is a common pattern that many people plan to do. |
Hmmmmm. I can't get that to work either... diff --git a/webpack.config.js b/webpack.config.js
index ef5453d..7c75bce 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -17,11 +17,29 @@ module.exports = {
name: "vendors",
chunks: "all"
},
- "styles-compiled": {
- name: "styles-compiled",
- test: /\.css$/,
+ extractVueStyles: {
+ test: m => {
+ return /\.vue\?vue&type=style/.test(m.identifier());
+ },
+ name: "vue-styles",
chunks: "all",
- enforce: true
+
+ // enforce: false
+ // results in no vue-styles chunk
+ // Only a bundle.css file
+ enforce: false
+ },
+ extractOtherStyles: {
+ test: m => {
+ return m.constructor.name == "CssModule";
+ },
+
+ // enforce: false
+ // results in no other-styles chunk
+ // Only a bundle.css file
+ name: "other-styles",
+ chunks: "all",
+ enforce: false
}
}
} Am I doing something wrong? :( That produces no files now. |
Doing |
Exact same problem here. My configuration differs in using
Still can get to merge all my the generated css in one file. |
I am still not sure how to do this. I am waiting for |
@sokra Anything we are oversighting in order to make this work that you know about? |
same issue here |
same issue |
Please don't write |
I think I sorted it out finally, at least is working for me:
|
/cc @amir20 looks on #113 (comment) solution, it is works for you? |
I think it worked (kinda). I validated by doing However, I said "kinda" because my javascript now isn't executing. 👎 I need to debug more to understand what's going on. Here is the diff for the curious diff --git a/webpack.config.js b/webpack.config.js
index b54a754..655fb5b 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -31,8 +31,9 @@ module.exports = {
},
"styles-compiled": {
name: "styles-compiled",
- test: /\.css$/,
- chunks: "all",
+ test: /\.(s?css|vue)$/,
+ chunks: "initial",
+ minChunks: 1,
enforce: true
}
} |
@amir20 can you create minimum reproducible test repo, it is help to solve your problem faster |
Still working on it. I am not sure if |
Ok I have applied the changes to my old test repo at https://github.com/amir20/vue-mini-css/commit/375389e5ff297c3e2002d28b513d0484ea1cdd70 I think the problem is that all the javascript goes Does that make sense? |
@amir20 sorry i am not familiar with vue and vue-loader, but i can ivnestigate what is wrong, https://github.com/amir20/vue-mini-css is minimum reproducible test repo? |
Yup. I created that when I created this issue. I am pretty sure the pattern vue will also capture the output of all JavaScript files that vue components.
Sent via my iPhone
… On May 8, 2018, at 8:14 AM, Evilebot Tnawi ***@***.***> wrote:
@amir20 sorry i am not familiar with vue and vue-loader, but i can ivnestigate what is wrong, https://github.com/amir20/vue-mini-css is minimum reproducible test repo?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@evilebottnawi might be worth asking |
@amir20 vue-cli have issue around this problem? |
I don’t think so. Since they haven’t implemented the new version yet, there isn’t anything that is “broken”? |
@amir20 Thanks for your investigations. I managed to get rid of the JS extraction problem by removing the JavaScript in the styles
See this issue for more details: #85 |
I just tried it. It looks like it might have worked. I'll try it on my actual project this week and update back. |
@alexander-heimbuch thx, it is actually worked ! |
Sadly, after a lot of effort, I am unable to figure out why javascript is not executing at all. I figured out when I remove I hope there is an easier way to configure webpack 4 with mini-css-extran. |
Hmm. I think I found the problem. optimization: {
// concatenateModules: true,
// runtimeChunk: true,
splitChunks: {
cacheGroups: {
commons: {
test: /node_modules/,
chunks: "initial",
name: "vendors"
},
"styles-compiled": {
name: "styles-compiled",
test: module =>
module.nameForCondition &&
/\.(s?css|vue)$/.test(module.nameForCondition()) && !/^javascript/.test(module.type),
chunks: "all",
enforce: true
}
}
}
}, This produces The contents of |
A similar issue: My webpack 3 build which does not use any dynamic loading (ExtractTextPlugin), resulted in one concatenated CSS file of all the styles from my .vue files, per bundle (edit: eg. "utils.js", "page1.js" "page2.js" resulted in "utils.css", "page1.css", "page2.css" -- where "utils" was my common / root bundle used across the site). I couldn't make that work in Webpack 4. I tried many snippets I found online, always ended up with ONE styles file, even though my 3 javascript bundles are being output. And, there would be indeed this extra "styles.js" file which Webpack 3 + ExtractTextPlugin didn't produce. |
For everybody who is coming to this issue. I solved this problem by inlining I don't know of any other solution where |
Any news on this one? How is this actually getting almost to none attention? This means you can't bundle your css in anyway? |
Having the same issue, have tried many MANY approaches. The only thing that's done anything remotely useful is the one below. This gives me the desired result (of merging the inline style outputs from vue components into one file) but still there are JS versions of these styles being generated resulting in inline styles on the page AND these. Not sure how fix this, this whole process has been a nightmare. Here's my current vue.config.js, can post my webpack.config as well: http://jsfiddle.net/av42ky7d/
|
Guys before write here please create minimum reproducible test repo and add link on this repo in post, it is help to solve your issue(s). |
I believe this is a similar issue. For me, even if I'm able to extract all the CSS out into one file, it breaks the component entry files. Minimal reproduction repo: https://github.com/hirokiosame/test-build |
I am quite urgently in need for a way to concatenate all my css files now.. https://gist.github.com/amoshydra/f0a79123fd184088e7e674333d0fc191 node concatenate-css.js dist/css/*.css dist/style.css At the moment, I can't apply any |
Here two problem:
What is problem here? Don't do this in future - don't write difference issues in one issue. It is hard to understand what is problem you want to solve. So only top issue was solved here, other will be ignored - one problem = one issue. |
/cc @amir20 sorry for big delay, a lot of work, problem still exists? If yes can you create latest actual repository and describe in readme what you have and what you expected? |
@evilebottnawi I believe this repo reproduces his issue https://github.com/hirokiosame/test-build |
@hirokiosame what you expected? All in one file or each component create own |
All in one file
On Tue, Dec 11, 2018 at 1:39 Evilebot Tnawi ***@***.***> wrote:
@hirokiosame <https://github.com/hirokiosame> what you expected? All in
one file or each component create own css file?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#113 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABBp7goC1O2aV7cytEAbW_bR1MuwhQAVks5u331agaJpZM4TrkdF>
.
--
Kind regards,
Hiroki Osame
|
@hirokiosame do you try above examples? |
Yes, I've tried the various webpack configs.
Try cloning the repo. I wrote this in the ReadMe, and it's also
communicated in the thread above, but once the CSS is outputted in one
file, the JS breaks.
On Tue, Dec 11, 2018 at 1:44 Evilebot Tnawi ***@***.***> wrote:
@hirokiosame <https://github.com/hirokiosame> do you try above examples?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#113 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABBp7uZ4kmVFDDpJ3AmRxQjZHfWs-IY1ks5u335mgaJpZM4TrkdF>
.
--
Kind regards,
Hiroki Osame
|
Ya exact same problem as @hirokiosame ! |
@jimblue What you mean breaks? |
@evilebottnawi I used to have a repo to show this bug. I think I have deleted it and gotten a new laptop since so I don't have the work anymore. The bug is simple. I don't think there is any need to have a lot of conversations about this. When creating a single css file, a javascript file is also created that is required for the whole thing to run. That's the bug. So the final files are 1. styles.css, 2. styles.js and 3. scripts.js. To fix the bug, styles.js needs to be included in script.js. The contents of the JS file is Hope this helps. The bug is pretty big in my opinion and there it should be very easy to reproduce. |
i have a same question, any one has the answer? |
Please open issue in |
nwrightau's solution worked for me |
This works perfectly. I have a doubt ...How can I change the final css name? |
Using |
I am losing my mind. I have googled for hours and don't know what else to try. I am moving from EWP to this module and I can't get to produce one css file. I have also updated to latest
vue-loader
.Webpack Confg
Version
[email protected]
[email protected]
Bug
NODE_ENV='production' webpack --progress --mode production
Produces this...
When I do
ag --css "player-comparison"
which is a class that I know is in one of the vue files I getDoes this make sense? Wouldn't it make sense to get all css files in the combined css. My config and package files.
The text was updated successfully, but these errors were encountered: