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

Commit 0027e9f

Browse files
sunnylostznck
authored andcommitted
make <script> tag support src attribute; also fixed eslint warnings. (#123)
1 parent 34f2260 commit 0027e9f

File tree

8 files changed

+47
-1
lines changed

8 files changed

+47
-1
lines changed

src/style/css.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const addScopeID = postcss.plugin('add-scope-id', options => {
2525
const selectorTransformer = selectorParser(selectors => {
2626
selectors.each(selector => {
2727
let target = null
28+
/* eslint-disable complexity */
2829
selector.each(n => {
2930
if (n.type === 'combinator' && n.value === '>>>') {
3031
n.value = ' '
@@ -51,6 +52,7 @@ const addScopeID = postcss.plugin('add-scope-id', options => {
5152
target = n
5253
}
5354
})
55+
/* eslint-enable complexity */
5456

5557
target && selector.insertAfter(target, selectorParser.attribute({
5658
attribute: options.scopeID

src/style/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function ensureDirectory (directory) {
3232
}
3333
}
3434

35+
/* eslint-disable complexity */
3536
export default function (files, options) {
3637
if (typeof (options.css) === 'boolean') {
3738
return
@@ -74,3 +75,4 @@ export default function (files, options) {
7475
if (err) throw err
7576
})
7677
}
78+
/* eslint-enable complexity */

src/vueTransform.js

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ async function processScript (source, id, content, options, nodes, modules, scop
8989
debug(`Process script: ${id}`)
9090
const lang = normalizeLang(source.attrs.lang)
9191

92+
if (source.attrs.src) {
93+
source.code = `import __vue_module__ from '${source.attrs.src}'; export default __vue_module__;`
94+
}
95+
9296
if (source.attrs.lang && ['js', 'babel'].indexOf(source.attrs.lang) < 0) {
9397
if (!(source.attrs.lang in options.script)) {
9498
throw new Error(`[rollup-plugin-vue] ${source.attrs.lang} is not yet supported in .vue files.`)

test/expects/external-script.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
color: #000;
3+
}

test/expects/external-script.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const data = {
2+
name: 'test'
3+
};
4+
5+
var __vue_module__ = {
6+
data() {
7+
return data
8+
}
9+
};
10+
11+
var __$__vue_module__ = Object.assign(__vue_module__, { template: "<div class=\"test\"></div>",});
12+
__$__vue_module__.prototype = __vue_module__.prototype;
13+
14+
export default __$__vue_module__;

test/fixtures/external-script.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const data = {
2+
name: 'test'
3+
}
4+
5+
export default {
6+
data() {
7+
return data
8+
}
9+
}

test/fixtures/external-script.vue

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<style>
2+
body {
3+
color: #000;
4+
}
5+
</style>
6+
7+
<template>
8+
<div class="test"></div>
9+
</template>
10+
11+
<script src="./external-script.js"></script>

test/test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function test(name) {
6363
'pug',
6464
'less',
6565
'style',
66-
'stylus'
66+
'stylus',
67+
'external-script'
6768
].indexOf(name) > -1) {
6869
var css = read('expects/' + name + '.css')
6970
assert.equal(css.trim(), actualCss.trim(), 'should output style tag content')

0 commit comments

Comments
 (0)