【发布时间】:2022-09-27 13:00:54
【问题描述】:
是否可以配置 webpack 使其在已编译的 scss 旁边输出未编译的 scss 文件?
我希望以这种方式公开 scss 变量、mixin 和函数。
文件:
styles/
index.scss
webpack.config.js:
module.exports = {
entry: path.resolve(__dirname, \"./src/index.js\"),
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: \"./lib/index.css\",
}),
],
module: {
rules: [
{
test: /\\.scss$/i,
use: [
MiniCssExtractPlugin.loader,
\"css-loader\",
{
loader: require.resolve(\"sass-loader\"),
options: {
warnRuleAsWarning: true,
sourceMap: true,
sassOptions: {
includePaths: [\"../../node_modules\"],
outputStyle: \"compressed\",
outFile: path.resolve(__dirname, \"./lib/index.css\"),
},
},
},
],
}
]
},
resolve: {
extensions: [\".tsx\", \".ts\", \".js\", \".css\", \".scss\"],
},
output: {
filename: \"[name].js\",
library: {
type: \"umd\",
name: \"design-system\",
}
}
};
示例输出:
lib/
index.css (compiled version)
index.scss (uncompiled version)
标签: webpack sass sass-loader