admin管理员组文章数量:1434409
I'm having a bit of trouble getting Webpack in bination with the postcss-loader to watch imported css files. They're being processed on the first run, but webpack does not repile when I modify these files.
E.g.
I have my main css file where I import all css modules:
...
/* Base imports */
@import "base/base-imports";
...
In base imports I have for the sake of example applied a color to the body:
body {
background: tomato;
}
I now set the background to another color tho debug whether the css file is reloaded, but isn't.
This is my webpack config:
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin')
var autoprefixer = require('autoprefixer');
var precss = require('precss');
var fontMagician = require('postcss-font-magician');
var atImport = require('postcss-import');
module.exports = {
entry: [
'./src/index.js'
],
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: 'bundle.js',
},
module: {
loaders: [
{
test: /\.css$/,
loader: "style-loader!css-loader!postcss-loader"
}
],
},
postcss: function(webpack) {
return [
autoprefixer({ browsers: ['last 2 versions'] }),
precss,
fontMagician,
atImport({
path: './src/styles/*.css',
addDependencyTo: webpack
}),
];
},
plugins: [
new HtmlWebpackPlugin({
title: 'Custom template',
template: 'src/index.html', // Load a custom template
inject: 'body' // Inject all scripts into the body
})
],
devtool: 'source-map',
devServer: {
contentBase: './dist',
hot: true
},
}
I'm having a bit of trouble getting Webpack in bination with the postcss-loader to watch imported css files. They're being processed on the first run, but webpack does not repile when I modify these files.
E.g.
I have my main css file where I import all css modules:
...
/* Base imports */
@import "base/base-imports";
...
In base imports I have for the sake of example applied a color to the body:
body {
background: tomato;
}
I now set the background to another color tho debug whether the css file is reloaded, but isn't.
This is my webpack config:
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin')
var autoprefixer = require('autoprefixer');
var precss = require('precss');
var fontMagician = require('postcss-font-magician');
var atImport = require('postcss-import');
module.exports = {
entry: [
'./src/index.js'
],
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: 'bundle.js',
},
module: {
loaders: [
{
test: /\.css$/,
loader: "style-loader!css-loader!postcss-loader"
}
],
},
postcss: function(webpack) {
return [
autoprefixer({ browsers: ['last 2 versions'] }),
precss,
fontMagician,
atImport({
path: './src/styles/*.css',
addDependencyTo: webpack
}),
];
},
plugins: [
new HtmlWebpackPlugin({
title: 'Custom template',
template: 'src/index.html', // Load a custom template
inject: 'body' // Inject all scripts into the body
})
],
devtool: 'source-map',
devServer: {
contentBase: './dist',
hot: true
},
}
Share
Improve this question
asked Jan 15, 2016 at 7:54
HoetmaaiersHoetmaaiers
3,5032 gold badges23 silver badges33 bronze badges
1
- 3 Could you try to move atImport before precss? I guess that your imports is processed by precss instead of postcss-import. – Kreozot Commented Jan 15, 2016 at 13:18
1 Answer
Reset to default 5Okay,
This question had 2 things wrong, so the solution is:
- Do atImport before precss, thank you @Kreozot.
- Reference to the exact css filename. With this I mean is: @import
"base/_base-imports"
instead of@import "base/base-imports"
if the filename is"_base-imports"
. It is not resolved like a sass partial.
本文标签: javascriptWatch imported css files in webpackpostcssloaderStack Overflow
版权声明:本文标题:javascript - Watch imported css files in webpack + postcss-loader - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745624064a2666861.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论