Skip to content

Commit 0d8ab8d

Browse files
committed
simplify readme
1 parent d9f50e0 commit 0d8ab8d

File tree

1 file changed

+5
-314
lines changed

1 file changed

+5
-314
lines changed

README.md

Lines changed: 5 additions & 314 deletions
Original file line numberDiff line numberDiff line change
@@ -1,323 +1,14 @@
11
# vue-loader [![Build Status](https://circleci.com/gh/vuejs/vue-loader/tree/master.svg?style=shield)](https://circleci.com/gh/vuejs/vue-loader/tree/master) [![npm package](https://badge.fury.io/js/vue-loader.svg)](https://www.npmjs.com/package/vue-loader)
22

3-
> Vue.js component loader for [Webpack](http://webpack.github.io), using Webpack loaders for the parts.
3+
> Vue.js component loader for [Webpack](http://webpack.github.io).
44
55
It allows you to write your components in this format:
66

77
![screenshot](http://blog.evanyou.me/images/vue-component.png)
88

9-
## Table of Contents
9+
For detailed usage, checkout the [documentation](http://vuejs.github.io/vue-loader/).
1010

11+
There are also some example projects:
1112

12-
- [Basic Usage](#basic-usage)
13-
- [ES2015 by Default](#es2015-by-default)
14-
- [CSS Pre-Processors](#css-pre-processors)
15-
- [PostCSS](#postcss)
16-
- [Template Pre-Processors](#template-pre-processors)
17-
- [Src Imports](#src-imports)
18-
- [Asset URL Handling](#asset-url-handling)
19-
- [Scoped CSS](#scoped-css)
20-
- [Hot Reload](#hot-reload)
21-
- [Syntax Highlighting](#syntax-highlighting)
22-
- [Linting](#linting)
23-
- [Testing](#testing)
24-
- [Advanced Loader Configuration](#advanced-loader-configuration)
25-
- [Example Project](https://github.com/vuejs/vue-loader-example)
26-
27-
## Basic Usage
28-
29-
Config Webpack:
30-
31-
``` js
32-
// webpack.config.js
33-
module.exports = {
34-
entry: './main.js',
35-
output: {
36-
filename: 'build.js'
37-
},
38-
module: {
39-
loaders: [
40-
{ test: /\.vue$/, loader: 'vue' },
41-
]
42-
}
43-
}
44-
```
45-
46-
And this is all you need to do in your main entry file:
47-
48-
``` js
49-
// main.js
50-
var Vue = require('vue')
51-
var App = require('./app.vue')
52-
53-
new Vue({
54-
el: 'body',
55-
components: {
56-
app: App
57-
}
58-
})
59-
```
60-
61-
In your HTML:
62-
63-
``` html
64-
<body>
65-
<app></app>
66-
<script src="build.js"></script>
67-
</body>
68-
```
69-
70-
## ES2015 by Default
71-
72-
`vue-loader` automatically applies Babel transforms to the JavaScript inside `*.vue` components. Write ES2015 today!
73-
74-
**Compatibility Note:** vue-loader 7.0+ uses Babel 6. If you need to use Babel 5 for transpiling your code, use vue-loader 6.x.
75-
76-
The default Babel options used for Vue.js components are:
77-
78-
``` js
79-
{
80-
presets: ['es2015'],
81-
plugins: ['transform-runtime']
82-
}
83-
```
84-
85-
If you wish to override this, you can add a `babel` field in your webpack config, which will be applied to all JavaScript processed by `babel-loader`. For example:
86-
87-
``` js
88-
// webpack.config.js
89-
module.exports = {
90-
// other configs...
91-
babel: {
92-
// enable stage 0 transforms.
93-
// make sure to install babel-presets-stage-0
94-
presets: ['es2015', 'stage-0'],
95-
plugins: ['transform-runtime']
96-
}
97-
}
98-
```
99-
100-
## CSS Pre-Processors
101-
102-
`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):
103-
104-
``` html
105-
<style lang="stylus">
106-
/* use stylus here */
107-
</style>
108-
```
109-
110-
You can also include Webpack loader queries in the `lang` attribute:
111-
112-
``` html
113-
<style lang="sass?outputStyle=expanded">
114-
/* use sass here with expanded output */
115-
</style>
116-
```
117-
118-
## PostCSS
119-
120-
Any CSS output via `vue-loader` 6.0+ is piped through [PostCSS](https://github.com/postcss/postcss) for [scoped CSS](#scoped-css) rewriting and aut-prefixed by default using [autoprefixer](https://github.com/postcss/autoprefixer). You can configure autoprefixer or provide your own PostCSS plugins in the `vue` section of your webpack config:
121-
122-
``` js
123-
// webpack.config.js
124-
module.exports = {
125-
// other configs...
126-
vue: {
127-
// configure autoprefixer
128-
autoprefixer: {
129-
browsers: ['last 2 versions']
130-
}
131-
}
132-
}
133-
```
134-
135-
Using other PostCSS plugins:
136-
137-
``` js
138-
// webpack.config.js
139-
module.exports = {
140-
// other configs...
141-
vue: {
142-
// use custom postcss plugins
143-
postcss: [require('cssnext')()],
144-
// disable vue-loader autoprefixing.
145-
// this is a good idea since cssnext comes with it too.
146-
autoprefixer: false
147-
}
148-
}
149-
```
150-
151-
## Template Pre-Processors
152-
153-
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`.
154-
155-
## Src Imports
156-
157-
If you want, you can separate your templates, styles or scripts into separate files and import them using the `src` attribute:
158-
159-
``` html
160-
<template src="./template.html"></template>
161-
<style src="./style.css"></style>
162-
<script src="./script.js"></script>
163-
```
164-
165-
Beware that `src` imports follow similar rules to `require()` calls, which means for relative paths you need to start with `./`, and you can import resources from installed NPM packages, e.g. `<style src="todomvc-app-css/index.css">`.
166-
167-
## Asset URL Handling
168-
169-
By default, `vue-loader` automatically processes your style and template files with `css-loader` and `vue-html-loader` - this means that all asset URLs such as `<img src="...">`, `background: url(...)` and CSS `@import` are **resolved as module dependencies**.
170-
171-
For example, `url(image.png)` will be translated into `require('./image.png')`. Because `.png` is not JavaScript, 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. This may feel cumbersome, but it gives you some very powerful benefits in managing your static assets this way:
172-
173-
1. `file-loader` allows you to customize where to copy and place the asset file (by specifying `publicPath` in your Webpack config), and how they should be named with version hashes.
174-
175-
2. `url-loader` allows you to conditionally load a file as a inline Data URL if they are smaller than a given threshold.
176-
177-
For more details, see the respective documentations for [vue-html-loader](https://github.com/vuejs/vue-html-loader) and [css-loader](https://github.com/webpack/css-loader).
178-
179-
## Scoped CSS
180-
181-
> Experimental
182-
183-
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 using PostCSS to transform the following:
184-
185-
``` html
186-
<style scoped>
187-
.example {
188-
color: red;
189-
}
190-
</style>
191-
<template>
192-
<div class="example">hi</div>
193-
</template>
194-
```
195-
196-
Into the following:
197-
198-
``` html
199-
<style>
200-
.example[_v-f3f3eg9] {
201-
color: red;
202-
}
203-
</style>
204-
<template>
205-
<div class="example" _v-f3f3eg9>hi</div>
206-
</template>
207-
```
208-
209-
#### Notes
210-
211-
1. You can include both scoped and non-scoped styles in the same component.
212-
213-
2. A child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS.
214-
215-
3. If you are nesting a component inside itself, the styles may still leak down since they are considered the same component.
216-
217-
4. Partials are not affected by scoped styles.
218-
219-
## Hot Reload
220-
221-
> Experimental
222-
223-
When using `webpack-dev-server` in hot mode, `vue-loader` enables hot component reloading for Vue.js 1.0.0+. An example config:
224-
225-
``` js
226-
// webpack.config.js
227-
module.exports = {
228-
entry: './src/main.js',
229-
output: {
230-
publicPath: '/static/',
231-
filename: 'build.js'
232-
},
233-
module: {
234-
loaders: [
235-
{ test: /\.vue$/, loader: 'vue' },
236-
]
237-
},
238-
devtool: '#source-map'
239-
}
240-
```
241-
242-
In `index.html`, include the bundle:
243-
244-
``` html
245-
<script src="static/build.js"></script>
246-
```
247-
248-
Then, run the dev server with:
249-
250-
``` bash
251-
webpack-dev-server --inline --hot
252-
```
253-
254-
Finally, visit `http://localhost:8080/` to see the app with hot reloading.
255-
256-
For a complete example with hot reloading in action, see [vue-hackernews](https://github.com/vuejs/vue-hackernews).
257-
258-
### Hot Reload Notes
259-
260-
- When a component is hot-reloaded, its current state is preserved. However, the component itself is destroyed and recreated, so all of its lifecycle hooks will be called accordingly. Make sure to properly teardown any side effects in your lifecycle hooks.
261-
262-
- Private state for child components of a hot-reloaded component is not guaranteed to be preserved across reloads.
263-
264-
- A root Vue instance or a manually mounted instance cannot be hot-reloaded. It will always force a full reload.
265-
266-
## Advanced Loader configuration
267-
268-
By default, `vue-loader` will try to use the loader with the same name as
269-
the `lang` attribute, but you can configure which loader should be used.
270-
271-
#### Example: Use CoffeeScript for all `<script>` tags
272-
273-
``` js
274-
module.exports = {
275-
// entry, output...
276-
module: {
277-
loaders: [{
278-
test: /\.vue$/, loader: 'vue'
279-
}]
280-
},
281-
vue: {
282-
loaders: {
283-
js: 'coffee'
284-
}
285-
},
286-
devtool: '#source-map'
287-
}
288-
```
289-
290-
#### Example: Extracting CSS into a Single File
291-
292-
To extract out the generated css into a separate file,
293-
use this Webpack config:
294-
295-
``` js
296-
var ExtractTextPlugin = require("extract-text-webpack-plugin");
297-
298-
module.exports = {
299-
// entry, output...
300-
module: {
301-
loaders: [
302-
{
303-
test: /\.vue$/, loader: 'vue'
304-
},
305-
]
306-
},
307-
vue: {
308-
loaders: {
309-
css: ExtractTextPlugin.extract("css"),
310-
stylus: ExtractTextPlugin.extract("css!stylus")
311-
}
312-
},
313-
plugins: [
314-
new ExtractTextPlugin("[name].css")
315-
]
316-
}
317-
```
318-
319-
## Example Project
320-
321-
For a simple setup example, see [vue-loader-example](https://github.com/vuejs/vue-loader-example).
322-
323-
For an actual project with dev setup with hot reloading and production setup with minification, see [vue-hackernews](https://github.com/vuejs/vue-hackernews).
13+
- [vue-loader-example](https://github.com/vuejs/vue-loader-example/)
14+
- [vue-hackernews](https://github.com/vuejs/vue-hackernews)

0 commit comments

Comments
 (0)