Skip to content

Commit 086ac69

Browse files
committed
fix: resolve path in windows
1 parent 2f23313 commit 086ac69

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

template/build/webpack.base.conf.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ function resolve (dir) {
1010
return path.join(__dirname, '..', dir)
1111
}
1212

13-
function getEntry (dir, entryFile) {
14-
var files = glob.sync(dir + '/pages/**/main.js');
15-
var map = {};
16-
files.forEach(file => {
17-
var key = file.replace(dir + '/', '').replace(/\.js$/, '');
18-
map[key] = file;
19-
})
20-
return map;
13+
function getEntry (rootSrc, pattern) {
14+
var files = glob.sync(path.resolve(rootSrc, pattern))
15+
return files.reduce((res, file) => {
16+
var info = path.parse(file)
17+
var key = info.dir.slice(rootSrc.length + 1) + '/' + info.name
18+
res[key] = path.resolve(file)
19+
return res
20+
}, {})
2121
}
2222

2323
const appEntry = { app: resolve('./src/main.js') }
24-
const pagesEntry = getEntry(resolve('./src'), 'main.js')
24+
const pagesEntry = getEntry(resolve('./src'), 'pages/**/main.js')
2525
const entry = Object.assign({}, appEntry, pagesEntry)
2626

2727
module.exports = {
28-
entry: entry, // 如果要自定义生成的 dist 目录里面的文件路径,
29-
// 可以将 entry 写成 {'toPath': 'fromPath'} 的形式,
30-
// toPath 为相对于 dist 的路径, 例:index/demo,则生成的文件地址为 dist/index/demo.js
28+
// 如果要自定义生成的 dist 目录里面的文件路径,
29+
// 可以将 entry 写成 {'toPath': 'fromPath'} 的形式,
30+
// toPath 为相对于 dist 的路径, 例:index/demo,则生成的文件地址为 dist/index/demo.js
31+
entry,
3132
target: require('mpvue-webpack-target'),
3233
output: {
3334
path: config.build.assetsRoot,

0 commit comments

Comments
 (0)