You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -69,29 +72,97 @@ var app = new Vue(appOptions).$mount('#app')
69
72
70
73
## Pre-Processors
71
74
72
-
`vue-loader` allows you to use per-file pre-processors inside `*.vue` componentswith 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):
73
76
74
77
```html
75
78
<stylelang="stylus">
76
79
/* use stylus here */
77
80
</style>
78
81
```
79
82
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:
81
84
82
85
```html
83
86
<stylelang="sass?outputStyle=expanded">
84
87
/* use sass here with expanded output */
85
88
</style>
86
89
```
87
90
88
-
#### A Note on Loader Dependencies
91
+
##Template Pre-Processors
89
92
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`.
91
94
92
-
#### Template Pre-Processors
95
+
##Scoped Styles
93
96
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
+
<divclass="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
+
<divclass="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:
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).
95
166
96
167
## Style Imports
97
168
@@ -180,4 +251,6 @@ module.exports = {
180
251
181
252
## Example Project
182
253
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