看,我的文件夹结构是这样的:
我的索引链接到app.js,问题是webpack配置无法编译fils(显然),这是我要使事情更清楚的意思:
var path = require('path');
module.exports = {
mode: 'development',
entry: './app.js',
module: {
rules: [
{
test: /\.css$/, use: [ 'style-loader', 'css-loader' ],
include: [
path.resolve(__dirname, 'js/custom.js'),
path.resolve(__dirname, 'js/owl-carousel.js'),
]
}
]
},
output: {
path: path.resolve(__dirname),
filename: 'bundle.js'
}
};
我的app.js上有这个
require('./style.css');
我在做错事吗?
答案 0 :(得分:0)
使用MiniCssExtractPlugin加载程序,该加载程序将提取CSS并写入新的CSS文件。
var MiniCssExtractPlugin = require(“ mini-css-extract-plugin”); 将它们添加到您的webpack配置中:
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: [ 'style-loader', MiniCssExtractPlugin.loader, 'css-loader']
}
]
}
plugins: [
new MiniCssExtractPlugin({
filename: 'style.css',
}),
让我知道您问题仍然存在