Skip to content

Commit

Permalink
feat(umd): 增加echarts-ng2.umd.js
Browse files Browse the repository at this point in the history
  • Loading branch information
twp0217 committed Jun 4, 2017
1 parent 1e2f9d5 commit 9b1ca44
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules
/bundles
32 changes: 32 additions & 0 deletions config/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* taken from angular2-webpack-starter
*/
var path = require('path');

// Helper functions
var ROOT = path.resolve(__dirname, '..');

function hasProcessFlag(flag) {
return process.argv.join('').indexOf(flag) > -1;
}

function isWebpackDevServer() {
return process.argv[1] && !! (/webpack-dev-server$/.exec(process.argv[1]));
}

function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [ROOT].concat(args));
}

function checkNodeImport(context, request, cb) {
if (!path.isAbsolute(request) && request.charAt(0) !== '.') {
cb(null, 'commonjs ' + request); return;
}
cb();
}

exports.hasProcessFlag = hasProcessFlag;
exports.isWebpackDevServer = isWebpackDevServer;
exports.root = root;
exports.checkNodeImport = checkNodeImport;
18 changes: 15 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
"name": "echarts-ng2",
"version": "1.4.1",
"description": "Angular2 ECharts component",
"main": "src/index.js",
"main": "bundles/echarts-ng2.umd.js",
"module": "src/index.js",
"typings": "src/index.d.ts",
"scripts": {
"ngc": "ngc",
"webpack": "webpack",
"clean": "rimraf bundles",
"webpack:uglify": "webpack --config webpack.config.uglify.js",
"changelog:init": "conventional-changelog -i CHANGELOG.md -s -p angular -r 0",
"changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
"prepublish": "ngc"
"bundles": "npm run clean && npm run webpack && npm run webpack:uglify",
"build": "npm run bundles && npm run ngc",
"prepublish": "npm run build"
},
"repository": {
"type": "git",
Expand All @@ -34,9 +40,15 @@
"@angular/compiler": "^2.4.0",
"@angular/compiler-cli": "^2.4.0",
"@angular/core": "^2.4.0",
"awesome-typescript-loader": "^3.1.3",
"codelyzer": "^3.0.1",
"conventional-changelog-cli": "^1.3.1",
"rimraf": "^2.6.1",
"rxjs": "^5.2.0",
"tslint": "^5.4.2",
"tslint-loader": "^3.5.3",
"typescript": "^2.1.5",
"webpack": "^2.6.1",
"zone.js": "^0.7.6"
}
}
}
8 changes: 4 additions & 4 deletions src/component/echarts-ng2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class EchartsNg2Component implements AfterViewInit, OnDestroy, ECharts {
this.chart && (typeof this._group !== 'undefined') && ((<any>this.chart).group = this._group);
}

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

@ViewChild('host') host;
@ViewChild('host') host: ElementRef;

constructor(
private el: ElementRef,
Expand All @@ -59,7 +59,7 @@ export class EchartsNg2Component implements AfterViewInit, OnDestroy, ECharts {
if (!this.chart) {
this.ngZone.runOutsideAngular(() => {
this.onBeforeInit.emit();
this.chart = echarts.init(this.host.nativeElement, this.theme, this.style ? {} : this.opts);
this.chart = <any>(echarts.init(this.host.nativeElement, this.theme, this.style ? {} : this.opts));
this.onAfterInit.emit();
this.option && this.chart.setOption(this.option);
this.setGroup();
Expand Down Expand Up @@ -193,6 +193,6 @@ export class EchartsNg2Component implements AfterViewInit, OnDestroy, ECharts {
}

disconnect = (group: string): void => {
echarts.disconnect(group);
(<any>echarts).disconnect(group);
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './component/api';
export * from './component/echarts-ng2.component';
export * from './component/echarts-ng2.module';
export * from './component/echarts-ng2.module';
116 changes: 116 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"rules": {
"callable-types": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
"eofline": true,
"forin": true,
"import-blacklist": [true, "rxjs"],
"import-spacing": true,
"indent": [
true,
"spaces"
],
"interface-over-type-literal": true,
"label-position": true,
"max-line-length": [
true,
140
],
"member-access": false,
"member-ordering": [
true,
"static-before-instance",
"variables-before-functions"
],
"no-arg": true,
"no-bitwise": true,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": false,
"no-empty-interface": true,
"no-eval": true,
"no-inferrable-types": [true, "ignore-params"],
"no-shadowed-variable": true,
"no-string-literal": false,
"no-string-throw": true,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"prefer-const": true,
"quotemark": [
true,
"single"
],
"radix": true,
"semicolon": [
"always"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"typeof-compare": true,
"unified-signatures": true,
"variable-name": false,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],

"directive-selector": [true, "attribute", "app", "camelCase"],
"component-selector": [true, "element", "app", "kebab-case"],
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-input-rename": true,
"no-output-rename": true,
"use-life-cycle-interface": true,
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true,
"no-access-missing-member": true,
"templates-use-public": true,
"invoke-injectable": true
}
}
64 changes: 64 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Adapted from angular2-webpack-starter
*/

const helpers = require('./config/helpers'),
webpack = require('webpack');

/**
* Webpack Plugins
*/
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');

module.exports = {
devtool: 'inline-source-map',

resolve: {
extensions: ['.ts', '.js']
},

entry: helpers.root('src/index.ts'),

output: {
path: helpers.root('bundles'),
publicPath: '/',
filename: 'echarts-ng2.umd.js',
libraryTarget: 'umd',
library: 'echarts-ng2'
},

// require those dependencies but don't bundle them
externals: [/^\@angular\//, /^rxjs\//],

module: {
rules: [{
enforce: 'pre',
test: /\.ts$/,
loader: 'tslint-loader',
exclude: [helpers.root('node_modules')]
}, {
test: /\.ts$/,
loader: 'awesome-typescript-loader?declaration=false',
exclude: [/\.e2e\.ts$/]
}]
},

plugins: [
// fix the warning in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('./src')
),

new webpack.LoaderOptionsPlugin({
options: {
tslintLoader: {
emitErrors: false,
failOnHint: false
}
}
})
]
};
70 changes: 70 additions & 0 deletions webpack.config.uglify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Adapted from angular2-webpack-starter
*/

const helpers = require('./config/helpers'),
webpack = require('webpack');

/**
* Webpack Plugins
*/
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');

module.exports = {
devtool: 'inline-source-map',

resolve: {
extensions: ['.ts', '.js']
},

entry: helpers.root('src/index.ts'),

output: {
path: helpers.root('bundles'),
publicPath: '/',
filename: 'echarts-ng2.umd.min.js',
libraryTarget: 'umd',
library: 'echarts-ng2'
},

// require those dependencies but don't bundle them
externals: [/^\@angular\//, /^rxjs\//],

module: {
rules: [{
enforce: 'pre',
test: /\.ts$/,
loader: 'tslint-loader',
exclude: [helpers.root('node_modules')]
}, {
test: /\.ts$/,
loader: 'awesome-typescript-loader?declaration=false',
exclude: [/\.e2e\.ts$/]
}]
},

plugins: [
// fix the warning in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
helpers.root('./src')
),

new webpack.LoaderOptionsPlugin({
options: {
tslintLoader: {
emitErrors: false,
failOnHint: false
}
}
}),

new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
};

0 comments on commit 9b1ca44

Please sign in to comment.