Skip to content
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

feat(build): add es2015 support #3202

Merged
merged 3 commits into from
Dec 6, 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
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 @@ -133,6 +134,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