Skip to content

build: fix sourcemap paths #9068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions tools/package-tools/build-bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {buildConfig} from './build-config';
import {BuildPackage} from './build-package';
import {rollupRemoveLicensesPlugin} from './rollup-remove-licenses';
import {rollupGlobals, dashCaseToCamelCase} from './rollup-globals';
import {remapSourcemap} from './sourcemap-remap';

// There are no type definitions available for these imports.
const rollup = require('rollup');
Expand Down Expand Up @@ -66,7 +67,6 @@ export class PackageBundler {
*/
private async bundleEntryPoint(config: BundlesConfig) {
// Build FESM-2015 bundle file.
// TODO: re-add sorcery when we upgrade to Angular 5.x
await this.createRollupBundle({
moduleName: config.moduleName,
entry: config.entryFile,
Expand All @@ -75,7 +75,6 @@ export class PackageBundler {
});

// Build FESM-5 bundle file.
// TODO: re-add sorcery when we upgrade to Angular 5.x
await this.createRollupBundle({
moduleName: config.moduleName,
entry: config.esm5EntryFile,
Expand All @@ -84,7 +83,6 @@ export class PackageBundler {
});

// Create UMD bundle of ES5 output.
// TODO: re-add sorcery when we upgrade to Angular 5.x
await this.createRollupBundle({
moduleName: config.moduleName,
entry: config.esm5Dest,
Expand All @@ -93,8 +91,15 @@ export class PackageBundler {
});

// Create a minified UMD bundle using UglifyJS
// TODO: re-add sorcery when we upgrade to Angular 5.x
uglifyJsFile(config.umdDest, config.umdMinDest);

// Remaps the sourcemaps to be based on top of the original TypeScript source files.
await Promise.all([
remapSourcemap(config.esm2015Dest),
remapSourcemap(config.esm5Dest),
remapSourcemap(config.umdDest),
remapSourcemap(config.umdMinDest),
]);
}

/** Creates a rollup bundle of a specified JavaScript file.*/
Expand Down
9 changes: 6 additions & 3 deletions tools/package-tools/minify-sources.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import {writeFileSync} from 'fs';
import {basename} from 'path';

// There are no type definitions available for these imports.
const uglify = require('uglify-js');

/** Minifies a JavaScript file by using UglifyJS2. Also writes sourcemaps to the output. */
export function uglifyJsFile(inputPath: string, outputPath: string) {
const sourcemapOut = `${outputPath}.map`;
const sourceMapPath = `${outputPath}.map`;

const result = uglify.minify(inputPath, {
outSourceMap: sourcemapOut,
inSourceMap: `${inputPath}.map`,
outSourceMap: basename(sourceMapPath),
output: {
comments: 'some'
}
});

writeFileSync(outputPath, result.code);
writeFileSync(sourcemapOut, result.map);
writeFileSync(sourceMapPath, result.map);
}