Skip to content

Commit

Permalink
refactor(aio): fix a package bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Zhukov committed Apr 27, 2017
1 parent 30cb75c commit 7c04a04
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/tmp
/compiled
/build
/lib

# dependencies
node_modules
Expand Down
23 changes: 21 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var cleanCSS = require('gulp-clean-css');

var inlineResources = require('./scripts/inline-resources');

gulp.task('start', copySources);
gulp.task('copy-and-build', copySources);

function copySources() {
gulp.src('./src/framework/**/*')
Expand Down Expand Up @@ -40,4 +40,23 @@ function compileSass() {
.pipe(gulp.dest('./build'));
}

gulp.task('default', ['start']);
gulp.task('default', ['copy-and-build']);

gulp.task('inline-resource', copyResources);

function copyResources() {
gulp.src([
'./build/**/*.html',
'./build/**/*.css',
'./build/**/*.scss',
'./build/**/LICENSE.txt',
'./build/**/README.md',
'./build/**/package.json'
])
.pipe(gulp.dest('./lib'))
.on('end', inlineResource)
}

function inlineResource() {
inlineResources('./lib');
}
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,22 @@
"start": "ng serve",
"start:hmr": "ng serve --hmr",
"start:aot": "ng serve --aot",
"build": "npm run clean:dist && ng build",
"build": "rimraf dist && ng build",
"build:prod": "npm run build -- --prod",
"build:prod:aot": "npm run build -- --aot",
"build:ci": "npm run build:prod && npm run build:prod:aot",
"build:ghpages": "npm run build:prod:aot -- --base-href \"https://akveo.github.io/ng2-admin/\" && ngh",
"build:release": "rimraf build && gulp && ngc -p tsconfig.publish.json",
"build:release": "rimraf build lib compiled && gulp && tsc -p tsconfig.publish.json && ngc -p tsconfig.publish.json && gulp inline-resource && rollup -c ./tools/build/rollup.config.theme.js && rollup -c ./tools/build/rollup.config.auth.js",
"test": "ng test -sr",
"test:coverage": "npm run clean:coverage && ng test -sr -cc",
"test:coverage": "rimraf coverage && ng test -sr -cc",
"lint": "ng lint",
"lint:styles": "stylelint ./src/framework/**/*.scss",
"lint:ci": "npm run lint && npm run lint:styles",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "ng e2e",
"e2e:ci": "ng e2e --config ./protractor.conf.ci.js",
"doc": "compodoc ./src/framework -p ./tsconfig.json --theme readthedocs -d docs --disableGraph --disableCoverage --hideGenerator",
"doc:serve": "npm run doc -- -s -o",
"clean:dist": "npm run rimraf -- dist",
"clean:coverage": "npm run rimraf -- coverage",
"clean:doc": "npm run rimraf -- doc"
"doc:serve": "npm run doc -- -s -o"
},
"keywords": [
"angular",
Expand Down
22 changes: 22 additions & 0 deletions tools/build/rollup.config.auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
ROLLUP_GLOBALS,
getLicenseBanner,
} from './rollup.config.common';

const globals = Object.assign({}, ROLLUP_GLOBALS, {
'immutable': 'immutable',
});

const banner = getLicenseBanner('@nga/auth', '../../lib/auth/package.json');

export default {
context: 'this',
external: Object.keys(globals),
globals,
moduleName: 'nga.auth',
entry: 'lib/auth/index.js',
dest: 'lib/auth/bundles/auth.umd.js',
banner,
format: 'umd',
moduleId: '',
}
10 changes: 4 additions & 6 deletions tools/build/rollup.config.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ export const ROLLUP_GLOBALS = {
'@angular/common': 'ng.common',
'@angular/forms': 'ng.forms',
'@angular/http': 'ng.http',
'@angular/router': 'ng.router',
'@angular/platform-browser': 'ng.platformBrowser',
'@angular/platform-browser-dynamic': 'ng.platformBrowserDynamic',
'@angular/platform-browser/animations': 'ng.platformBrowser.animations',
'@angular/platform-server': 'ng.platformServer',

// Rxjs dependencies
'rxjs/Subject': 'Rx',
'rxjs/Observable': 'Rx',
'rxjs/ReplaySubject': 'Rx',
'rxjs/add/observable/fromEvent': 'Rx.Observable',
'rxjs/add/observable/forkJoin': 'Rx.Observable',
'rxjs/add/observable/of': 'Rx.Observable',
Expand All @@ -28,14 +31,9 @@ export const ROLLUP_GLOBALS = {
'rxjs/add/operator/first': 'Rx.Observable.prototype',
'rxjs/add/operator/startWith': 'Rx.Observable.prototype',
'rxjs/add/operator/switchMap': 'Rx.Observable.prototype',
'rxjs/Observable': 'Rx',
'rxjs/add/operator/publish': 'Rx.Observable.prototype',
};

export const BUILD_CONFIG = {
sourceMap: false,
format: 'umd',
}

export function getLicenseBanner(libName, pjsonPath) {
const libVersion = require(pjsonPath).version;

Expand Down
20 changes: 10 additions & 10 deletions tools/build/rollup.config.theme.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {
ROLLUP_GLOBALS,
BUILD_CONFIG,
getLicenseBanner,
} from './rollup.config.common';

const globals = Object.assign({}, ROLLUP_GLOBALS, {
'immutable': 'immutable',
});

const banner = getLicenseBanner('@nga/theme', '../../src/framework/theme/package.json');
const banner = getLicenseBanner('@nga/theme', '../../lib/theme/package.json');

export default {
...Object.assign({}, BUILD_CONFIG, {
external: Object.keys(globals),
globals,
moduleName: 'nga.theme',
entry: 'dist/theme/index.js',
dest: 'dist/theme/bundles/theme.umd.js',
banner,
}),
context: 'this',
external: Object.keys(globals),
globals,
moduleName: 'nga.theme',
entry: 'lib/theme/index.js',
dest: 'lib/theme/bundles/theme.umd.js',
banner,
format: 'umd',
moduleId: '',
}
11 changes: 6 additions & 5 deletions tsconfig.publish.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@
"module": "es2015",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
"outDir": "./dist",
"outDir": "./lib",
"rootDir": "./build",
"sourceMap": true,
"target": "es5",
"inlineSources": true,
"stripInternal": true,
"baseUrl": ".",
"paths": {
"@angular/core": ["node_modules/@angular/core"]
},
"skipLibCheck": true
},
"files": [
"./build/auth/index.ts"
"include": [
"./build/**/*"
],
"angularCompilerOptions": {
"strictMetadataEmit": true,
"genDir": "./compiled"
"genDir": "./compiled",
"debug": true
}
}

0 comments on commit 7c04a04

Please sign in to comment.