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

make <script> tag support src attribute; also fixed eslint warnings. #123

Merged
merged 1 commit into from
Aug 22, 2017
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
2 changes: 2 additions & 0 deletions src/style/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const addScopeID = postcss.plugin('add-scope-id', options => {
const selectorTransformer = selectorParser(selectors => {
selectors.each(selector => {
let target = null
/* eslint-disable complexity */
selector.each(n => {
if (n.type === 'combinator' && n.value === '>>>') {
n.value = ' '
Expand All @@ -51,6 +52,7 @@ const addScopeID = postcss.plugin('add-scope-id', options => {
target = n
}
})
/* eslint-enable complexity */

target && selector.insertAfter(target, selectorParser.attribute({
attribute: options.scopeID
Expand Down
2 changes: 2 additions & 0 deletions src/style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function ensureDirectory (directory) {
}
}

/* eslint-disable complexity */
export default function (files, options) {
if (typeof (options.css) === 'boolean') {
return
Expand Down Expand Up @@ -74,3 +75,4 @@ export default function (files, options) {
if (err) throw err
})
}
/* eslint-enable complexity */
4 changes: 4 additions & 0 deletions src/vueTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ async function processScript (source, id, content, options, nodes, modules, scop
debug(`Process script: ${id}`)
const lang = normalizeLang(source.attrs.lang)

if (source.attrs.src) {
source.code = `import __vue_module__ from '${source.attrs.src}'; export default __vue_module__;`
}

if (source.attrs.lang && ['js', 'babel'].indexOf(source.attrs.lang) < 0) {
if (!(source.attrs.lang in options.script)) {
throw new Error(`[rollup-plugin-vue] ${source.attrs.lang} is not yet supported in .vue files.`)
Expand Down
3 changes: 3 additions & 0 deletions test/expects/external-script.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: #000;
}
14 changes: 14 additions & 0 deletions test/expects/external-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const data = {
name: 'test'
};

var __vue_module__ = {
data() {
return data
}
};

var __$__vue_module__ = Object.assign(__vue_module__, { template: "<div class=\"test\"></div>",});
__$__vue_module__.prototype = __vue_module__.prototype;

export default __$__vue_module__;
9 changes: 9 additions & 0 deletions test/fixtures/external-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const data = {
name: 'test'
}

export default {
data() {
return data
}
}
11 changes: 11 additions & 0 deletions test/fixtures/external-script.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<style>
body {
color: #000;
}
</style>

<template>
<div class="test"></div>
</template>

<script src="./external-script.js"></script>
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function test(name) {
'pug',
'less',
'style',
'stylus'
'stylus',
'external-script'
].indexOf(name) > -1) {
var css = read('expects/' + name + '.css')
assert.equal(css.trim(), actualCss.trim(), 'should output style tag content')
Expand Down