【发布时间】:2016-05-17 04:44:57
【问题描述】:
我正在重写一堆 HTML+CSS+JS 以更加模块化。我开始很简单,有两个 NPM 包:
-
Core 有一些 SCSS:
index.js
require("./styles/variables.scss"); require("./styles/test-import.scss");样式/变量.scss
$color-primary: rgb(0, 123, 196); $color-type-main: rgb(51, 51, 51);styles/test-import.scss
@import "variables"; body { background: $color-primary } -
Test 需要 Core 并希望使用变量:
index.js
require("core"); require("./styles/test.scss");styles/test.scss
body { background: $color-primary; }
Core 使用 Webpack 构建得很好。测试失败,因为它找不到 $color-primary。
我考虑过的一个选项是直接导入变量文件,即
require("./node_modules/core/styles/variables");
...但这似乎不太可扩展。 NPM 可以随时决定更改其目录结构。
【问题讨论】: