Skip to content

Commit 1c1e081

Browse files
committed
allow regex in webpackConfig in vue.config.js, fixes #7
1 parent cc606da commit 1c1e081

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,22 @@ function setWebpackOptions (api, options) {
113113
...alias,
114114
...api.resolveWebpackConfig().resolve.alias
115115
}
116+
function replacer (key, value) {
117+
if (value instanceof RegExp) return '__REGEXP ' + value.toString()
118+
else return value
119+
}
120+
function toRegex (match, p1, regex) {
121+
return regex.replace('\\\\', '\\')
122+
}
123+
let stringConfig = JSON.stringify(config, replacer).replace(
124+
/("__REGEXP)(.+?)(")(?=,)/,
125+
toRegex
126+
)
116127
if (!fs.existsSync(api.resolve('.') + '/dist_electron')) {
117128
fs.mkdirSync(api.resolve('.') + '/dist_electron')
118129
}
119130
fs.writeFileSync(
120131
api.resolve('.') + '/dist_electron/webpack.renderer.additions.js',
121-
'module.exports=' + JSON.stringify(config)
132+
'module.exports=' + stringConfig
122133
)
123134
}

0 commit comments

Comments
 (0)