Skip to content

Commit

Permalink
Merge pull request express-vue#58 from express-vue/feature/better_che…
Browse files Browse the repository at this point in the history
…ck_in_require

require checks
  • Loading branch information
danielcherubini committed Aug 4, 2017
2 parents 0790367 + 9ae21b7 commit 8480f3b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-vue-renderer",
"version": "0.5.6",
"version": "0.5.7",
"description": "Rendering Engine for turning Vue files into Javascript Objects",
"homepage": "https://github.com/express-vue/express-vue-renderer",
"author": {
Expand Down Expand Up @@ -43,7 +43,8 @@
"src/models/index.js",
"src/parser/index.js",
"src/renderer/index.js",
"src/utils/index.js"
"src/utils/index.js",
"**/*.vue"
]
},
"scripts": {
Expand Down
30 changes: 16 additions & 14 deletions src/utils/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,22 @@ function requireFromString(code: string, filename: string = '', optsObj: Object
for (const vueComponentFileMatch of vueComponentFileMatches) {
//get the file out of the require string
//this is because its easier to do string replace later
const vueComponentFile = vueComponentFileMatch.match(options.vueFileRegex)[0];
getVueObject(vueComponentFile, options.rootPath, vueComponentFileMatch)
.then(renderedItem => {
const rawString = renderedItem.rendered.scriptStringRaw;
newCode = newCode.replace(renderedItem.match, rawString);
//check if its the last element and then render
if (vueComponentFileMatch === last_element) {
m._compile(newCode, filename);
resolve(m.exports.default);
}
})
.catch(error => {
reject(error);
});
const vueComponentFile = vueComponentFileMatch.match(options.vueFileRegex);
if (vueComponentFile && vueComponentFile.length > 0) {
getVueObject(vueComponentFile[0], options.rootPath, vueComponentFileMatch)
.then(renderedItem => {
const rawString = renderedItem.rendered.scriptStringRaw;
newCode = newCode.replace(renderedItem.match, rawString);
//check if its the last element and then render
if (vueComponentFileMatch === last_element) {
m._compile(newCode, filename);
resolve(m.exports.default);
}
})
.catch(error => {
reject(error);
});
}
}
} else {
reject(new Error('Couldnt require component from string: ' + error));
Expand Down

0 comments on commit 8480f3b

Please sign in to comment.