Skip to content

Commit 4af64ca

Browse files
committed
Merge remote-tracking branch 'upstream/master' into working
# Conflicts: # README.md
2 parents bc17a9b + 36276c0 commit 4af64ca

File tree

108 files changed

+6112
-11754
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+6112
-11754
lines changed

Diff for: docs/en/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Introduction
22

3-
### What is `vue-loader`?
3+
### What is Vue Loader?
44

55
`vue-loader` is a loader for webpack that can transform Vue components written in the following format into a plain JavaScript module:
66

@@ -9,7 +9,7 @@
99
There are many cool features provided by `vue-loader`:
1010

1111
- ES2015 enabled by default;
12-
- Allows using other webpack loaders for each part of a Vue component, for example SASS for `<style>` and Jade for `<template>`;
12+
- Allows using other webpack loaders for each part of a Vue component, for example Sass for `<style>` and Jade for `<template>`;
1313
- Allows custom sections in a .vue file that can have custom loader chains applied to them
1414
- Treat static assets referenced in `<style>` and `<template>` as module dependencies and handle them with webpack loaders;
1515
- Can simulate scoped CSS for each component;
@@ -32,7 +32,7 @@ But webpack can do more than that. With "loaders", we can teach webpack to trans
3232
- Transpile ES2015, CoffeeScript or TypeScript modules into plain ES5 CommonJS modules;
3333
- Optionally you can pipe the source code through a linter before doing the compilation;
3434
- Transpile Jade templates into plain HTML and inline it as a JavaScript string;
35-
- Transpile SASS files into plain CSS, then convert it into a JavaScript snippet that insert the resulting CSS as a `<style>` tag;
35+
- Transpile Sass files into plain CSS, then convert it into a JavaScript snippet that insert the resulting CSS as a `<style>` tag;
3636
- Process an image file referenced in HTML or CSS, moved it to the desired destination based on the path configurations, and naming it using its md5 hash.
3737

3838
webpack is so powerful that when you understand how it works, it can dramatically improve your front-end workflow. Its primary drawback is its verbose and complex configuration; but with this guide you should be able to find solutions for most common issues when using webpack with Vue.js and `vue-loader`.

Diff for: docs/en/SUMMARY.md

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
- [Production Build](workflow/production.md)
1919
- [Linting](workflow/linting.md)
2020
- [Testing](workflow/testing.md)
21-
- [Testing with Mocks](workflow/testing-with-mocks.md)
2221
- [Options Reference](options.md)
2322
- [loaders](options.md#loaders)
2423
- [preLoaders](options.md#preloaders)
@@ -34,4 +33,3 @@
3433
- [buble](options.md#buble)
3534
- [extractCSS](options.md#extractcss)
3635
- [optimizeSSR](options.md#optimizessr)
37-
- [cacheBusting](options.md#cachebusting)

Diff for: docs/en/configurations/advanced.md

+4-29
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ To do that, specify the `loaders` option for `vue-loader`:
1212

1313
> Note that `preLoaders` and `postLoaders` are only supported in 10.3.0+
1414
15-
### webpack 2.x
16-
1715
``` js
1816
module.exports = {
1917
// other options...
@@ -25,8 +23,8 @@ module.exports = {
2523
loader: 'vue-loader',
2624
options: {
2725
// `loaders` will overwrite the default loaders.
28-
// The following config will cause all <script> tags without "lang"
29-
// attribute to be loaded with coffee-loader
26+
// The following config will cause all `<script>` tags without `lang`
27+
// attribute to be loaded with `coffee-loader`
3028
loaders: {
3129
js: 'coffee-loader'
3230
},
@@ -43,8 +41,8 @@ module.exports = {
4341
// - For `html`, the result returned by the default loader
4442
// will be compiled JavaScript render function code.
4543
//
46-
// - For `css`, the result will be returned by vue-style-loader
47-
// which isn't particularly useful in most cases. Using a postcss
44+
// - For `css`, the result will be returned by `vue-style-loader`
45+
// which isn't particularly useful in most cases. Using a PostCSS
4846
// plugin will be a better option.
4947
postLoaders: {
5048
html: 'babel-loader'
@@ -59,27 +57,4 @@ module.exports = {
5957
}
6058
```
6159

62-
### webpack 1.x
63-
64-
``` js
65-
// webpack.config.js
66-
module.exports = {
67-
// other options...
68-
module: {
69-
loaders: [
70-
{
71-
test: /\.vue$/,
72-
loader: 'vue'
73-
}
74-
]
75-
},
76-
// `vue-loader` configurations
77-
vue: {
78-
loaders: {
79-
// same configuration rules as above
80-
}
81-
}
82-
}
83-
```
84-
8560
A more practical usage of the advanced loader configuration is [extracting CSS inside components into a single file](./extract-css.md).

Diff for: docs/en/configurations/asset-url.md

+18
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,26 @@ will be compiled into:
1414
createElement('img', { attrs: { src: require('../image.png') }})
1515
```
1616

17+
### Transform Rules
18+
19+
- If the URL is an absolute path (e.g. `/images/foo.png`), it will be preserved as-is.
20+
21+
- If the URL starts with `.`, it's interpreted as a relative module request and resolved based on the folder structure on your file system.
22+
23+
- If the URL starts with `~`, anything after it is interpreted as a module request. This means you can even reference assets inside node modules:
24+
25+
``` html
26+
<img src="~/some-npm-package/foo.png">
27+
```
28+
29+
- (13.7.0+) If the URL starts with `@`, it's also interpreted as a module request. This is useful if your webpack config has an alias for `@`, which by default points to `/src` in any project created by `vue-cli`.
30+
31+
### Related Loaders
32+
1733
Because `.png` is not a JavaScript file, you will need to configure webpack to use [file-loader](https://github.com/webpack/file-loader) or [url-loader](https://github.com/webpack/url-loader) to handle them. The project scaffolded with `vue-cli` has also configured this for you.
1834

35+
### Why
36+
1937
The benefits of all this are:
2038

2139
1. `file-loader` allows you to designate where to copy and place the asset file, and how to name it using version hashes for better caching. Moreover, this also means **you can just place images next to your `*.vue` files and use relative paths based on the folder structure instead of worrying about deployment URLs**. With proper config, webpack will auto-rewrite the file paths into correct URLs in the bundled output.

Diff for: docs/en/configurations/custom-blocks.md

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ comp-a h2 {
4141
#### webpack.config.js
4242

4343
``` js
44-
// webpack 2.x
4544
var ExtractTextPlugin = require("extract-text-webpack-plugin")
4645

4746
module.exports = {

Diff for: docs/en/configurations/extract-css.md

-36
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ Note this only extracts `*.vue` files though - CSS imported in JavaScript still
3939

4040
Example config to extract all the processed CSS in all Vue components into a single CSS file:
4141

42-
### webpack 2.x
43-
44-
4542
``` js
4643
// webpack.config.js
4744
var ExtractTextPlugin = require("extract-text-webpack-plugin")
@@ -69,36 +66,3 @@ module.exports = {
6966
]
7067
}
7168
```
72-
73-
### webpack 1.x
74-
75-
``` bash
76-
npm install extract-text-webpack-plugin --save-dev
77-
```
78-
79-
``` js
80-
// webpack.config.js
81-
var ExtractTextPlugin = require("extract-text-webpack-plugin")
82-
83-
module.exports = {
84-
// other options...
85-
module: {
86-
loaders: [
87-
{
88-
test: /\.vue$/,
89-
loader: 'vue'
90-
},
91-
]
92-
},
93-
vue: {
94-
loaders: {
95-
css: ExtractTextPlugin.extract("css"),
96-
// you can also include <style lang="less"> or other langauges
97-
less: ExtractTextPlugin.extract("css!less")
98-
}
99-
},
100-
plugins: [
101-
new ExtractTextPlugin("style.css")
102-
]
103-
}
104-
```

Diff for: docs/en/configurations/pre-processors.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ In webpack, all pre-processors need to be applied with a corresponding loader. `
44

55
### CSS
66

7-
For example, let's compile our `<style>` tag with SASS:
7+
For example, let's compile our `<style>` tag with Sass:
88

99
``` bash
1010
npm install sass-loader node-sass --save-dev
@@ -20,7 +20,7 @@ Under the hood, the text content inside the `<style>` tag will be first compiled
2020

2121
#### sass-loader caveat
2222

23-
Contrary to what its name indicates, [*sass*-loader](https://github.com/jtangelder/sass-loader) parses *SCSS* syntax by default. If you actually want to use the indented *SASS* syntax, you have to configure vue-loader's options for sass-loader accordingly.
23+
Contrary to what its name indicates, [*sass*-loader](https://github.com/jtangelder/sass-loader) parses *SCSS* syntax by default. If you actually want to use the indented *Sass* syntax, you have to configure vue-loader's options for sass-loader accordingly.
2424

2525
```javascript
2626
{

Diff for: docs/en/features/css-modules.md

+1-12
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,14 @@ CSS Modules are processed via [css-loader](https://github.com/webpack/css-loader
8181
``` js
8282
{
8383
modules: true,
84-
importLoaders: true,
84+
importLoaders: 1,
8585
localIdentName: '[hash:base64]'
8686
}
8787
```
8888

8989
You can use vue-loader's `cssModules` option to provide additional query options to `css-loader`:
9090

9191
``` js
92-
// webpack 1
93-
vue: {
94-
cssModules: {
95-
// overwrite local ident name
96-
localIdentName: '[path][name]---[local]---[hash:base64:5]',
97-
// enable camelCase
98-
camelCase: true
99-
}
100-
}
101-
102-
// webpack 2
10392
module: {
10493
rules: [
10594
{

Diff for: docs/en/features/es2015.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ can be simplified to:
4848

4949
``` html
5050
<my-component>
51-
<template scope="{ id, text }">
51+
<template slot-scope="{ id, text }">
5252
<span>{{ id }} {{ text }}</span>
5353
</template>
5454
</my-component>

Diff for: docs/en/features/postcss.md

+27-15
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,30 @@ Any CSS output processed by `vue-loader` is piped through [PostCSS](https://gith
44

55
## Using a Config File
66

7-
Starting in 11.0 `vue-loader` supports auto-loading the same PostCss config files supported by [`postcss-loader`](https://github.com/postcss/postcss-loader#usage):
7+
`vue-loader` supports auto-loading the same PostCss config files supported by [`postcss-loader`](https://github.com/postcss/postcss-loader#usage):
88

99
- `postcss.config.js`
1010
- `.postcssrc`
1111
- `postcss` field in `package.json`
1212

1313
Using a config file allows you to share the same config between your normal CSS files processed by `postcss-loader` and the CSS inside `*.vue` files, and is recommended.
1414

15-
## Inline Options
15+
## Using with `postcss-loader`
1616

17-
Alternatively, you can specify postcss config specifically for `*.vue` files using the `postcss` option for `vue-loader`.
17+
Since `vue-loader` handles PostCSS on its styles internally, you only need to apply `postcss-loader` to standalone CSS files. There's no need to specify `lang="postcss"` on a style block if there is a PostCSS config file in your project.
1818

19-
Example usage in webpack 1.x:
19+
Sometimes the user may want to use `lang="postcss"` only for syntax highlighting purposes. Starting in 13.6.0, if no loader has been explicitly configured for the following common PostCSS extensions (via `vue-loader`'s own `loaders` option), they will simply go through `vue-loader`'s default PostCSS transforms:
2020

21-
``` js
22-
// webpack.config.js
23-
module.exports = {
24-
// other configs...
25-
vue: {
26-
// use custom postcss plugins
27-
postcss: [require('postcss-cssnext')()]
28-
}
29-
}
30-
```
21+
- `postcss`
22+
- `pcss`
23+
- `sugarss`
24+
- `sss`
25+
26+
## Inline Options
3127

32-
For webpack 2.x:
28+
Alternatively, you can specify PostCSS config specifically for `*.vue` files using the `postcss` option for `vue-loader`.
29+
30+
Example:
3331

3432
``` js
3533
// webpack.config.js
@@ -66,3 +64,17 @@ In addition to providing an Array of plugins, the `postcss` option also accepts:
6664
}
6765
}
6866
```
67+
68+
### Disabling Auto Config File Loading
69+
70+
In `13.6.0+`, auto PostCSS config file loading can be disabled by specifying `postcss.useConfigFile: false`:
71+
72+
``` js
73+
postcss: {
74+
useConfigFile: false,
75+
plugins: [/* ... */],
76+
options: {/* ... */}
77+
}
78+
```
79+
80+
This allows the PostCSS configuration inside `*.vue` files to be entirely controlled by the inline config.

Diff for: docs/en/features/scoped-css.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The above will be compiled into:
6464
.a[data-v-f3f3eg9] .b { /* ... */ }
6565
```
6666

67-
Some pre-processors, such as SASS, may not be able to parse `>>>` properly. In those cases you can use the `/deep/` combinator instead - it's an alias for `>>>` and works exactly the same.
67+
Some pre-processors, such as Sass, may not be able to parse `>>>` properly. In those cases you can use the `/deep/` combinator instead - it's an alias for `>>>` and works exactly the same.
6868

6969
### Dynamically Generated Content
7070

0 commit comments

Comments
 (0)