Skip to content

Commit 9b1ca44

Browse files
committed
feat(umd): 增加echarts-ng2.umd.js
1 parent 1e2f9d5 commit 9b1ca44

File tree

8 files changed

+303
-8
lines changed

8 files changed

+303
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/node_modules
2+
/bundles

config/helpers.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* taken from angular2-webpack-starter
3+
*/
4+
var path = require('path');
5+
6+
// Helper functions
7+
var ROOT = path.resolve(__dirname, '..');
8+
9+
function hasProcessFlag(flag) {
10+
return process.argv.join('').indexOf(flag) > -1;
11+
}
12+
13+
function isWebpackDevServer() {
14+
return process.argv[1] && !! (/webpack-dev-server$/.exec(process.argv[1]));
15+
}
16+
17+
function root(args) {
18+
args = Array.prototype.slice.call(arguments, 0);
19+
return path.join.apply(path, [ROOT].concat(args));
20+
}
21+
22+
function checkNodeImport(context, request, cb) {
23+
if (!path.isAbsolute(request) && request.charAt(0) !== '.') {
24+
cb(null, 'commonjs ' + request); return;
25+
}
26+
cb();
27+
}
28+
29+
exports.hasProcessFlag = hasProcessFlag;
30+
exports.isWebpackDevServer = isWebpackDevServer;
31+
exports.root = root;
32+
exports.checkNodeImport = checkNodeImport;

package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
"name": "echarts-ng2",
33
"version": "1.4.1",
44
"description": "Angular2 ECharts component",
5-
"main": "src/index.js",
5+
"main": "bundles/echarts-ng2.umd.js",
6+
"module": "src/index.js",
67
"typings": "src/index.d.ts",
78
"scripts": {
89
"ngc": "ngc",
10+
"webpack": "webpack",
11+
"clean": "rimraf bundles",
12+
"webpack:uglify": "webpack --config webpack.config.uglify.js",
913
"changelog:init": "conventional-changelog -i CHANGELOG.md -s -p angular -r 0",
1014
"changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
11-
"prepublish": "ngc"
15+
"bundles": "npm run clean && npm run webpack && npm run webpack:uglify",
16+
"build": "npm run bundles && npm run ngc",
17+
"prepublish": "npm run build"
1218
},
1319
"repository": {
1420
"type": "git",
@@ -34,9 +40,15 @@
3440
"@angular/compiler": "^2.4.0",
3541
"@angular/compiler-cli": "^2.4.0",
3642
"@angular/core": "^2.4.0",
43+
"awesome-typescript-loader": "^3.1.3",
44+
"codelyzer": "^3.0.1",
3745
"conventional-changelog-cli": "^1.3.1",
46+
"rimraf": "^2.6.1",
3847
"rxjs": "^5.2.0",
48+
"tslint": "^5.4.2",
49+
"tslint-loader": "^3.5.3",
3950
"typescript": "^2.1.5",
51+
"webpack": "^2.6.1",
4052
"zone.js": "^0.7.6"
4153
}
42-
}
54+
}

src/component/echarts-ng2.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class EchartsNg2Component implements AfterViewInit, OnDestroy, ECharts {
1717
this.chart && (typeof this._group !== 'undefined') && ((<any>this.chart).group = this._group);
1818
}
1919

