vue-cli3 + webpack4 搭建换肤功能

在项目中实现一键换肤功能,采用style-loader方式,但因vue-cli3和webpack4的封装导致配置复杂。通过将原SASS方案改为LESS并解决loader找不到的问题,最终在style-loader中找到解决方案,使用style-loader并设置injectType为'lazyStyleTag'。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中有个一键换肤的功能,百度后发现有很多demo,最终采用style-loader方式

由于使用vue-cli3创建的项目,对webpack配置都进行封装了,导致使用起来极度不习惯

原文作者是使用sass的,改成相应less方式

    // 换肤loader
    const less = config.module.rule('less').toConfig();
    const useable = { ...less.oneOf[3], test: /\.useable\.less$/ };
    useable.use = [...useable.use];
    useable.use[0] = { loader: "style-loader/useable"}         
      ;//style-loader/url 找不到对应loader
    config.module.rule('less').merge({ oneOf: [useable] });

项目运行时始终报错找不到对应的loader,百度一圈也没对应解决方法

最后在style-loader上找到解决方案

useable.use[0] = { loader: "style-loader", options: { injectType: 'lazyStyleTag' } } ;//style-loader/url 找不到对应loader

不采用style-loader/useable而使用style-loader,并添加options: { injectType: 'lazyStyleTag' }

style-loader地址:https://github.com/webpack-contrib/style-loader

原文作者:https://www.cnblogs.com/webSciprt/p/ji-yuwebpack4vuecli3xiang-mu-de-huan-fu-gong-neng.html

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值