我正在尝试让 webpack 将我的 CSS 文件(使用 PostCSS)编译为单独的文件。从文档来看,这似乎正是 ExtractTextPlugin 应该做的。但是,我无法让 webpack 对我的 CSS 文件执行任何操作。
相关项目结构:
dist
⎣js
⎣bundle.js
public
⎣css
⎣style.css*
src
⎣css
⎣index.css
* file doesn’t exist (hasn’t been created)
webpack.config.babel.js
import webpack from 'webpack';
import path from 'path';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import { WDS_PORT } from './src/shared/config';
import { isProd } from './src/shared/util';
export default {
entry: [
'react-hot-loader/patch',
'./src/client',
],
output: {
filename: 'js/bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: isProd ? '/static/' : `http://localhost:${ WDS_PORT }/dist/`,
},
module: {
rules: [
{ test: /\.(js|jsx)$/, use: 'babel-loader', exclude: /node_modules/ },
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 1,
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: 'inline',
},
},
],
}),
},
],
},
devtool: isProd ? false : 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.css'],
},
devServer: {
port: WDS_PORT,
hot: true,
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new ExtractTextPlugin('./public/css/style.css'),
],
};
这将很高兴地正确编译我的 javascript,但它对我的 CSS 没有任何作用。出了什么问题,我该如何解决?