|
| 1 | +import path from 'path' |
1 | 2 | import postcss from 'postcss'; |
2 | 3 | import autoprefixer from 'autoprefixer'; |
3 | 4 | import postcssModules from 'postcss-modules'; |
@@ -57,6 +58,40 @@ VueComponentTagHandler = class VueComponentTagHandler { |
57 | 58 | message: 'Expected <template>, <script>, or <style> tag in template file', |
58 | 59 | }); |
59 | 60 | } |
| 61 | + |
| 62 | + if (tag.attribs.src) { |
| 63 | + if (tag.contents.trim()) { |
| 64 | + throwCompileError({ |
| 65 | + inputFile: this.inputFile, |
| 66 | + message: `Should not have any contents if using the 'src' attribute.`, |
| 67 | + tag: tag.tagName, |
| 68 | + charIndex: tag.tagStartIndex, |
| 69 | + }) |
| 70 | + } else { |
| 71 | + const filePath = path.resolve(path.dirname(getFilePath(this.inputFile)), tag.attribs.src) |
| 72 | + try { |
| 73 | + tag.origin = Object.assign({}, tag) |
| 74 | + tag.basePath = filePath |
| 75 | + tag.contents = tag.fileContents = getFileContents(filePath) |
| 76 | + tag.sourceName = filePath |
| 77 | + tag.tagStartIndex = 0 |
| 78 | + this.dependencyManager.addDependency(filePath) |
| 79 | + } catch (e) { |
| 80 | + if (e.message === 'file-not-found') { |
| 81 | + throwCompileError({ |
| 82 | + inputFile: this.inputFile, |
| 83 | + message: `File ${filePath} not found.`, |
| 84 | + tag: tag.tagName, |
| 85 | + charIndex: tag.tagStartIndex, |
| 86 | + }) |
| 87 | + } else { |
| 88 | + throw e |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + } else { |
| 93 | + tag.basePath = path.resolve(getFilePath(this.inputFile)) |
| 94 | + } |
60 | 95 | } |
61 | 96 |
|
62 | 97 | getResults() { |
@@ -101,7 +136,9 @@ VueComponentTagHandler = class VueComponentTagHandler { |
101 | 136 | //console.log(`Compiling <script> in lang ${lang}...`); |
102 | 137 | let result = compile({ |
103 | 138 | source: script, |
104 | | - inputFile: this.inputFile |
| 139 | + inputFile: this.inputFile, |
| 140 | + basePath: tag.basePath, |
| 141 | + dependencyManager: this.dependencyManager, |
105 | 142 | }); |
106 | 143 | script = result.script; |
107 | 144 | if (result.map) { |
@@ -130,7 +167,7 @@ VueComponentTagHandler = class VueComponentTagHandler { |
130 | 167 | // Babel options |
131 | 168 | this.babelOptions.sourceMap = true; |
132 | 169 | this.babelOptions.filename = |
133 | | - this.babelOptions.sourceFileName = fullInputFilePath; |
| 170 | + this.babelOptions.sourceFileName = tag.basePath; |
134 | 171 | this.babelOptions.sourceMapTarget = this.babelOptions.filename + '.map'; |
135 | 172 |
|
136 | 173 | // Babel compilation |
@@ -215,7 +252,9 @@ VueComponentTagHandler = class VueComponentTagHandler { |
215 | 252 | //console.log(`Compiling <template> in lang ${lang}...`); |
216 | 253 | let result = compile({ |
217 | 254 | source: template, |
218 | | - inputFile: this.inputFile |
| 255 | + inputFile: this.inputFile, |
| 256 | + basePath: templateTag.basePath, |
| 257 | + dependencyManager: this.dependencyManager, |
219 | 258 | }); |
220 | 259 | template = result.template; |
221 | 260 | } |
@@ -272,7 +311,8 @@ VueComponentTagHandler = class VueComponentTagHandler { |
272 | 311 | let result = compile({ |
273 | 312 | source: css, |
274 | 313 | inputFile: this.inputFile, |
275 | | - dependencyManager: this.dependencyManager |
| 314 | + basePath: styleTag.basePath, |
| 315 | + dependencyManager: this.dependencyManager, |
276 | 316 | }); |
277 | 317 | //console.log('Css result', result); |
278 | 318 | css = result.css; |
|
0 commit comments