1

我已经在https://github.com/joostvanrijn/webpacker创建了一个示例应用程序来完成,但这是我的问题:

# app/javascript/packs/stylesheets.scss

@import 'variables';
@import 'foo';

# app/javascript/packs/_variables.scss

$bar: #fff;

# app/javascript/packs/_foo.scss

body {
  color: $bar;
}

现在,当我跑步时,/bin/webpack-dev-server我得到

Undefined variable: "$bar".

更重要的是

[84] ./app/javascript/packs/_foo.scss 988 bytes {2} [built] [failed] [1 error]

似乎 Rails/webpacker 编译所有文件,而不仅仅是stylesheets.scss

4

1 回答 1

2

我终于找到了答案。

来自 Webpacker 自述文件:

The configuration for what Webpack is supposed to compile by default 
rests on the convention that every file in app/javascript/packs/*
(default) or whatever path you set for source_entry_path in the 
webpacker.yml configuration is turned into their own output files (or 
entry points, as Webpack calls it).

因此,通过将 sass 部分移动到另一个文件夹,现在只有 stylesheets.scss 被编译。

于 2017-07-12T07:31:35.607 回答