-
Notifications
You must be signed in to change notification settings - Fork 809
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
extractStyles not working as intended with css in vue components #2589
Comments
It appears that this has to do w/ style extraction + use of async components. I'll take a look today. |
@thecrypticace Did you get chance to look into it? |
I've a similar problem in laravel mix 4.2.0. In my case, if I use: it works perfectly but it created on the wrong folder, so at public/js/app.css and public/js/vendor.css My first code attemplt was: But that would create a vue.css with only the content of vendor.css, the app.css seems to be overwritten by the vendor one So for now, I'm using extractVueStyles: '[name].css', since it works with the only inconvenient of having the css on a js folder. best regards |
@Daniel4Digital This pointed me in the direction as to why something isn't working. When using |
Any fixes to this? If i apply
in laravel mix vue options, the webpack tries to load chunk called "app.js" when trying to load dynamically imported components. |
So I've confirmed that async components + style extraction doesn't work properly. If I tell webpack to only extract styles for non-async components things work fine but that's definitely not ideal. |
Today I updated to laravel mix 6 (Saw today too that this issue regards version 6) and try to use vue({ And the app.css is now on the correct folder, but the vendor.css still goes to js folder no matter what. Even if I use extractStyles: true, the vendor.css still goes to js folder. And using '[name].css' no longer works, since it seems not to be needed anymore. Dunno if related to this issue no more. But well. |
In v6, this builds a vendor.css file in mix.js('resources/scripts/main.js', 'public/scripts/main.js').vue({extractStyles: 'public/styles/vendor.css'}) |
Also when using
In laravel mix vue options, the build output is a plain "[name].css" file. In laravel-mix 5, the css file was created using the input scripts name. For example if i have |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Attempting to wake this up. What is the intended behaviour here? If a string is provided the css chunks are concatenated into one css file, if a boolean value is provided then the chunks are correctly output, however we lose control over where they end up. I'm not sure how hard it is to make this a little more flexible, but I'd be willing to attempt a PR here. |
Faced with the same problem. In my case scss block in single file components was not extracted. After some investigation, this workaround has helped me: |
If i had two different "main" scripts in my webpack.mix.js config:
and if I had set option: The laravel mix bundled files like this:
Now if I use the newer Laravel mix version with It generates files like this:
If i try to use it generates files like this:
Is there still any workarounds for this? |
update i guess my use case is a little different, im not trying to do split entry points like others in this thread. I, too, am curious how i can configure laravel-mix ideally i could use something like:
seems like no matter what string value i set laravel-mix/src/components/CssWebpackConfig.js Lines 178 to 185 in 6ee2985
also, i'm unclear if as i continue to investigate: i noticed that laravel-mix is requiring v1 of MiniCSSExtractPlugin also, FWIW, i'm still using Vue2 also, I'm attempting to get styles extracted from vue SingleFileComponents, do i need to change my do need to call
➜ app git:(feature/inertia) ✗ yarn why mini-css-extract-plugin
├─ @vue/cli-service@npm:5.0.4
│ └─ mini-css-extract-plugin@npm:2.6.0 (via npm:^2.5.3)
│
├─ @vue/cli-service@npm:5.0.4 [0460f]
│ └─ mini-css-extract-plugin@npm:2.6.0 [3fb00] (via npm:^2.5.3 [3fb00])
│
├─ app@workspace:.
│ └─ mini-css-extract-plugin@npm:2.6.0 [0460f] (via npm:^2.6.0 [0460f])
│
├─ laravel-mix@npm:6.0.43
│ └─ mini-css-extract-plugin@npm:1.6.2 (via npm:^1.6.2)
│
└─ laravel-mix@npm:6.0.43 [0460f]
└─ mini-css-extract-plugin@npm:1.6.2 [09b24] (via npm:^1.6.2 [09b24]) i tried overriding the config using: mix.override((webpackConfig) => {
webpackConfig.plugins.map((p,k) => {
if(p.constructor.name === 'MiniCssExtractPlugin'){
webpackConfig.plugins[k].options.filename = "[name].[contenthash].css";
webpackConfig.plugins[k].options.chunkFilename = "[id].[contenthash].css";
}
}); Plugins List:
|
In my case. I have components with Example.
each component have mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.vue({
version: 2
})
.version(); Is there any workaround? |
I'm not sure if your problem is related to this issue. You might want to look into overwriting https://github.com/webpack-contrib/style-loader with webpack override option. If registering components locally or registering them as async components fixes your problem, that is the approach I would take instead of messing with the style-loader. |
node -v
): 14.15.0npm -v
): 6.14.8Description:
Laravel mix is unable to extract css from vue component and throwing error.
webpack.mix.js
Vue component:
When running the mix command for watch and visiting the page gave following error:
What is the possible solution to above?
The text was updated successfully, but these errors were encountered: