In webpack, all pre-processors need to be applied with a corresponding loader. `vue-loader` allows you to use other webpack loaders to process a part of a Vue component. It will automatically infer the proper loaders to use based on the `lang` attribute of a language block and the rules in your webpack config.
Any content inside the block will be processed by webpack as if it's inside a `*.scss` file.
这个块里的任何内容都会被 webpack 当作在一个 `*.scss` 文件中一样被处理。
### SASS vs SCSS
### SASS vs SCSS
Note that `sass-loader` processes the non-indent-based `scss` syntax by default. In order to use the indent-based `sass` syntax, you need to pass options to the loader:
@@ -69,9 +69,9 @@ Note that `sass-loader` processes the non-indent-based `scss` syntax by default.
...
@@ -69,9 +69,9 @@ Note that `sass-loader` processes the non-indent-based `scss` syntax by default.
}
}
```
```
### Sharing Global Variables
### 共享全局变量
`sass-loader`also supports a `data` option which allows you to share common variables among all processed files without having to explicit import them:
Configuration of PostCSS can be done via `postcss.config.js` or `postcss-loader` options. For details, consult [postcss-loader docs](https://github.com/postcss/postcss-loader).
Processing templates is a little different, because most webpack template loaders such as `pug-loader` return a template function instead of a compiled HTML string. Instead of using `pug-loader`, we need to use a loader that returns the raw HTML string instead, e.g. `pug-plain-loader`:
模板的处理会稍微有些不同,因为绝大对数 webpack 的模板类 loader,诸如 `pug-loader`,会返回一个模板函数而不是一个编译好的 HTML 字符串。所以我们需要使用一个返回原始的 HTML 字符串的 loader,例如 `pug-plain-loader`,而不是使用 `pug-loader`。
If you also intend to use it to import `.pug` files as HTML strings in JavaScript, you will need to chain `raw-loader` after the preprocessing loader. Note however adding `raw-loader` would break the usage in Vue components, so you need to have two rules, one of them targeting Vue files using a `resourceQuery`, the other one (fallback) targeting JavaScript imports: