Skip to content

Commit 95bd94a

Browse files
committed
compatible with win
1 parent 61d9a64 commit 95bd94a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"start": "jest test --watch",
77
"test": "jest test",
88
"test:webpack": "cd test && webpack",
9-
"test:webpack:ts": "cd test && TEST_EXT=ts webpack",
9+
"test:webpack:ts": "cd test && cross-env TEST_EXT=ts webpack",
1010
"prebuild": "rimraf ./lib && mkdirp ./lib",
1111
"build:watch": "babel src -o lib/index.js -w",
1212
"build": "babel src -o lib/index.js",
@@ -40,6 +40,7 @@
4040
"babel-plugin-transform-es2015-spread": "^6.22.0",
4141
"babel-preset-es2015": "^6.24.0",
4242
"babel-preset-stage-0": "^6.22.0",
43+
"cross-env": "^5.2.0",
4344
"eslint": "^4.2.0",
4445
"eslint-config-standard": "^10.2.1",
4546
"eslint-loader": "^1.9.0",

src/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,13 @@ export default class WXAppPlugin {
366366
const flatSubEntryResources = [].concat(...subEntryResources.map(v => v));
367367
const scripts = entryResources.concat(flatSubEntryResources).map(::this.getFullScriptPath);
368368

369+
const isWin = scripts.findIndex(v => v.indexOf('\\') >= 0) !== -1;
369370
const lastSubDirs = new Set();
370371
subEntryResources.forEach((pages, index) => {
371372
if (pages.length) {
372-
const subDir = pages[0].slice(0, pages[0].lastIndexOf('/') + 1);
373+
const subDir = isWin
374+
? pages[0].slice(0, pages[0].lastIndexOf('\\') + 1)
375+
: pages[0].slice(0, pages[0].lastIndexOf('/') + 1);
373376

374377
compiler.apply(
375378
new CommonsChunkPlugin({
@@ -431,7 +434,12 @@ export default class WXAppPlugin {
431434
const globalVar = target.name === 'Alipay' ? 'my' : 'wx';
432435
const subEntryResources = [].concat(...this.subEntryResources.map(v => v))
433436
const scripts = [].concat(this.entryResources).concat(subEntryResources);
434-
const subDirs = this.subEntryResources.filter(v => v.length).map(v => v[0].slice(0, v[0].lastIndexOf('/') + 1));
437+
const isWin = scripts.findIndex(v => v.indexOf('\\') >= 0) !== -1;
438+
const subDirs = this.subEntryResources
439+
.filter(v => v.length)
440+
.map(v => isWin
441+
? v[0].slice(0, v[0].lastIndexOf('\\') + 1)
442+
: v[0].slice(0, v[0].lastIndexOf('/') + 1));
435443

436444
// inject chunk entries
437445
compilation.chunkTemplate.plugin('render', (core, { name }) => {

0 commit comments

Comments
 (0)