Skip to content

Commit d5b9746

Browse files
committed
feat($compile): better bundle logic
Bundling loging upgraded to use Webpack; bugfix: CommonModule replaced with BrowserModule closes #1
1 parent 292faaa commit d5b9746

30 files changed

+769
-678
lines changed

.gitignore

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
# OS generated files
2+
Thumbs.db
13
.DS_Store
24

3-
# npm and yarn
5+
# Node generated files
46
node_modules
57
*.log
68

7-
# build
9+
# Code coverage
10+
coverage
11+
12+
# Ignored files
13+
bundles
814
lib
15+
src/*.d.ts
16+
src/*.js
17+
index.d.ts
18+
index.js
19+
*.map
20+
21+
# @angular/compiler-cli
22+
*.metadata.*
23+
*.ngsummary.*
24+
*.ngfactory.*
25+
*.ngstyle.*

.npmignore

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
# common
2-
node_modules
3-
demo
4-
*.log
1+
# OS generated files
2+
Thumbs.db
53
.DS_Store
6-
.tmp
74

8-
# Webpack
9-
webpack.config.js
5+
# Node generated files
6+
node_modules
7+
*.log
8+
*.yml
109

11-
# source/config
10+
# Ignored files
1211
src
13-
*.yml
12+
config
13+
coverage
14+
demo
15+
.nyc_output
16+
.test
17+
.tmp
1418
.gitignore
19+
*.ts
20+
!*.d.ts

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ node_js:
1111
before_script:
1212
- npm prune
1313

14-
script:
15-
- npm run build_prod
16-
1714
after_success:
15+
- npm run build_prod
1816
- npm run semantic-release
1917

2018
branches:

README.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
99
angular2-expandable-list is an HTML `<angular2-expandable-list>` tag enhanced with styling and animation
1010

11+
Plunker DEMO available [here](https://embed.plnkr.co/uAPJq0/)
12+
1113
![screenshot](http://i.imgur.com/Qa402ev.gif)
1214

1315
## Table of contents
@@ -43,13 +45,7 @@ If you are using System.js you may want to add this into `map` and `package` con
4345
```json
4446
{
4547
"map": {
46-
"angular2-expandable-list": "node_modules/angular2-expandable-list"
47-
},
48-
"packages": {
49-
"angular2-expandable-list": {
50-
"main": "index.js",
51-
"defaultExtension": "js"
52-
}
48+
"angular2-expandable-list": "node_modules/angular2-expandable-list/bundles/angular2-expandable-list.umd.js"
5349
}
5450
}
5551
```
@@ -208,23 +204,15 @@ your `<expandable-list>`.
208204
## Demo App
209205

210206
Have a look at the [demo](https://github.com/andreasonny83/angular2-expandable-list/tree/master/demo)
211-
available in this repository for a real Angular2 application using the `Angular2-expandable-list` library.
207+
available in this repository for a real Angular2 application using the Angular2-Cookie-Law library.
212208

213209
From your terminal all the Node dependencies using npm:
214210

215-
```bash
216-
$ npm install
217-
# Or Yarn
218-
$ yarn install
219-
```
220-
221-
Then initialize the application with:
222-
223211
```bash
224212
$ npm run demo
225213
```
226214

227-
Open your browser to [http://localhost:8080/](http://localhost:8080/)
215+
Open your browser to [http://localhost:9007/](http://localhost:9007/)
228216
to see the application running.
229217

230218
## Contributing

config/helpers.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* angular2-expandable-list
3+
*
4+
* Copyright 2017, @andreasonny83, All rights reserved.
5+
*
6+
* @author: @andreasonny83 <andreasonny83@gmail.com>
7+
*/
8+
9+
var path = require('path');
10+
11+
// Helper functions
12+
var ROOT = path.resolve(__dirname, '..');
13+
14+
function hasProcessFlag(flag) {
15+
return process.argv.join('').indexOf(flag) > -1;
16+
}
17+
18+
function isWebpackDevServer() {
19+
return process.argv[1] && !! (/webpack-dev-server/.exec(process.argv[1]));
20+
}
21+
22+
function root(args) {
23+
args = Array.prototype.slice.call(arguments, 0);
24+
return path.join.apply(path, [ROOT].concat(args));
25+
}
26+
27+
exports.hasProcessFlag = hasProcessFlag;
28+
exports.isWebpackDevServer = isWebpackDevServer;
29+
exports.root = root;
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1+
/**
2+
* angular2-expandable-list
3+
*
4+
* Copyright 2017, @andreasonny83, All rights reserved.
5+
*
6+
* @author: @andreasonny83 <andreasonny83@gmail.com>
7+
*/
8+
19
const path = require('path');
10+
const helpers = require('./helpers');
211
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
3-
const TsConfigPathsPlugin = require('awesome-typescript-loader').TsConfigPathsPlugin;
412

513
const ROOT = path.resolve(__dirname);
614

