webpack 4 有一个简单的配置
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
entry: {
app: './src/index.js',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, './dist'),
publicPath: '/dist',
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
})
],
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: '/node_modules/'
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
],
},
],
},
}
CSS-file 被导入到入口点(index.js),需要在生产构建中将其输出到单独的 CSS-file(使用 mini-css-extract-plugin,想试试这个插件,而不是其他方法)。但出现错误: https ://i.stack.imgur.com/VoqTW.png
这是完整的文件结构 https://github.com/DazzRune/webpack4test