引入插件const WebpackVariableReplacer = require('webpack-stylesheet-variable-replacer-plugin'); 定义插件配置信息new WebpackVariableReplacer({ publicPath: '', buildPath: 'static/', nextSupport: true, specifyEntry: /_app\.js/, matchVariables: { main: '#209CEE', } }), 客户端调用替换主题的方法...
综合起来觉得使用起来比较繁琐,于是自己动手撸了一个webpack插件:webpack-stylesheet-variable-replacer-plugin,只需要在webpack配置中增加一个plugin,其他的就OK了,支持key--value方式来定义需要替换的变量,还有就是注入文件可控,不会重复注入。下面介绍一下使用方法,简单三步走: 引入插件 const WebpackVariableReplacer...
第二步 定义webpack plugin new configureWebpack({matchVariables: {main: '#456789'}}) 第三步 任何地方调用方法实现换肤 window.replaceStyleVariable({main:'#987654'}) 参考优化参考 webpack-stylesheet-variable-replacer-plugin 优化css 提取,将含css变量的css内容从主css抽离,独立单独主题style ...
1、安装包 :npm i webpack-stylesheet-variable-replacer-plugin -D 2、在config-overrides.js中引入包: constWebpackVariableReplacer=require('webpack-stylesheet-variable-replacer-plugin'); 3、 在override方法中加入webpackVariableReplacer配置 module.exports=functionoverride(config,env){//do stuff with the ...
综合起来觉得使用起来比较繁琐,于是自己动手撸了一个webpack插件:webpack-stylesheet-variable-replacer-plugin,只需要在webpack配置中增加一个plugin,其他的就OK了,支持key--value方式来定义需要替换的变量,还有就是注入文件可控,不会重复注入。下面介绍一下使用方法,简单三步走: ...