|
1 | | -# Version 2.3 |
| 1 | +## Installation |
| 2 | +[Node][node] and [Rollup][rollup] are required to use rollup-plugin-vue. Use [NPM][NPM] or [yarn][yarn] to add `rollup-plugin-vue` as development dependency to your project. |
| 3 | + |
| 4 | +### Using NPM |
| 5 | +``` |
| 6 | +npm install --save-dev rollup-plugin-vue |
| 7 | +``` |
| 8 | + |
| 9 | +### Using yarn |
| 10 | +``` |
| 11 | +yarn add --dev rollup-plugin-vue |
| 12 | +``` |
| 13 | + |
| 14 | +### Use plugin |
| 15 | +Next add `rollup-plugin-vue` to `rollup` plugins. |
| 16 | + |
| 17 | +``` js |
| 18 | +// rollup.config.js |
| 19 | +import vue from 'rollup-plugin-vue'; |
| 20 | + |
| 21 | +export default { |
| 22 | + plugins: [ |
| 23 | + vue(), |
| 24 | + ], |
| 25 | +}; |
| 26 | +``` |
| 27 | +## Configuration |
| 28 | +For most cases `rollup-plugin-vue` works out of the box. But, you can always configure it to your needs. |
| 29 | + |
| 30 | +### Style |
| 31 | +This section lists config options for `<style>` elements. |
| 32 | + |
| 33 | +#### Custom handler |
| 34 | +The `css` option accepts style handling options. |
| 35 | +- Set `css: null` to extract a consolidated style file in `dist/bundle.css`. |
| 36 | +- Set `css: false` to disable style at all. |
| 37 | +- Set `css: String` (eg: `css: 'dist/css/my-bundle.css`) to extract a consolidated style file in `dist/css/my-bundle.css`. |
| 38 | +- Set `css: Function` to provide a custom handler. Your handler would receive 3 parameters: |
| 39 | + - `style: String` - A string with all style elements' content concatenated. |
| 40 | + - `styles: Array` - A list of style elements. Each style element would an object with following keys: |
| 41 | + - `code: String` - Contents of the `<style>` element. |
| 42 | + - `id: String` - Path of the `.vue` file. |
| 43 | + - `lang: String` - Language defined on `<style>` element (defaults to `css`). |
| 44 | + - `module: Boolean` - Is `<style>` element a CSS module? |
| 45 | + - `scoped: Boolean` - Should `<style>` element be scoped? <p class="warning">Scoped styles are not supported yet.</p> |
| 46 | + - `map: Object` - Source map object. |
| 47 | + - `$compiled: { code: String, ?map: Object }` - If [auto styles](#auto-styles) is enabled, `<style>` is transformed to `css`. |
| 48 | + - `compile: Function` - An async compiler that takes two parameters: |
| 49 | + - `style: { code: String, lang: String, ?map: Object }` - Style code and language. |
| 50 | + - `options: { ?sass: Object, ?less: Object, ?cssModules: Object }` - Processing library configuration options. |
| 51 | + |
| 52 | + ``` js |
| 53 | + // rollup.config.js |
| 54 | + import fs from 'fs' |
| 55 | + import vue from 'rollup-plugin-vue' |
| 56 | + |
| 57 | + export default { |
| 58 | + ... |
| 59 | + plugins: [ |
| 60 | + vue({ |
| 61 | + css (style, styles, compiler) { |
| 62 | + fs.writeFileSync('dist/bundle.css', style) |
| 63 | + fs.writeFileSync('dist/bundle.sass', styles.map(style => style.code).concat('\n')) |
| 64 | + } |
| 65 | + }) |
| 66 | + ], |
| 67 | + ... |
| 68 | + } |
| 69 | + ``` |
| 70 | + |
| 71 | +#### Auto Styles |
| 72 | +Style elements are automatically processed using relevant libraries (eg: node-sass for scss/sass). This is enabled by default. Set `autoStyles: false` to disable. |
| 73 | + |
| 74 | +#### Style Languages |
| 75 | +You can specify `<style>` language using `lang` attribute (eg: `<style lang="scss"></style>`). |
| 76 | +List of supported style languages: |
| 77 | + |
| 78 | +- ##### CSS |
| 79 | +The default style language. |
| 80 | + |
| 81 | +- ##### Sass/Scss |
| 82 | +It uses `node-sass@^4.5.0` to process `sass/scss` style elements. You can provide `node-sass` configuration options by ```scss: { /* node-sass options */}```. |
| 83 | + |
| 84 | +- ##### Less |
| 85 | +It uses `less@^2.7.2` to process `less` style elements. You can provide `less` configuration options by ```less: { /* node-sass options */}```. |
| 86 | + |
| 87 | +<p class="tip" markdown="1"> |
| 88 | +`node-sass` and `less` are optional dependencies. If you are using `scss/sass/less` you should require (`yarn add --dev node-sass less`) them. |
| 89 | +</p> |
| 90 | + |
| 91 | +#### Use other plugins |
| 92 | +Set `autoStyles: false` and `styleToImport: true` to import style as a dependency and plugins like [rollup-plugin-scss](https://github.com/differui/rollup-plugin-sass) can be used. |
| 93 | + |
| 94 | +``` js |
| 95 | +// rollup.config.js |
| 96 | +import vue from 'rollup-plugin-vue' |
| 97 | +import scss from 'rollup-plugin-scss' |
| 98 | +
|
| 99 | +export default { |
| 100 | + ... |
| 101 | + plugins: [ |
| 102 | + vue({ autoStyles: false, styleToImport: true }), |
| 103 | + scss() |
| 104 | + ], |
| 105 | + ... |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +### Template |
| 110 | + |
| 111 | +#### Template Languages |
| 112 | + |
| 113 | +- ##### HTML |
| 114 | + |
| 115 | +- ##### Pug/Jade |
| 116 | + |
| 117 | +### Script |
| 118 | + |
| 119 | +#### Script Languages |
| 120 | + |
| 121 | +- ##### ES6/Babel |
| 122 | + |
| 123 | +- ##### Coffee |
| 124 | + |
| 125 | +### Custom template injection |
| 126 | + |
| 127 | +### Handle with(this) issue |
| 128 | + |
| 129 | +### include/exclude |
| 130 | + |
| 131 | +[node]: http://nodejs.org/ |
| 132 | +[rollup]: http://rollupjs.org |
| 133 | +[NPM]: https://www.npmjs.com/#getting-started |
| 134 | +[yarn]: http://yarnpkg.com/ |
0 commit comments