Skip to content

Commit 9388051

Browse files
author
Guillaume Chau
authored
Merge pull request #214 from nathantreid/npm-vue-components
Enable loading of .vue files from npm packages
2 parents 99f76ee + 8730baa commit 9388051

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packages/vue-component/plugin/vue-compiler.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,22 @@ VueComponentCompiler = class VueCompo extends CachingCompiler {
153153

154154
const { js, templateHash } = generateJs(vueId, inputFile, compileResult)
155155

156+
let outputFilePath = inputFile.getPathInPackage();
157+
// Meteor will error when loading .vue files on the server unless they are postfixed with .js
158+
if (inputFile.getArch().indexOf('os') === 0 && inputFilePath.indexOf('node_modules') !== -1) {
159+
outputFilePath += '.js';
160+
}
161+
162+
// Including the source maps for .vue files from node_modules breaks source mapping.
163+
const sourceMap = inputFilePath.indexOf('node_modules') === -1
164+
? compileResult.map
165+
: undefined;
166+
156167
// Add JS Source file
157168
inputFile.addJavaScript({
158-
path: inputFile.getPathInPackage(),
169+
path: outputFilePath,
159170
data: js,
160-
sourceMap: compileResult.map,
171+
sourceMap: sourceMap,
161172
lazy: false,
162173
});
163174

@@ -610,7 +621,7 @@ function generateJs (vueId, inputFile, compileResult, isHotReload = false) {
610621
js += `__vue_options__.packageName = '${inputFile.getPackageName()}';`;
611622

612623
// Export
613-
js += `module.export('default', exports.default = __vue_script__);`;
624+
js += `module.export('default', exports.default = __vue_script__);exports.__esModule = true;`;
614625

615626
if (!isHotReload) {
616627
// Hot-reloading

0 commit comments

Comments
 (0)