gpt4 book ai didi

vue.js - 我如何在 Vue CLI 3 中使用 stylus-resources-loader?

转载 作者:搜寻专家 更新时间:2023-10-30 22:16:45 24 4
gpt4 key购买 nike

我知道它涉及修改 vue.config.js,但是简单地将我想要的配置粘贴到 configureWebpack 对象中似乎不起作用。有没有其他人能够解决这个问题?

需要添加的配置:

module: {
rules: [
{
test: /\.vue$/,
use: [
{
loader: "vue-loader",
options: {
loaders: {
stylus: [
{
loader: "stylus-resources-loader",
options: {
resources:
"./src/assets/_base.styl",
},
},
],
},
},
},
],
},
],
},

谢谢!

最佳答案

const path = require('path');

module.exports = {
chainWebpack: (config) => {
config.module
.rule('vue')
.use('vue-loader')
.tap((options) => {
options.loaders.stylus = options.loaders.stylus.concat({
loader: 'stylus-resources-loader',
options: {
resources: path.resolve('./src/assets/_base.styl'),
},
});
return options;
});
},
};


更新:

需要注意的是lang的值<style lang="stylus"> 中的属性会影响配置项的写法!当langstylus , stylus安装在 loader 上,应该这样写:options.loaders.stylus , 而当 lang 的值是styl , 应该写成options.loaders.styl .

由于 @vue/cli-service/lib/webpack/CSSLoaderResolver.js 中的以下代码:

getLoader (test, loader, options = {}) {
styl (test = /\.styl$/) {
return this.getLoader(test, 'stylus')
}

stylus (test = /\.stylus$/) {
return this.getLoader(test, 'stylus')
}
}

引用https://stackoverflow.com/a/49086022/4723163

关于vue.js - 我如何在 Vue CLI 3 中使用 stylus-resources-loader?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48750182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com