Skip to content

Commit

Permalink
feat(build): add es2015 build target support (#3202)
Browse files Browse the repository at this point in the history
* feat(build): add es2015 support

* refactor(build): use await instead of promises

* feat(build): clear tmp folder, fix es2015 field in package.json
  • Loading branch information
IlyaSurmay authored and valorkin committed Dec 6, 2017
1 parent 4131489 commit 735101c
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 1 deletion.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
"disable-lint": "tslint \"**/*.ts\" -c tslint.json --fix --type-check -t prose -e \"node_modules/**\" -e \"dist/**\" -e \"temp/**\" -e \"scripts/docs/**\"",
"flow.changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
"flow.github-release": "conventional-github-releaser -p angular",
"build": "run-s build.ngm build.sass",
"build": "run-s build.ngm build.sass build.es2015",
"build.sass": "node-sass --recursive src --output dist --source-map true --source-map-contents sass",
"build.ngm": "ngm build -p src --clean",
"build.watch": "ngm build -p src --watch --skip-bundles",
"build.es2015": "node ./scripts/es2015/bundle.es2015.js",
"start": "ng serve --aot --host 0.0.0.0",
"pretest": "run-s lint build link",
"test": "ng test -sr",
Expand Down Expand Up @@ -134,6 +135,9 @@
"protractor": "5.1.2",
"reflect-metadata": "0.1.10",
"require-dir": "0.3.2",
"rollup": "0.52.1",
"rollup-plugin-commonjs": "8.2.6",
"rollup-plugin-node-resolve": "3.0.0",
"rxjs": "5.4.3",
"ts-helpers": "^1.1.1",
"ts-loader": "3.0.5",
Expand Down
30 changes: 30 additions & 0 deletions scripts/es2015/bundle.es2015.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
const path = require('path');
const execa = require('execa');
const fs = require('fs-extra');
const del = require('del');
const inlineResources = require('ngm-cli/helpers/inline-resources');
const src = 'src';
const tmp = '.tmp';
const dist = 'dist-es2015';
const tsconfigPath = '.tmp/tsconfig.json';

async function createEs2015Bundle() {
await del(tmp);
console.log('Copying src to temp folder');
await fs.copy(src, tmp);
const tsconfig = require(path.resolve(tsconfigPath));
tsconfig.compilerOptions.target = 'es2015';
tsconfig.compilerOptions.outDir = '../' + dist;
await fs.writeFile(tsconfigPath, JSON.stringify(tsconfig), 'utf8');
console.log('Inlining templates and styles');
await inlineResources.inlineResources(tmp);
console.log('Compiling library from temp folder');
await execa('ngc', ['-p', tmp], { preferLocal: true });
console.log('Bundling es2015 bundle');
await execa('rollup --config ./scripts/es2015/es2015.config.js', { shell: true });
console.log('Removing temp folders');
await del([tmp, dist]);
}
createEs2015Bundle();

37 changes: 37 additions & 0 deletions scripts/es2015/es2015.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';
const fs = require('fs-extra');
const rollup = require('rollup');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const ROLLUP_GLOBALS = require('./rollup.globals');
const libName = 'ngx-bootstrap';
const PATH_SRC = 'dist-es2015/';
const PATH_DIST = 'dist/bundles/';

export default {
input: PATH_SRC + 'index.js',
output: {
format: 'es',
file: PATH_DIST + libName + '.es2015.js',
sourcemap: true,
name: libName
},
external: Object.keys(ROLLUP_GLOBALS),
plugins: [
resolve({
module: true,
main: true
}),
commonjs({
include: 'node_modules/**',
})
],
onwarn: warning => {
const skip_codes = [
'THIS_IS_UNDEFINED',
'MISSING_GLOBAL_NAME'
];
if (skip_codes.indexOf(warning.code) != -1) return;
console.error(warning);
}
};
Loading

1 comment on commit 735101c

@FrancescoBorzi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job, thanks a lot! waiting for the release to test it!

Please sign in to comment.