Skip to content

Commit

Permalink
feat(packaging): generate sourcemaps (#666)
Browse files Browse the repository at this point in the history
Closes #662
BREAKING CHANGE: umd file name simplified from 'ng-zorro-antd.js' to 'antd.js'
  • Loading branch information
trotyl authored and vthinkxie committed Dec 6, 2017
1 parent a731817 commit 8665639
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 56 deletions.
50 changes: 32 additions & 18 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,42 @@ rm -rf publish
cp -r src/components src/__gen_components
node ./less.convert.js

echo 'Generating entry file using Angular compiler'
$(npm bin)/ngc -p tsconfig-build.json
rm -rf src/__gen_components
echo 'Compiling to es2015 via Angular compiler'
$(npm bin)/ngc -p tsconfig-build.json -t es2015 --outDir publish-es2015/src

echo 'Bundling to es module'
export ROLLUP_FORMAT=es
$(npm bin)/rollup -c rollup.config.js
rm -rf publish/src/*.js
rm -rf publish/src/**/*.js
sed -e "s/from '.\//from '.\/src\//g" publish/src/index.d.ts > publish/index.d.ts
sed -e "s/\":\".\//\":\".\/src\//g" publish/src/index.metadata.json > publish/index.metadata.json
rm publish/src/index.d.ts publish/src/index.metadata.json
echo 'Bundling to es module of es2015'
export ROLLUP_TARGET=esm
$(npm bin)/rollup -c rollup.config.js -f es -i publish-es2015/src/index.js -o publish-es2015/esm2015/antd.js

echo 'Compiling to es5 via Angular compiler'
$(npm bin)/ngc -p tsconfig-build.json -t es5 --outDir publish-es5/src

echo 'Bundling to es module of es5'
export ROLLUP_TARGET=esm
$(npm bin)/rollup -c rollup.config.js -f es -i publish-es5/src/index.js -o publish-es5/esm5/antd.js

echo 'Transpiling es module to es5'
$(npm bin)/tsc --allowJs --importHelpers --target es5 --module es2015 --outDir publish/esm5 publish/esm15/index.js
echo 'Bundling to umd module of es5'
export ROLLUP_TARGET=umd
$(npm bin)/rollup -c rollup.config.js -f umd -i publish-es5/esm5/antd.js -o publish-es5/bundles/antd.umd.js

echo 'Bundling to umd module'
export ROLLUP_FORMAT=umd
$(npm bin)/rollup -c rollup.config.js
echo 'Bundling to minified umd module of es5'
export ROLLUP_TARGET=mumd
$(npm bin)/rollup -c rollup.config.js -f umd -i publish-es5/esm5/antd.js -o publish-es5/bundles/antd.umd.min.js

echo 'Minifying umd module'
$(npm bin)/uglifyjs publish/bundles/ng-zorro-antd.umd.js --output publish/bundles/ng-zorro-antd.umd.min.js
echo 'Unifying publish folder'
mv publish-es5 publish
mv publish-es2015/esm2015 publish/esm2015
rm -rf publish-es2015

echo 'Cleaning up temporary files'
rm -rf src/__gen_components
rm -rf publish/src/*.js
rm -rf publish/src/**/*.js

echo 'Normalizing entry files'
sed -e "s/from '.\//from '.\/src\//g" publish/src/index.d.ts > publish/antd.d.ts
sed -e "s/\":\".\//\":\".\/src\//g" publish/src/index.metadata.json > publish/antd.metadata.json
rm publish/src/index.d.ts publish/src/index.metadata.json

echo 'Copying package.json'
cp package.json publish/package.json
Empty file modified integration-test.sh
100644 → 100755
Empty file.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"lint": "ng lint",
"e2e": "ng e2e"
},
"main": "./bundles/ng-zorro-antd.umd.js",
"module": "./esm5/index.js",
"es2015": "./esm15/index.js",
"main": "./bundles/antd.umd.js",
"module": "./esm5/antd.js",
"es2015": "./esm2015/antd.js",
"typings": "./antd.d.ts",
"keywords": [
"ant",
"design",
Expand Down Expand Up @@ -76,14 +77,14 @@
"marked": "^0.3.6",
"protractor": "~5.1.2",
"rollup": "^0.49.2",
"rollup-plugin-commonjs": "^8.2.1",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-uglify": "^2.0.1",
"rxjs": "^5.5.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2",
"uglify-js": "^3.0.28",
"web-animations-js": "^2.3.1",
"zone.js": "^0.8.17"
},
Expand Down
50 changes: 18 additions & 32 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
// import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';
import sourcemaps from 'rollup-plugin-sourcemaps';

const format = process.env.ROLLUP_FORMAT || 'es';
const target = process.env.ROLLUP_TARGET || 'esm';

let globals = {
'@angular/animations': 'ng.animations',
Expand Down Expand Up @@ -113,43 +114,28 @@ let globals = {
'rxjs/operators/tap': 'Rx.Observable.prototype',
};

if (format === 'es') {
globals = Object.assign(globals, {
'tslib': 'tslib',
});
}

let input;
let file;

switch (format) {
case 'es':
input = './publish/src/index.js';
file = './publish/esm15/index.js';
let plugins = [
sourcemaps(),
replace({ "import * as moment": "import moment" }),
resolve(),
];

switch (target) {
case 'esm':
Object.assign(globals, {
'tslib': 'tslib',
});
break;
case 'umd':
input = './publish/esm5/index.js';
file = './publish/bundles/ng-zorro-antd.umd.js';
case 'mumd':
plugins.push(uglify());
break;
default:
throw new Error(`format ${format} is not supported`);
}

export default {
input,
output: {
file,
format,
},
exports: 'named',
name: 'ngZorro.antd',
plugins: [
replace({ "import * as moment": "import moment" }),
resolve(),
// commonjs({
// include: 'node_modules/rxjs/operator/*'
// }), // Resolve: Error: 'xxx' is not exported by xxx, see: https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
],
plugins,
external: Object.keys(globals),
globals,
sourceMap: true,
}
2 changes: 1 addition & 1 deletion tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"declaration": true,
"importHelpers": true,
"module": "es2015",
"sourceMap": false,
"sourceMap": true,
"target": "es2015",
"types": [
"node"
Expand Down

0 comments on commit 8665639

Please sign in to comment.