-
Notifications
You must be signed in to change notification settings - Fork 511
feat: extract multiple css files based on pattern #159
Comments
👍 |
+1 |
1 similar comment
+1 |
This worked for me: Add this at the top of your webpack.config.js:
Add this into your loaders part:
Add this into plugin part:
Now it should load
|
@mrtom213 I am trying your code from above, but when I use it, I get the same output in both files. Is there anything else you are doing? What version are you using? |
@jimitndiaye I've come across this same issue. I feel this is a fairly common use case for people like me who occasionally work on hodgepodge, brown-field projects. @mrtom213 I wasn't able to successfully build out separate files as per your example. (webpack 2.2.1, extract-text-webpack-plugin 2.1.0) @bebraw Do you have any thoughts on the usefulness of this proposed enhancement? Thanks! |
@bro-strummer Three plugin/loader pairs would seem like the solution to me if I understood the problem right. You should be very careful when you set up the loaders to make sure they match only the CSS files you intend. Otherwise you'll get CSS where you don't want it. extract-loader might work for the original problem too. |
I'm having the same problem. I expected that with multiple entries, configured like this. entry: [
'./src/js/app.js',
'./src/scss/app.scss',
'./src/scss/login.scss'
], And a scss loader configured like this: test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'resolve-url-loader'
},
{
loader: 'postcss-loader'
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
}) And finally, with the following plugins section: plugins: [
new ExtractTextPlugin('/css/[name].css'),
// Other plugins ...
], I will get separate 2 files: But what's more weird - the output file name is new ExtractTextPlugin({
filename: '[name].css'
}); But it doesn't work either. |
@wujekbogdan Instead of entry: [
'./src/js/app.js',
'./src/scss/app.scss',
'./src/scss/login.scss'
], could you try something along entry: {
app: './src/js/app.js',
appStyle: './src/scss/app.scss',
loginStyle: './src/scss/login.scss'
}
|
the suggestion of using use: [ 'file-loader?name=[name].css', 'extract-loader', 'css-loader', 'sass-loader' ] and it converted no need for keeping a massive list of entry points either (this project had like a good 60 that would've been needed) |
I've changed my configuration entry: {
appJs: './src/js/app.js',
appCss: './src/scss/app.scss',
loginCss: './src/scss/login/login.scss'
}, Indeed, it works (however it's confusing, because in loaders This is the console output:
And there's one more issue. I want my files to be named entry: {
app: './src/js/app.js',
app: './src/scss/app.scss',
login: './src/scss/login/login.scss'
}, // Edit: Thanks @NogsMPLS, I also gave the entry: [
'./src/js/app.js',
'./src/scss/app.scss',
'./src/scss/login/login.scss'
], And the part that's responsible for the SCSS compilation/extraction looks like the following: {
test: /\.scss$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].css',
context: './src/css/',
outputPath: 'css/',
publicPath: '../'
}
},
{
loader: 'extract-loader'
},
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'resolve-url-loader'
},
{
loader: 'postcss-loader'
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
} So now, finally, Webpack is so powerful tool, but so badly documented... |
Same issue for me. I have a
And my plugins array:
Finally I have a Edit : I finally use https://github.com/kevlened/copy-webpack-plugin to simply copy files from source to dist. |
@wujekbogdan I'm trying to adapt your solution and I got this error: |
@karim10 |
@wujekbogdan Thanks a lot 😅 |
Solved, please see #159 (comment). Thanks for everyone. Feel free to feedback. |
Oh, sorry, it should be solved using only ETWP |
ETWP entered maintenance mode and won't receive any feature updates, please open an issue in |
I have three sass files: app.ios.scss, app.wp.scss and app.md.scss.
I'm trying to extract them into seperate files after conversion into css. I've got my loaders configured as follows:
If I require a file as '../styles/app.ios.scss' in my app, I'd like it to output an app.ios.css file. Similarly requiring app.wp.scss should output app.wp.css.
Unfortunately all of it is going into one file (css/app.[hash].css), where app is the name of the entry that requests those files.
How do I achieve multiple files as described above? Do I actually have to configure 3 separate loaders?
The text was updated successfully, but these errors were encountered: