Skip to content

Commit a1a5892

Browse files
committed
readme
1 parent f057ad5 commit a1a5892

File tree

1 file changed

+80
-7
lines changed

1 file changed

+80
-7
lines changed

README.md

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ It allows you to write your components in this format:
3232

3333
- [Basic Usage](#basic-usage)
3434
- [Pre-Processors](#pre-processors)
35+
- [Template Pre-Processors](#template-pre-processors)
36+
- [Scoped Styles](#scoped-styles)
37+
- [Hot Reload](#hot-reload)
3538
- [Style Imports](#style-imports)
3639
- [Asset URL Handling](#asset-url-handling)
3740
- [Advanced Loader Configuration](#advanced-loader-configuration)
@@ -69,29 +72,97 @@ var app = new Vue(appOptions).$mount('#app')
6972

7073
## Pre-Processors
7174

72-
`vue-loader` allows you to use per-file pre-processors inside `*.vue` components with the `lang` attribute:
75+
`vue-loader` allows you to use other Webpack loaders to pre-process the different parts inside your `*.vue` components. Just specify the loader to use with the `lang` attribute (you also need to install the loader, obviously):
7376

7477
``` html
7578
<style lang="stylus">
7679
/* use stylus here */
7780
</style>
7881
```
7982

80-
The `lang` attribute will be used to automatically locate the loader to use, and you can pass Webpack loader queries in it as well:
83+
You can also include Webpack loader queries in the `lang` attribute:
8184

8285
``` html
8386
<style lang="sass?outputStyle=expanded">
8487
/* use sass here with expanded output */
8588
</style>
8689
```
8790

88-
#### A Note on Loader Dependencies
91+
## Template Pre-Processors
8992

90-
By default, `vue-loader` requires `vue-html-loader`, `css-loader` and `style-loader` as peer dependencies. In order to use pre-processors, you also need to install the corresponding Webpack loader for that language.
93+
For template pre-processors, you should install `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
9194

92-
#### Template Pre-Processors
95+
## Scoped Styles
9396

94-
For template pre-processors, you should install `template-html-loader` plus the raw templating engine. For example to use `jade`, you will need to install both `template-html-loader` and `jade` instead of `jade-loader`.
97+
When a `<style>` tag has the `scoped` attribute, its CSS will apply to elements of the current component only. This is similar to the style encapsulation found in Shadow DOM, but doesn't require any polyfills. It is achieved by transforming the following:
98+
99+
``` html
100+
<style>
101+
.example {
102+
color: red;
103+
}
104+
</style>
105+
<template>
106+
<div class="example">hi</div>
107+
</template>
108+
```
109+
110+
Into the following:
111+
112+
``` html
113+
<style>
114+
.example[_v-1] {
115+
color: red;
116+
}
117+
</style>
118+
<template>
119+
<div class="example" _v-1>hi</div>
120+
</template>
121+
```
122+
123+
#### Notes
124+
125+
1. You can include both scoped and non-scoped styles in the same component.
126+
127+
2. A child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS.
128+
129+
3. Partials are not affected by scoped styles.
130+
131+
## Hot Reload
132+
133+
When using `webpack-dev-server` in hot mode, `vue-loader` enables hot component reloading for Vue.js 1.0.0+. An example config:
134+
135+
``` js
136+
module.exports = {
137+
entry: ['webpack/hot/dev-server', './src/main.js'],
138+
output: {
139+
publicPath: '/static/',
140+
filename: 'build.js'
141+
},
142+
module: {
143+
loaders: [
144+
{ test: /\.vue$/, loader: 'vue' },
145+
]
146+
},
147+
devtool: '#source-map'
148+
}
149+
```
150+
151+
In `index.html`, include the bundle:
152+
153+
``` html
154+
<script src="/static/build.js"></script>
155+
```
156+
157+
Then, run the dev server with:
158+
159+
``` bash
160+
webpack-dev-server --hot --config build/webpack.dev.config.js
161+
```
162+
163+
Finally, visit `http://localhost:8080/webpack-dev-server/` to see the app with hot reloading.
164+
165+
For a complete example with hot reloading in action, see [vue-hackernews](https://github.com/vuejs/vue-hackernews).
95166

96167
## Style Imports
97168

@@ -180,4 +251,6 @@ module.exports = {
180251

181252
## Example Project
182253

183-
See [vue-loader-example](https://github.com/vuejs/vue-loader-example).
254+
For a simple setup example, see [vue-loader-example](https://github.com/vuejs/vue-loader-example).
255+
256+
For an actual project with dev setup with hot reloading and production setup with minification, see [vue-hackernews](https://github.com/vuejs/vue-hackernews).

0 commit comments

Comments
 (0)