Skip to content
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

add esModule support #349

Merged
merged 2 commits into from
Sep 14, 2016
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
8 changes: 8 additions & 0 deletions docs/en/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@
- type: `Object`

Pass options to the template rendering engine (via [consolidate](https://github.com/tj/consolidate.js)) if you are using a non-html templating language.

### esModule

- ^9.4.3
- type: `Boolean`
- default: `undefined`

Whether to emit esModule compatible code. By default vue-loader will emit default export in commonjs format like `module.exports = ....`. When `esModule` is set to true, default export will be transpiled into `exports.__esModule = true; exports = ...`. Useful for interoperating with transpiler other than Bable, like TypeScript.
6 changes: 5 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ module.exports = function (content) {
'")}\n'
}
// final export
output += '\nmodule.exports = __vue_exports__\n'
if (options.esModule) {
output += '\nexports.__esModule = true;\nexports["default"] = __vue_exports__\n'
} else {
output += '\nmodule.exports = __vue_exports__\n'
}
} else {
// inject-loader support
output +=
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,24 @@ describe('vue-loader', function () {
done()
})
})

it('support es compatible modules', function (done) {
test({
entry: './test/fixtures/basic.vue',
vue: {
esModule: true
}
}, function (window, module, rawModule) {
expect(rawModule.__esModule).to.equal(true)
var vnode = mockRender(rawModule.default, {
msg: 'hi'
})
expect(vnode.tag).to.equal('h2')
expect(vnode.data.staticClass).to.equal('red')
expect(vnode.children[0]).to.equal('hi')

expect(rawModule.default.data().msg).to.contain('Hello from Component A!')
done()
})
})
})