Skip to content

Commit 735101c

Browse files
IlyaSurmayvalorkin
authored andcommitted
feat(build): add es2015 build target support (#3202)
* feat(build): add es2015 support * refactor(build): use await instead of promises * feat(build): clear tmp folder, fix es2015 field in package.json
1 parent 4131489 commit 735101c

File tree

5 files changed

+470
-1
lines changed

5 files changed

+470
-1
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
"disable-lint": "tslint \"**/*.ts\" -c tslint.json --fix --type-check -t prose -e \"node_modules/**\" -e \"dist/**\" -e \"temp/**\" -e \"scripts/docs/**\"",
2323
"flow.changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
2424
"flow.github-release": "conventional-github-releaser -p angular",
25-
"build": "run-s build.ngm build.sass",
25+
"build": "run-s build.ngm build.sass build.es2015",
2626
"build.sass": "node-sass --recursive src --output dist --source-map true --source-map-contents sass",
2727
"build.ngm": "ngm build -p src --clean",
2828
"build.watch": "ngm build -p src --watch --skip-bundles",
29+
"build.es2015": "node ./scripts/es2015/bundle.es2015.js",
2930
"start": "ng serve --aot --host 0.0.0.0",
3031
"pretest": "run-s lint build link",
3132
"test": "ng test -sr",
@@ -134,6 +135,9 @@
134135
"protractor": "5.1.2",
135136
"reflect-metadata": "0.1.10",
136137
"require-dir": "0.3.2",
138+
"rollup": "0.52.1",
139+
"rollup-plugin-commonjs": "8.2.6",
140+
"rollup-plugin-node-resolve": "3.0.0",
137141
"rxjs": "5.4.3",
138142
"ts-helpers": "^1.1.1",
139143
"ts-loader": "3.0.5",

scripts/es2015/bundle.es2015.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
const path = require('path');
3+
const execa = require('execa');
4+
const fs = require('fs-extra');
5+
const del = require('del');
6+
const inlineResources = require('ngm-cli/helpers/inline-resources');
7+
const src = 'src';
8+
const tmp = '.tmp';
9+
const dist = 'dist-es2015';
10+
const tsconfigPath = '.tmp/tsconfig.json';
11+
12+
async function createEs2015Bundle() {
13+
await del(tmp);
14+
console.log('Copying src to temp folder');
15+
await fs.copy(src, tmp);
16+
const tsconfig = require(path.resolve(tsconfigPath));
17+
tsconfig.compilerOptions.target = 'es2015';
18+
tsconfig.compilerOptions.outDir = '../' + dist;
19+
await fs.writeFile(tsconfigPath, JSON.stringify(tsconfig), 'utf8');
20+
console.log('Inlining templates and styles');
21+
await inlineResources.inlineResources(tmp);
22+
console.log('Compiling library from temp folder');
23+
await execa('ngc', ['-p', tmp], { preferLocal: true });
24+
console.log('Bundling es2015 bundle');
25+
await execa('rollup --config ./scripts/es2015/es2015.config.js', { shell: true });
26+
console.log('Removing temp folders');
27+
await del([tmp, dist]);
28+
}
29+
createEs2015Bundle();
30+

scripts/es2015/es2015.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
const fs = require('fs-extra');
3+
const rollup = require('rollup');
4+
const resolve = require('rollup-plugin-node-resolve');
5+
const commonjs = require('rollup-plugin-commonjs');
6+
const ROLLUP_GLOBALS = require('./rollup.globals');
7+
const libName = 'ngx-bootstrap';
8+
const PATH_SRC = 'dist-es2015/';
9+
const PATH_DIST = 'dist/bundles/';
10+
11+
export default {
12+
input: PATH_SRC + 'index.js',
13+
output: {
14+
format: 'es',
15+
file: PATH_DIST + libName + '.es2015.js',
16+
sourcemap: true,
17+
name: libName
18+
},
19+
external: Object.keys(ROLLUP_GLOBALS),
20+
plugins: [
21+
resolve({
22+
module: true,
23+
main: true
24+
}),
25+
commonjs({
26+
include: 'node_modules/**',
27+
})
28+
],
29+
onwarn: warning => {
30+
const skip_codes = [
31+
'THIS_IS_UNDEFINED',
32+
'MISSING_GLOBAL_NAME'
33+
];
34+
if (skip_codes.indexOf(warning.code) != -1) return;
35+
console.error(warning);
36+
}
37+
};

0 commit comments

Comments
 (0)