From 85f0e0f7301f9d7eea5559a475972a9799d29167 Mon Sep 17 00:00:00 2001 From: Bart Ledoux Date: Tue, 8 Sep 2020 21:11:35 -0500 Subject: [PATCH 1/6] test: make simple test more precise --- examples/simple/rollup.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/simple/rollup.config.js b/examples/simple/rollup.config.js index ec3c031..f49ea15 100644 --- a/examples/simple/rollup.config.js +++ b/examples/simple/rollup.config.js @@ -2,9 +2,9 @@ import VuePlugin from 'rollup-plugin-vue' export default [ { - input: 'src/App.vue', + input: 'src/HelloWorld.vue', output: { - file: 'dist/app.js', + file: 'dist/HelloWorld.js', format: 'esm', sourcemap: 'inline', }, From 24bf6eaa26ee07fb8ae729931884ea09e7d68f7f Mon Sep 17 00:00:00 2001 From: Bart Ledoux Date: Tue, 8 Sep 2020 21:11:57 -0500 Subject: [PATCH 2/6] test: add the no-template example for test --- examples/no-template/package.json | 12 ++++++++++++ examples/no-template/rollup.config.js | 14 ++++++++++++++ examples/no-template/src/HelloWorld.vue | 10 ++++++++++ test/core.e2e.ts | 14 ++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 examples/no-template/package.json create mode 100644 examples/no-template/rollup.config.js create mode 100644 examples/no-template/src/HelloWorld.vue diff --git a/examples/no-template/package.json b/examples/no-template/package.json new file mode 100644 index 0000000..b3ac6c2 --- /dev/null +++ b/examples/no-template/package.json @@ -0,0 +1,12 @@ +{ + "name": "simple", + "version": "0.0.0", + "private": true, + "scripts": { + "build": "rollup -c" + }, + "dependencies": { + "rollup": "^2.10.9", + "rollup-plugin-vue": "link:../.." + } +} diff --git a/examples/no-template/rollup.config.js b/examples/no-template/rollup.config.js new file mode 100644 index 0000000..f49ea15 --- /dev/null +++ b/examples/no-template/rollup.config.js @@ -0,0 +1,14 @@ +import VuePlugin from 'rollup-plugin-vue' + +export default [ + { + input: 'src/HelloWorld.vue', + output: { + file: 'dist/HelloWorld.js', + format: 'esm', + sourcemap: 'inline', + }, + plugins: [VuePlugin()], + external: ['vue'], + }, +] diff --git a/examples/no-template/src/HelloWorld.vue b/examples/no-template/src/HelloWorld.vue new file mode 100644 index 0000000..a7c0416 --- /dev/null +++ b/examples/no-template/src/HelloWorld.vue @@ -0,0 +1,10 @@ + diff --git a/test/core.e2e.ts b/test/core.e2e.ts index bf76c26..01c85c9 100644 --- a/test/core.e2e.ts +++ b/test/core.e2e.ts @@ -12,6 +12,20 @@ describe('simple', () => { }) }) +describe('no-template', () => { + let result!: RollupOutput + + beforeAll(async () => { + result = await roll('no-template') + }) + + it('should leave the render function alone when no template is in the SFC', () => { + expect(result.output[0].code).not.toEqual( + expect.stringContaining('.render =') + ) + }) +}) + describe('custom-block', () => { let result!: RollupOutput From a35ce0ed43ac7d9187fe23ec696a51ed44ca5181 Mon Sep 17 00:00:00 2001 From: Bart Ledoux Date: Tue, 8 Sep 2020 21:12:34 -0500 Subject: [PATCH 3/6] fix: when an SFC has no template leave render --- src/index.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 81a02db..6d9eccb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -417,13 +417,17 @@ function transformVueSFC( const id = hash(isProduction ? shortFilePath + '\n' + code : shortFilePath) // feature information const hasScoped = descriptor.styles.some((s) => s.scoped) - const templateImport = getTemplateCode( - descriptor, - resourcePath, - id, - hasScoped, - isServer - ) + + const templateImport = descriptor.template + ? '' + : getTemplateCode(descriptor, resourcePath, id, hasScoped, isServer) + + const renderReplace = !descriptor.template + ? '' + : isServer + ? `script.ssrRender = ssrRender` + : `script.render = render` + const scriptImport = getScriptCode(descriptor, resourcePath) const stylesCode = getStyleCode( descriptor, @@ -441,7 +445,7 @@ function transformVueSFC( templateImport, stylesCode, customBlocksCode, - isServer ? `script.ssrRender = ssrRender` : `script.render = render`, + renderReplace, ] if (hasScoped) { output.push(`script.__scopeId = ${_(`data-v-${id}`)}`) From 6d304f554f6a43eea6958f410a9ed78abf538689 Mon Sep 17 00:00:00 2001 From: Bart Ledoux Date: Wed, 23 Sep 2020 14:11:40 -0500 Subject: [PATCH 4/6] test: fix import example --- examples/no-template/src/HelloWorld.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/no-template/src/HelloWorld.vue b/examples/no-template/src/HelloWorld.vue index a7c0416..4194206 100644 --- a/examples/no-template/src/HelloWorld.vue +++ b/examples/no-template/src/HelloWorld.vue @@ -1,5 +1,5 @@