【发布时间】:2018-08-26 06:23:06
【问题描述】:
我正在搜索如何将全局(在我的示例中为THEME_NAME)注入所有 vue 组件:
<template>..</template>
<style lang="scss">
@import "bulmaswatch/<%=THEME_NAME=>/bulmaswatch.scss";
.foo {
color: $primary;
}
</style>
上下文:
我在我的 vue 应用程序(vue Cli 3)中使用 bulma css 的 darkly theme
<template>..</template>
<style lang="scss">
@import "bulmaswatch/darkly/bulmaswatch.scss";
.foo {
color: $primary;
}
</style>
为了切换到cyborg 主题,我将不得不将darkly 替换为cyborg...
有没有更好的方法?类似的东西
<template>..</template>
<style lang="scss">
@import "bulmaswatch/<%=THEME_NAME=>/bulmaswatch.scss";
.foo {
color: $primary;
}
</style>
然后在Webpack或vue.config.js的某个地方,我们可以决定主题是什么
configureWebpack: () => {
return {
plugins: [
new webpack.DefinePlugin({
THEME_NAME: "cyborg"
}),
],
}
}
【问题讨论】:
-
我相信 DefinePlugin 只适用于 JavaScript,你必须改用 string-replace-webpack-plugin 之类的东西。可惜SASS不支持像LESS这样的动态
@import语句。
标签: vue.js sass vue-component bulma