Skip to content

Commit

Permalink
fix(vuetransfomer): fix unknown asset language for vue scripts/templa… (
Browse files Browse the repository at this point in the history
#7056)

* fix(vuetransfomer): fix unknown asset language for vue scripts/templates/styles

* test: loading external files from vue sfcs

Co-authored-by: Jasper De Moor <jasperdemoor@gmail.com>
  • Loading branch information
RuyiLi and DeMoorJasper committed Oct 15, 2021
1 parent 674539e commit 85b76e8
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
@@ -0,0 +1,3 @@
<template src="./main.pug"></template>
<style src="./style.scss"></style>
<script src="./script.ts"></script>
@@ -0,0 +1,5 @@
div
h1 foo
h2 bar
div.box
p {{ msg }}
@@ -0,0 +1,7 @@
export default {
data () {
return {
msg: 'Hello World'
}
}
}
@@ -0,0 +1,24 @@
$cool-color: #c0ff33;

div {
h1 {
color: red;
}
}

h2 {
color: blue;

&:hover {
color: $cool-color;
}
}

.box {
border: 1px solid black;

p {
color: $cool-color;
font-size: 10rem;
}
}
15 changes: 15 additions & 0 deletions packages/core/integration-tests/test/vue.js
Expand Up @@ -105,4 +105,19 @@ describe('vue', function() {
assert.equal(typeof output.render, 'function');
assert.deepEqual(output.data(), {msg: 'Hello from Component A!'});
});
it('should load external templates/styles/scripts properly', async function() {
let b = await bundle(
path.join(__dirname, '/integration/vue-external-files/App.vue'),
);
let output = (await run(b)).default;
assert.equal(typeof output.render, 'function');
assert.deepEqual(output.data(), {msg: 'Hello World'});
let contents = await outputFS.readFile(
path.join(distDir, 'App.css'),
'utf8',
);
assert(contents.includes('color: #c0ff33'));
assert(contents.includes('h2:hover'));
assert(contents.includes('.box p'));
});
});
6 changes: 3 additions & 3 deletions packages/transformers/vue/src/VueTransformer.js
Expand Up @@ -207,7 +207,7 @@ async function processPipeline({
await resolve(asset.filePath, template.src),
)
).toString();
template.lang = extname(template.src);
template.lang = extname(template.src).slice(1);
}
let content = template.content;
if (template.lang && !['htm', 'html'].includes(template.lang)) {
Expand Down Expand Up @@ -267,7 +267,7 @@ ${
await resolve(asset.filePath, script.src),
)
).toString();
script.lang = extname(script.src);
script.lang = extname(script.src).slice(1);
}
let type;
switch (script.lang || 'js') {
Expand Down Expand Up @@ -323,7 +323,7 @@ ${
if (!style.module) {
style.module = MODULE_BY_NAME_RE.test(style.src);
}
style.lang = extname(style.src);
style.lang = extname(style.src).slice(1);
}
switch (style.lang) {
case 'less':
Expand Down

0 comments on commit 85b76e8

Please sign in to comment.