Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit a1ccc17

Browse files
committed
feat(sourcemaps): copy for prod and dev
1 parent ee3e41b commit a1ccc17

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/util/source-maps.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import * as Constants from './constants';
44
import { copyFileAsync, getBooleanPropertyValue, readDirAsync, unlinkAsync } from './helpers';
55
import { BuildContext } from './interfaces';
66

7-
export function purgeSourceMapsIfNeeded(context: BuildContext): Promise<any> {
8-
if (getBooleanPropertyValue(Constants.ENV_VAR_GENERATE_SOURCE_MAP)) {
9-
// keep the source maps and just return
10-
return Promise.resolve([]);
11-
}
7+
function copySourcemaps(context: BuildContext, shouldPurge: boolean) {
128
return readDirAsync(context.buildDir).then((fileNames) => {
139
const sourceMaps = fileNames.filter(fileName => fileName.endsWith('.map'));
1410
const fullPaths = sourceMaps.map(sourceMap => join(context.buildDir, sourceMap));
@@ -18,14 +14,25 @@ export function purgeSourceMapsIfNeeded(context: BuildContext): Promise<any> {
1814
if (copyBeforePurge) {
1915
mkdirpSync(context.sourcemapDir)
2016
const relativeTo = relative(fullPath, context.sourcemapDir)
21-
const fileName = basename(fullPath)
22-
promises.push(copyFileAsync(fullPath, join(context.sourcemapDir, fileName)).then(() => {
23-
return unlinkAsync(fullPath)
24-
}))
25-
} else {
17+
const fileName = basename(fullPath);
18+
if (fileName.indexOf('vendor.js') < 0) {
19+
promises.push(copyFileAsync(fullPath, join(context.sourcemapDir, fileName)));
20+
}
21+
}
22+
23+
if (shouldPurge) {
2624
promises.push(unlinkAsync(fullPath))
2725
}
2826
}
2927
return Promise.all(promises);
3028
});
3129
}
30+
31+
export function purgeSourceMapsIfNeeded(context: BuildContext): Promise<any> {
32+
if (getBooleanPropertyValue(Constants.ENV_VAR_GENERATE_SOURCE_MAP)) {
33+
// keep the source maps and just return
34+
return copySourcemaps(context, false);
35+
}
36+
37+
return copySourcemaps(context, true);
38+
}

0 commit comments

Comments
 (0)