在我的 js 文件“example.js”中,我想分别为桌面版和移动版网站导入两个 .scss 文件“example.scss”和“example.m.scss”。所以我需要三个输出——example.js、example.scss 和 example.m.scss。我如何在 Webpack 4 中实现它?
JS文件:
// CSS
import '../../css/example.scss';
import '../../css/mobile/example.m.scss';
我当前的 Webpack 配置:
const path = require('path');
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
entry: {
home: './src/AppBundle/Resources/public/js/main_home/main_home.js',
// ...
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'web/assets'),
},
module: {
rules: [
{
test: /\.scss|.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader", // translates CSS into CommonJS
"sass-loader" // compiles Sass to CSS, using Node Sass by default
]
},
{
test: /\.(png|jpg|jpeg|gif)$/,
use: ['file-loader'],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'file-loader'
}]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
'window.$': 'jquery',
'window.jQuery': 'jquery'
})
]
};