const color = require("./common/color.js");
function appScssVar(oldVarString) {
const newData = Object.keys(color)
.map((k) => `$${k}: ${color[k]};`)
.join("\n");
// 添加样式到全局,这样不用每个页面import了
if (!newData) {
return oldVarString;
}
return oldVarString + '\n' + newData;
}
module.exports = {
chainWebpack: (webpackConfig) => {
const cssTypes = ["vue-modules", "vue"];
cssTypes.forEach((type) => {
webpackConfig.module
.rule("scss")
.oneOf(type)
.use("sass-loader")
.tap((options) => {
if(!options) options = {}
if (!options.sassOptions) {
options.sassOptions = {};
}
options.prependData = appScssVar(options.prependData)
return options;
});
});
},
};
下面是报错:
ERROR Error: No loader specified
11:54:28.729 Error: No loader specified
11:54:28.729 at Function.normalizeUseItem (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:389:10)
11:54:28.758 at Function.normalizeUse (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:360:19)
11:54:28.767 at use.map (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:357:33)
11:54:28.767 at Array.map (<anonymous>)
11:54:28.795 at Function.normalizeUse (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:357:6)
11:54:28.796 at Function.normalizeRule (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:288:26)
11:54:28.824 at rules.map (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:110:20)
11:54:28.834 at Array.map (<anonymous>)
11:54:28.835 at Function.normalizeRules (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:109:17)
11:54:28.863 at Function.normalizeRule (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:300:28)
11:54:28.863 at rules.map (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:110:20)
11:54:28.892 at Array.map (<anonymous>)
11:54:28.923 at Function.normalizeRules (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:109:17)
11:54:28.923 at new RuleSet (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/RuleSet.js:104:24)
11:54:28.979 at VueLoaderPlugin.apply (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/plugin-webpack4.js:29:23)
11:54:29.009 at webpack (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli/node_modules/webpack/lib/webpack.js:51:13)
1 个回复
徐天
解决了吗,同求