Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit fa7661e

Browse files
authored
fix: Handle Vue.extend constructor export from .vue file (#206)
* test: Typescript Vue.extend component export * chore: Bump @vue/component-compiler version * chore: Remove unnecessary virtual extension from .vue block query
1 parent 98e75eb commit fa7661e

File tree

6 files changed

+76
-16
lines changed

6 files changed

+76
-16
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"rollup-plugin-image": "^1.0.2",
7373
"rollup-plugin-md": "^0.0.7",
7474
"rollup-plugin-node-resolve": "^3.3.0",
75+
"rollup-plugin-typescript": "^0.8.1",
7576
"ts-jest": "^22.4.5",
7677
"typescript": "^2.8.3",
7778
"vue": "^2.5.16",

Diff for: src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const createVuePartRequest: VuePartRequestCreator = ((
8080
.filter(it => it !== undefined)
8181
.join('.')
8282

83-
return `${path.basename(filename)}.${lang}?${queryString.stringify(query)}`
83+
return `${path.basename(filename)}?${queryString.stringify(query)}`
8484
}) as VuePartRequestCreator
8585

8686
createVuePartRequest.defaultLang = {

Diff for: test/fixtures/with-script-typescript.vue

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<h1 id="test" :style="style">Hello</h1>
3+
</template>
4+
5+
<script lang="ts">
6+
// @ts-ignore
7+
import Vue, { VueConstructor } from 'vue'
8+
9+
export default Vue.extend({
10+
data() {
11+
return {
12+
style: { color: 'red' }
13+
}
14+
}
15+
})
16+
</script>

Diff for: test/setup/index.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,23 @@ export async function build(filename, css = false): Promise<string> {
2424
plugins: [
2525
pluginCreateVueApp(input, filename),
2626
pluginCSS({
27-
include: '**/*.css?*',
2827
output: (s: string) => {
2928
style = s
3029
}
3130
}),
3231
pluginVue(options),
3332
...plugins
3433
],
34+
external: ['vue']
3535
})
3636

3737
cache[cacheKey] = (await bundle.generate({
3838
format: 'iife',
39-
name: 'App'
40-
})).code + (style ? `;(function() {
39+
name: 'App',
40+
globals: {
41+
vue: 'Vue'
42+
}
43+
})).code + (style ? `\n;(function() {
4144
var s = document.createElement('style');
4245
s.type = 'text/css';
4346
document.head.appendChild(s);
@@ -62,8 +65,12 @@ export async function open(name: string, browser: Browser, code: string, id: str
6265
</head>
6366
<body>
6467
<div id="app"></div>
65-
<script>${await VUE_SOURCE}</script>
66-
<script>${await code}</script>
68+
<script>
69+
${await VUE_SOURCE}
70+
</script>
71+
<script>
72+
${await code}
73+
</script>
6774
</body>
6875
</html>`
6976

Diff for: test/setup/plugins.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@ const pluginNodeResolve = require('rollup-plugin-node-resolve')
33
const pluginCommonJS = require('rollup-plugin-commonjs')
44
const pluginImage = require('rollup-plugin-image')
55
const pluginMarkdown = require('rollup-plugin-md')
6+
const pluginTypescript = require('rollup-plugin-typescript')
7+
const path = require('path')
68

79
export const plugins = [
810
pluginImage(),
911
pluginMarkdown(),
1012
pluginNodeResolve(),
1113
pluginCommonJS(),
14+
pluginTypescript({
15+
tsconfig: false,
16+
module: 'es2015'
17+
}),
1218
pluginBabel({
1319
presets: [
14-
[require.resolve('@babel/preset-env'), {
15-
modules: false,
16-
targets: {
17-
browsers: ['last 2 versions']
20+
[
21+
require.resolve('@babel/preset-env'),
22+
{
23+
modules: false,
24+
targets: {
25+
browsers: ['last 2 versions']
26+
}
1827
}
19-
}]
28+
]
2029
],
2130
babelrc: false,
2231
runtimeHelpers: true
@@ -30,7 +39,8 @@ export function pluginCreateVueApp(filename: string, component: string): any {
3039
if (id === filename) return filename
3140
},
3241
load(id) {
33-
if (id === filename) return `
42+
if (id === filename)
43+
return `
3444
import Component from '${component}'
3545
3646
Vue.config.productionTip = false
@@ -45,4 +55,4 @@ export function pluginCreateVueApp(filename: string, component: string): any {
4555
`
4656
}
4757
}
48-
}
58+
}

Diff for: yarn.lock

+29-3
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@
581581
vue-template-es2015-compiler "^1.6.0"
582582

583583
"@vue/component-compiler@^3.3.2":
584-
version "3.3.2"
585-
resolved "https://registry.yarnpkg.com/@vue/component-compiler/-/component-compiler-3.3.2.tgz#cccb36a698025c1ff93f8bd3ee7ed6ebc42c27c5"
584+
version "3.3.3"
585+
resolved "https://registry.yarnpkg.com/@vue/component-compiler/-/component-compiler-3.3.3.tgz#f23b5353515025e81d36448b71422b2510939502"
586586
dependencies:
587587
"@vue/component-compiler-utils" "^1.2.1"
588588
clean-css "^4.1.11"
@@ -1356,6 +1356,10 @@ compare-func@^1.3.1:
13561356
array-ify "^1.0.0"
13571357
dot-prop "^3.0.0"
13581358

1359+
1360+
version "2.0.1"
1361+
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-2.0.1.tgz#1edc1f93687fd97a325c59f55e45a07db106aca6"
1362+
13591363
compare-versions@^3.1.0:
13601364
version "3.2.1"
13611365
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.2.1.tgz#a49eb7689d4caaf0b6db5220173fd279614000f7"
@@ -3089,10 +3093,14 @@ jest@^22.4.2:
30893093
import-local "^1.0.0"
30903094
jest-cli "^22.4.3"
30913095

3092-
js-base64@^2.1.8, js-base64@^2.1.9:
3096+
js-base64@^2.1.8:
30933097
version "2.4.3"
30943098
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.3.tgz#2e545ec2b0f2957f41356510205214e98fad6582"
30953099

3100+
js-base64@^2.1.9:
3101+
version "2.4.5"
3102+
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.5.tgz#e293cd3c7c82f070d700fc7a1ca0a2e69f101f92"
3103+
30963104
js-stringify@^1.0.1:
30973105
version "1.0.2"
30983106
resolved "https://registry.yarnpkg.com/js-stringify/-/js-stringify-1.0.2.tgz#1736fddfd9724f28a3682adc6230ae7e4e9679db"
@@ -4537,6 +4545,16 @@ rollup-plugin-node-resolve@^3.3.0:
45374545
is-module "^1.0.0"
45384546
resolve "^1.1.6"
45394547

4548+
rollup-plugin-typescript@^0.8.1:
4549+
version "0.8.1"
4550+
resolved "https://registry.yarnpkg.com/rollup-plugin-typescript/-/rollup-plugin-typescript-0.8.1.tgz#2ff7eecc21cf6bb2b43fc27e5b688952ce71924a"
4551+
dependencies:
4552+
compare-versions "2.0.1"
4553+
object-assign "^4.0.1"
4554+
rollup-pluginutils "^1.3.1"
4555+
tippex "^2.1.1"
4556+
typescript "^1.8.9"
4557+
45404558
rollup-pluginutils@^1.3.1, rollup-pluginutils@^1.5.0, rollup-pluginutils@^1.5.1, rollup-pluginutils@^1.5.2:
45414559
version "1.5.2"
45424560
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408"
@@ -4992,6 +5010,10 @@ through@2, "through@>=2.2.7 <3":
49925010
version "2.3.8"
49935011
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
49945012

5013+
tippex@^2.1.1:
5014+
version "2.3.1"
5015+
resolved "https://registry.yarnpkg.com/tippex/-/tippex-2.3.1.tgz#a2fd5b7087d7cbfb20c9806a6c16108c2c0fafda"
5016+
49955017
49965018
version "1.0.4"
49975019
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1"
@@ -5104,6 +5126,10 @@ typedarray@^0.0.6:
51045126
version "0.0.6"
51055127
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
51065128

5129+
typescript@^1.8.9:
5130+
version "1.8.10"
5131+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-1.8.10.tgz#b475d6e0dff0bf50f296e5ca6ef9fbb5c7320f1e"
5132+
51075133
typescript@^2.8.3:
51085134
version "2.8.3"
51095135
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170"

0 commit comments

Comments
 (0)