20-
@Input() theme: Object | string = "default";
20+
@Input() theme: Object | string = 'default';
2121
@Input()
2222
set option(option: EChartOption) {
2323
this._option = option;
@@ -39,7 +39,7 @@ export class EchartsNg2Component implements AfterViewInit, OnDestroy, ECharts {
3939
@Output() onAfterInit: EventEmitter<any> = new EventEmitter();
4040
@Output() onOptionChange: EventEmitter<any> = new EventEmitter();
4141

42-
@ViewChild('host') host;
42+
@ViewChild('host') host: ElementRef;
4343

4444
constructor(
4545
private el: ElementRef,
@@ -59,7 +59,7 @@ export class EchartsNg2Component implements AfterViewInit, OnDestroy, ECharts {
5959
if (!this.chart) {
6060
this.ngZone.runOutsideAngular(() => {
6161
this.onBeforeInit.emit();
62-
this.chart = echarts.init(this.host.nativeElement, this.theme, this.style ? {} : this.opts);
62+
this.chart = <any>(echarts.init(this.host.nativeElement, this.theme, this.style ? {} : this.opts));
6363
this.onAfterInit.emit();
6464
this.option && this.chart.setOption(this.option);
6565
this.setGroup();
@@ -193,6 +193,6 @@ export class EchartsNg2Component implements AfterViewInit, OnDestroy, ECharts {
193193
}
194194

195195
disconnect = (group: string): void => {
196-
echarts.disconnect(group);
196+
(<any>echarts).disconnect(group);
197197
}
198198
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './component/api';
22
export * from './component/echarts-ng2.component';
3-
export * from './component/echarts-ng2.module';
3+
export * from './component/echarts-ng2.module';

tslint.json

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"rulesDirectory": [
3+
"node_modules/codelyzer"
4+
],
5+
"rules": {
6+
"callable-types": true,
7+
"class-name": true,
8+
"comment-format": [
9+
true,
10+
"check-space"
11+
],
12+
"curly": true,
13+
"eofline": true,
14+
"forin": true,
15+
"import-blacklist": [true, "rxjs"],
16+
"import-spacing": true,
17+
"indent": [
18+
true,
19+
"spaces"
20+
],
21+
"interface-over-type-literal": true,
22+
"label-position": true,
23+
"max-line-length": [
24+
true,
25+
140
26+
],
27+
"member-access": false,
28+
"member-ordering": [
29+
true,
30+
"static-before-instance",
31+
"variables-before-functions"
32+
],
33+
"no-arg": true,
34+
"no-bitwise": true,
35+
"no-console": [
36+
true,
37+
"debug",
38+
"info",
39+
"time",
40+
"timeEnd",
41+
"trace"
42+
],
43+
"no-construct": true,
44+
"no-debugger": true,
45+
"no-duplicate-variable": true,
46+
"no-empty": false,
47+
"no-empty-interface": true,
48+
"no-eval": true,
49+
"no-inferrable-types": [true, "ignore-params"],
50+
"no-shadowed-variable": true,
51+
"no-string-literal": false,
52+
"no-string-throw": true,
53+
"no-switch-case-fall-through": true,
54+
"no-trailing-whitespace": true,
55+
"no-unused-expression": true,
56+
"no-use-before-declare": true,
57+
"no-var-keyword": true,
58+
"object-literal-sort-keys": false,
59+
"one-line": [
60+
true,
61+
"check-open-brace",
62+
"check-catch",
63+
"check-else",
64+
"check-whitespace"
65+
],
66+
"prefer-const": true,
67+
"quotemark": [
68+
true,
69+
"single"
70+
],
71+
"radix": true,
72+
"semicolon": [
73+
"always"
74+
],
75+
"triple-equals": [
76+
true,
77+
"allow-null-check"
78+
],
79+
"typedef-whitespace": [
80+
true,
81+
{
82+
"call-signature": "nospace",
83+
"index-signature": "nospace",
84+
"parameter": "nospace",
85+
"property-declaration": "nospace",
86+
"variable-declaration": "nospace"
87+
}
88+
],
89+
"typeof-compare": true,
90+
"unified-signatures": true,
91+
"variable-name": false,
92+
"whitespace": [
93+
true,
94+
"check-branch",
95+
"check-decl",
96+
"check-operator",
97+
"check-separator",
98+
"check-type"
99+
],
100+
101+
"directive-selector": [true, "attribute", "app", "camelCase"],
102+
"component-selector": [true, "element", "app", "kebab-case"],
103+
"use-input-property-decorator": true,
104+
"use-output-property-decorator": true,
105+
"use-host-property-decorator": true,
106+
"no-input-rename": true,
107+
"no-output-rename": true,
108+
"use-life-cycle-interface": true,
109+
"use-pipe-transform-interface": true,
110+
"component-class-suffix": true,
111+
"directive-class-suffix": true,
112+
"no-access-missing-member": true,
113+
"templates-use-public": true,
114+
"invoke-injectable": true
115+
}
116+
}

webpack.config.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Adapted from angular2-webpack-starter
3+
*/
4+
5+
const helpers = require('./config/helpers'),
6+
webpack = require('webpack');
7+
8+
/**
9+
* Webpack Plugins
10+
*/
11+
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
12+
const DefinePlugin = require('webpack/lib/DefinePlugin');
13+
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
14+
15+
module.exports = {
16+
devtool: 'inline-source-map',
17+
18+
resolve: {
19+
extensions: ['.ts', '.js']
20+
},
21+
22+
entry: helpers.root('src/index.ts'),
23+
24+
output: {
25+
path: helpers.root('bundles'),
26+
publicPath: '/',
27+
filename: 'echarts-ng2.umd.js',
28+
libraryTarget: 'umd',
29+
library: 'echarts-ng2'
30+
},
31+
32+
// require those dependencies but don't bundle them
33+
externals: [/^\@angular\//, /^rxjs\//],
34+
35+
module: {
36+
rules: [{
37+
enforce: 'pre',
38+
test: /\.ts$/,
39+
loader: 'tslint-loader',
40+
exclude: [helpers.root('node_modules')]
41+
}, {
42+
test: /\.ts$/,
43+
loader: 'awesome-typescript-loader?declaration=false',
44+
exclude: [/\.e2e\.ts$/]
45+
}]
46+
},
47+
48+
plugins: [
49+
// fix the warning in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
50+
new webpack.ContextReplacementPlugin(
51+
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
52+
helpers.root('./src')
53+
),
54+
55+
new webpack.LoaderOptionsPlugin({
56+
options: {
57+
tslintLoader: {
58+
emitErrors: false,
59+
failOnHint: false
60+
}
61+
}
62+
})
63+
]
64+
};

webpack.config.uglify.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Adapted from angular2-webpack-starter
3+
*/
4+
5+
const helpers = require('./config/helpers'),
6+
webpack = require('webpack');
7+
8+
/**
9+
* Webpack Plugins
10+
*/
11+
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
12+
const DefinePlugin = require('webpack/lib/DefinePlugin');
13+
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
14+
15+
module.exports = {
16+
devtool: 'inline-source-map',
17+
18+
resolve: {
19+
extensions: ['.ts', '.js']
20+
},
21+
22+
entry: helpers.root('src/index.ts'),
23+
24+
output: {
25+
path: helpers.root('bundles'),
26+
publicPath: '/',
27+
filename: 'echarts-ng2.umd.min.js',
28+
libraryTarget: 'umd',
29+
library: 'echarts-ng2'
30+
},
31+
32+
// require those dependencies but don't bundle them
33+
externals: [/^\@angular\//, /^rxjs\//],
34+
35+
module: {
36+
rules: [{
37+
enforce: 'pre',
38+
test: /\.ts$/,
39+
loader: 'tslint-loader',
40+
exclude: [helpers.root('node_modules')]
41+
}, {
42+
test: /\.ts$/,
43+
loader: 'awesome-typescript-loader?declaration=false',
44+
exclude: [/\.e2e\.ts$/]
45+
}]
46+
},
47+
48+
plugins: [
49+
// fix the warning in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
50+
new webpack.ContextReplacementPlugin(
51+
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
52+
helpers.root('./src')
53+
),
54+
55+
new webpack.LoaderOptionsPlugin({
56+
options: {
57+
tslintLoader: {
58+
emitErrors: false,
59+
failOnHint: false
60+
}
61+
}
62+
}),
63+
64+
new webpack.optimize.UglifyJsPlugin({
65+
compress: {
66+
warnings: false
67+
}
68+
})
69+
]
70+
};

0 commit comments

Comments
 (0)