taro icon indicating copy to clipboard operation
taro copied to clipboard

taro3如何全局注入less

Open LiangFuzhi opened this issue 3 years ago • 6 comments

taro3如何全局注入less

试了两种方法都没生效 options.less

@theme-color: #07c160;
webpackChain (chain, webpack) {
//方法1
      chain.module.rule('less').use('style-resource')
        .loader('style-resources-loader')
        .options({
          patterns: [
            path.resolve(__dirname, 'src/assets/styles/options.less')
          ],
          // injector: 'append'
        })

//方法2
// chain.merge({
      //   module: {
      //     rule: {
      //       less: {
      //         test: /\.less$/,
      //         use: [{
      //           loader: 'style-resources-loader',
      //           options: {
      //             patterns: [path.resolve(__dirname, './src/assets/styles/options.less')],
      //             injector: 'append'
      //           }
      //         }]
      //       }
      //     }
      //   }
      // })
}

编译报错

color: fade(@theme-color, 50);
       ^
Error evaluating function `fade`: variable @theme-color is undefined

LiangFuzhi avatar Jun 21 '21 07:06 LiangFuzhi

@LiangFuzhi 解决了吗?

zhangfu-git avatar Sep 18 '21 06:09 zhangfu-git

@LiangFuzhi 解决了吗?

转用uniapp了

LiangFuzhi avatar Sep 18 '21 06:09 LiangFuzhi

webpackChain(chain, webpack) {
  chain.module
    .rule("less")
    .oneOf("0") // 小程序平台需要这个,h5平台这行去掉
    .use("style-resource")
    .loader("style-resources-loader")
    .options({
	    patterns: [path.resolve(__dirname, "..", "src/styles/index.less")]
	    // injector: 'append'
    });
}

Binbiubiubiu avatar Mar 20 '22 10:03 Binbiubiubiu

@Binbiubiubiu 用了还是不行

rgz665 avatar Nov 01 '22 09:11 rgz665

@rgz665 https://github.com/Binbiubiubiu/taro-plugin-style-resource

Binbiubiubiu avatar Nov 01 '22 16:11 Binbiubiubiu

@rgz665 https://github.com/Binbiubiubiu/taro-plugin-style-resource

"@tarojs/taro": "3.6.23",没用

LarryHangFan avatar Feb 15 '24 12:02 LarryHangFan

@rgz665 https://github.com/Binbiubiubiu/taro-plugin-style-resource

"@tarojs/taro": "3.6.23",没用

试过可以,使用的是NutUI-v4

ixre avatar Feb 23 '24 05:02 ixre