Skip to content

Commit 2d2c43f

Browse files
potential solution to double/single quotes
1 parent 9ab8d6d commit 2d2c43f

File tree

3 files changed

+41
-29
lines changed

3 files changed

+41
-29
lines changed

package-lock.json

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"babel-preset-es2015": "^6.24.1",
7070
"camel-case": "^3.0.0",
7171
"clean-css": "^4.1.7",
72-
"deepmerge": "^1.5.0",
72+
"deepmerge": "^1.5.1",
7373
"html-minifier": "^3.5.3",
7474
"lru-cache": "^4.1.1",
7575
"pug": "^2.0.0-rc.3",
@@ -88,7 +88,7 @@
8888
"babel-preset-flow": "^6.23.0",
8989
"codecov": "^2.3.0",
9090
"coveralls": "^2.13.1",
91-
"eslint": "^4.4.0",
91+
"eslint": "^4.4.1",
9292
"eslint-config-xo-space": "^0.16.0",
9393
"eslint-plugin-flowtype": "^2.35.0",
9494
"express": "^4.15.4",

src/utils/require.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Options {
1414
defaults: Models.Defaults;
1515
constructor(optsObj: Object) {
1616
this.vueFileRegex = /([\w/.\-@_\d]*\.vue)/igm;
17-
this.requireRegex = /(require\(')([\w/.\-@_\d]*\.vue)('\))/igm;
17+
this.requireRegex = /(require\(['"])([\w/.\-@_\d]*\.vue)(['"]\))/igm;
1818
this.appendPaths = optsObj.appendPaths || [];
1919
this.prependPaths = optsObj.prependPaths || [];
2020
this.rootPath = optsObj.rootPath || '';
@@ -46,18 +46,30 @@ function getVueObject(componentPath: string, rootPath: string, vueComponentFileM
4646
}
4747

4848
function replaceRelativePaths(code: string, rootPath: string): string {
49-
const parentMatches = code.match(/(require\('\.\.\/)/gm);
50-
const currentMatches = code.match(/(require\('\.\/)/gm);
51-
if (parentMatches) {
52-
for (const match of parentMatches) {
49+
const parentMatchesSingle = code.match(/(require\('\.\.\/)/gm);
50+
const currentMatchesSingle = code.match(/(require\('\.\/)/gm);
51+
const parentMatchesDouble = code.match(/(require\("\.\.\/)/gm);
52+
const currentMatchesDouble = code.match(/(require\("\.\/)/gm);
53+
if (parentMatchesSingle) {
54+
for (const match of parentMatchesSingle) {
5355
code = code.replace(match, `require('${rootPath}/../`);
5456
}
5557
}
56-
if (currentMatches) {
57-
for (const match of currentMatches) {
58+
if (parentMatchesDouble) {
59+
for (const match of parentMatchesDouble) {
60+
code = code.replace(match, `require("${rootPath}/../`);
61+
}
62+
}
63+
if (currentMatchesSingle) {
64+
for (const match of currentMatchesSingle) {
5865
code = code.replace(match, `require('${rootPath}/./`);
5966
}
6067
}
68+
if (currentMatchesDouble) {
69+
for (const match of currentMatchesDouble) {
70+
code = code.replace(match, `require("${rootPath}/./`);
71+
}
72+
}
6173

6274
return code;
6375
}

0 commit comments

Comments
 (0)