Skip to content

add vue-template-compiler options passing #976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- [cssSourceMap](options.md#csssourcemap)
- [esModule](options.md#esmodule)
- [preserveWhitespace](options.md#preservewhitespace)
- [compilerModules](options.md#compilermodules)
- [compilerDirectives](options.md#compilerdirectives)
- [transformToRequire](options.md#transformtorequire)
- [buble](options.md#buble)
- [extractCSS](options.md#extractcss)
Expand Down
16 changes: 16 additions & 0 deletions docs/en/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ module.exports = {

If set to `false`, the whitespaces between HTML tags in templates will be ignored.

### compilerModules

- type: `Array<ModuleOptions>`
- default: `[]`

Configure `modules` options for `vue-template-compiler`, In about details, see more [`modules` option](https://github.com/vuejs/vue/blob/dev/packages/vue-template-compiler/README.md#compilercompiletemplate-options) of `vue-template-compiler`.

### compilerDirectives

- type: `{ [tag: string]: Function }`
- default: `{}` (v13.0.5+)

> version note: in v12.x, supported in v12.2.3+

Configure `directives` options for `vue-template-compiler`, In about details, see more [`directives` option](https://github.com/vuejs/vue/blob/dev/packages/vue-template-compiler/README.md#compilercompiletemplate-options) of `vue-template-compiler`.

### transformToRequire

- type: `{ [tag: string]: string | Array<string> }`
Expand Down
2 changes: 2 additions & 0 deletions docs/ja/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- [cssSourceMap](options.md#csssourcemap)
- [esModule](options.md#esmodule)
- [preserveWhitespace](options.md#preservewhitespace)
- [compilerModules](options.md#compilermodules)
- [compilerDirectives](options.md#compilerdirectives)
- [transformToRequire](options.md#transformtorequire)
- [buble](options.md#buble)
- [extractCSS](options.md#extractcss)
Expand Down
18 changes: 17 additions & 1 deletion docs/ja/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,26 @@ module.exports = {
### preserveWhitespace

- 型: `boolean`
- デフォルトx: `true`
- デフォルト: `true`

もし `false` に設定されていたら、テンプレート内の HTML タグ間の空白は無視されます。

### compilerModules

- 型: `Array<ModuleOptions>`
- デフォルト: `[]`

`vue-template-compiler` の `modules` オプションを設定します。詳細については `vue-template-compiler` の [`modules` option](https://github.com/vuejs/vue/blob/dev/packages/vue-template-compiler/README.md#compilercompiletemplate-options) を参照してください。

### compilerDirectives

- 型: `{ [tag: string]: Function }`
- デフォルト: `{}` (v13.0.5 以降)

> バージョンメモ: v12.x においては、v12.2.3 以降からサポートされます。

`vue-template-compiler` の `directives` オプションを設定します。詳細については `vue-template-compiler` の [`directives` option](https://github.com/vuejs/vue/blob/dev/packages/vue-template-compiler/README.md#compilercompiletemplate-options) を参照してください。

### transformToRequire

- 型: `{ [tag: string]: string | Array<string> }`
Expand Down
1 change: 1 addition & 0 deletions lib/template-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = function (html) {
var compilerOptions = {
preserveWhitespace: options.preserveWhitespace,
modules: defaultModules.concat(userModules || []),
directives: vueOptions.compilerDirectives || options.compilerDirectives || {},
scopeId: options.hasScoped ? options.id : null,
comments: options.hasComment
}
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/custom-directive.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<p v-i18n="keypath"></p>
</template>
25 changes: 24 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function mockRender (options, data) {
}
function e (text = '') {
return {
text: text,
text: text,
isComment: true
}
}
Expand Down Expand Up @@ -899,6 +899,29 @@ describe('vue-loader', function () {
})
})

it('custom compiler directives', done => {
test({
entry: './test/fixtures/custom-directive.vue',
vue: {
compilerDirectives: {
i18n (el, dir) {
if (dir.name === 'i18n' && dir.value) {
el.i18n = dir.value
if (!el.props) {
el.props = []
}
el.props.push({ name: 'textContent', value: `_s(${JSON.stringify(dir.value)})` })
}
}
}
}
}, (window, module) => {
var vnode = mockRender(module)
expect(vnode.data.domProps.textContent).to.equal('keypath')
done()
})
})

it('functional component with styles', done => {
test({
entry: './test/fixtures/functional-style.vue'
Expand Down