7-
function root(args) {
8-
args = Array.prototype.slice.call(arguments, 0);
9-
return path.join.apply(path, [ROOT].concat(args));
10-
}
11-
1215
module.exports = {
1316
devtool: 'cheap-module-source-map',
1417

1518
entry: {
16-
'main': './demo/app.ts'
19+
'main': helpers.root('demo/app.ts')
1720
},
1821

1922
output: {
20-
path: root('demo'),
23+
path: helpers.root('demo'),
2124
filename: 'bundle.js',
2225
sourceMapFilename: '[name].map'
2326
},
2427

2528
resolve: {
2629
extensions: ['.ts', '.js'],
2730
modules: [
28-
root('demo'),
29-
root('src'),
30-
root('node_modules'),
31+
helpers.root('node_modules'),
3132
],
3233
},
3334

@@ -40,7 +41,7 @@ module.exports = {
4041
loader: 'awesome-typescript-loader',
4142
options: {
4243
configFileName: 'demo/tsconfig.json'
43-
},
44+
}
4445
},
4546
{
4647
loader: 'angular2-template-loader'
@@ -50,7 +51,7 @@ module.exports = {
5051
},
5152

5253
{
53-
test: /\.css|html?$/,
54+
test: /\.(css|html)?$/,
5455
use: [
5556
{
5657
loader: 'raw-loader'
@@ -61,11 +62,9 @@ module.exports = {
6162
},
6263

6364
plugins: [
64-
new TsConfigPathsPlugin(),
65-
6665
new ContextReplacementPlugin(
6766
/angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
68-
root('demo')
67+
helpers.root('demo')
6968
),
7069
]
7170
}

config/webpack.lib.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* angular2-expandable-list
3+
*
4+
* Copyright 2017, @andreasonny83, All rights reserved.
5+
*
6+
* @author: @andreasonny83 <andreasonny83@gmail.com>
7+
*/
8+
9+
const helpers = require('./helpers');
10+
const webpack = require('webpack');
11+
12+
/**
13+
* Webpack Plugins
14+
*/
15+
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
16+
const DefinePlugin = require('webpack/lib/DefinePlugin');
17+
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
18+
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
19+
20+
function ngExternal(ns) {
21+
const ng2Ns = `@angular/${ns}`;
22+
return { root: ['ng', ns], commonjs: ng2Ns, commonjs2: ng2Ns, amd: ng2Ns };
23+
}
24+
25+
module.exports = {
26+
devtool: 'source-map',
27+
28+
resolve: {
29+
extensions: ['.ts', '.js']
30+
},
31+
32+
entry: helpers.root('./index.ts'),
33+
34+
output: {
35+
path: helpers.root('bundles'),
36+
publicPath: '/',
37+
filename: 'angular2-expandable-list.umd.js',
38+
libraryTarget: 'umd',
39+
library: 'angular2-expandable-list'
40+
},
41+
42+
// require those dependencies but don't bundle them
43+
externals: {
44+
'@angular/core': ngExternal('core'),
45+
'@angular/common': ngExternal('common'),
46+
'@angular/platform-browser': ngExternal('platform-browser'),
47+
},
48+
49+
module: {
50+
rules: [
51+
52+
{
53+
test: /\.ts$/,
54+
use: [
55+
{
56+
loader: 'awesome-typescript-loader',
57+
options: {
58+
declaration: false
59+
}
60+
},
61+
{
62+
loader: 'angular2-template-loader'
63+
}
64+
],
65+
exclude: [/\.e2e\.ts$/]
66+
},
67+
68+
{
69+
test: /\.(css|html)?$/,
70+
use: [
71+
{
72+
loader: 'raw-loader'
73+
},
74+
]
75+
},
76+
77+
]
78+
},
79+
80+
plugins: [
81+
// fix the warning in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
82+
new ContextReplacementPlugin(
83+
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
84+
helpers.root('src')
85+
),
86+
87+
new LoaderOptionsPlugin({
88+
options: {
89+
tslintLoader: {
90+
emitErrors: false,
91+
failOnHint: false
92+
}
93+
}
94+
})
95+
]
96+
};

demo/app.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import { Component } from '@angular/core';
6161
export class AppComponent {
6262
items: any;
6363

64-
6564
constructor() {
6665
this.items = [
6766
{

demo/tsconfig.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
{
22
"compilerOptions": {
3+
"baseUrl": ".",
34
"target": "es5",
45
"module": "commonjs",
56
"moduleResolution": "node",
67
"sourceMap": true,
78
"emitDecoratorMetadata": true,
89
"experimentalDecorators": true,
9-
"lib": [ "es2015", "dom" ],
10+
"lib": [
11+
"es2015",
12+
"dom"
13+
],
14+
"types": [
15+
"jasmine",
16+
"node",
17+
"selenium-webdriver",
18+
"source-map",
19+
"webpack"
20+
],
1021
"noImplicitAny": true,
1122
"suppressImplicitAnyIndexErrors": true
1223
},

index.js

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)