From 3208453c8cc42e7d43d87bb0b6c74984bfb1a76e Mon Sep 17 00:00:00 2001 From: xiguaxigua Date: Thu, 14 Jun 2018 14:29:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=8C=85=E4=BD=93?= =?UTF-8?q?=E7=A7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/config.js | 42 +++++++++ build/rollup.config.js | 86 +++++++------------ build/webpack.config.js | 3 +- docs/en/README.md | 5 ++ docs/en/skill-demo.md | 2 +- docs/en/start.md | 36 ++++---- docs/index.html | 18 ++-- docs/install.md | 4 + docs/skill-demo.md | 2 +- docs/start.md | 36 ++++---- examples/router.js | 8 +- package-lock.json | 12 ++- package.json | 7 +- src/component-list.js | 3 +- src/{echarts-base.js => constants.js} | 44 +++++----- src/core.js | 17 ++-- src/packages/amap/index.js | 14 ++- src/packages/bar/index.js | 15 ++-- src/packages/bar/main.js | 2 +- src/packages/bmap/index.js | 14 ++- src/packages/candle/index.js | 15 ++-- src/packages/candle/main.js | 2 +- src/packages/chart/index.js | 14 ++- src/packages/funnel/index.js | 14 ++- src/packages/funnel/main.js | 2 +- src/packages/gauge/index.js | 15 ++-- src/packages/heatmap/index.js | 14 ++- src/packages/heatmap/main.js | 3 +- src/packages/histogram/index.js | 14 ++- src/packages/line/index.js | 14 ++- src/packages/line/main.js | 2 +- src/packages/map/index.js | 14 ++- src/packages/map/main.js | 3 +- src/packages/pie/index.js | 14 ++- src/packages/pie/main.js | 2 +- src/packages/radar/index.js | 14 ++- src/packages/radar/main.js | 2 +- src/packages/ring/index.js | 14 ++- src/packages/sankey/index.js | 14 ++- src/packages/sankey/main.js | 2 +- src/packages/scatter/index.js | 14 ++- src/packages/scatter/main.js | 2 +- src/packages/tree/index.js | 14 ++- src/packages/waterfall/index.js | 14 ++- test/load/webpack/candle/App.vue | 2 +- test/load/webpack/{guage => gauge}/App.vue | 0 test/load/webpack/{guage => gauge}/index.js | 0 .../{guage => gauge}/webpack.config.js | 0 48 files changed, 282 insertions(+), 322 deletions(-) create mode 100644 build/config.js rename src/{echarts-base.js => constants.js} (60%) rename test/load/webpack/{guage => gauge}/App.vue (100%) rename test/load/webpack/{guage => gauge}/index.js (100%) rename test/load/webpack/{guage => gauge}/webpack.config.js (100%) diff --git a/build/config.js b/build/config.js new file mode 100644 index 0000000..f19b7eb --- /dev/null +++ b/build/config.js @@ -0,0 +1,42 @@ +module.exports = { + pkgTypeList: [ + { type: 'cjs', min: false, suffix: '.common.js' }, + { type: 'cjs', min: true, suffix: '.common.min.js' }, + { type: 'umd', min: false, suffix: '.js' }, + { type: 'umd', min: true, suffix: '.min.js' } + ], + addons: [ + { + min: false, + type: 'es', + suffix: '.esm.js', + globalName: '', + src: 'src/index.es.js', + dist: 'lib/index' + }, + { + min: false, + type: 'cjs', + suffix: '.js', + globalName: '', + src: 'src/core.js', + dist: 'lib/core' + }, + { + min: false, + type: 'cjs', + suffix: '.js', + globalName: '', + src: 'src/utils.js', + dist: 'lib/utils' + }, + { + min: false, + type: 'cjs', + suffix: '.js', + globalName: '', + src: 'src/constants.js', + dist: 'lib/constants' + } + ] +} diff --git a/build/rollup.config.js b/build/rollup.config.js index b432483..b5401a8 100644 --- a/build/rollup.config.js +++ b/build/rollup.config.js @@ -8,79 +8,53 @@ const componentInfo = require('../src/component-list') const uglify = require('rollup-plugin-uglify').uglify const autoprefixer = require('autoprefixer') const cssnano = require('cssnano') +const path = require('path') +const fs = require('fs') +const { pkgTypeList, addons } = require('./config') let pkg = [] -const pkgTypeList = [ - { type: 'cjs', min: false, suffix: '.common.js' }, - { type: 'cjs', min: true, suffix: '.common.min.js' }, - { type: 'umd', min: false, suffix: '.js' }, - { type: 'umd', min: true, suffix: '.min.js' } -] pkgTypeList.forEach(({ type, min, suffix }) => { Object.keys(componentInfo).forEach(name => { const { src, dist } = componentInfo[name] - pkg.push({ - min, - type, - suffix, - globalName: name, - src, - dist - }) + pkg.push({ min, type, suffix, globalName: name, src, dist }) }) }) -const addons = [ - { - min: false, - type: 'es', - suffix: '.esm.js', - globalName: '', - src: 'src/index.es.js', - dist: 'lib/index' - } -] pkg = pkg.concat(addons) pkg.forEach(item => { rollupFn(item) }) -function rollupFn (item) { - const vueSettings = item.min +fs.mkdirSync(path.resolve(__dirname, '../lib')) + +async function rollupFn (item) { + const { min, dist, suffix, src: input, type: format, globalName: name } = item + const vueSettings = min ? { css: 'lib/style.min.css', postcss: [autoprefixer, cssnano] } : { css: 'lib/style.css', postcss: [autoprefixer] } - const plugins = [ - eslint({ - throwError: true, - exclude: 'node_modules/**' - }), + eslint(), vue(vueSettings), - resolve({ - extensions: ['.js', '.vue'] - }), - babel({ - exclude: 'node_modules/**', - plugins: ['external-helpers'] - }) + resolve({ extensions: ['.js', '.vue'] }), + babel({ plugins: ['external-helpers'] }) ] - if (item.min) plugins.push(uglify({}, minify)) + if (min) plugins.push(uglify({}, minify)) - rollup.rollup({ - input: item.src, - external: id => /^(echarts)/.test(id), - plugins - }).then(function (bundle) { - return bundle.write({ - format: item.type, - name: item.globalName, - globals: { - 'echarts/lib/echarts': 'echarts' - }, - file: item.dist + item.suffix - }) - }).catch((e) => { - console.log(e) - process.exit(1) - }) + const distPath = '../' + dist + suffix + const isCommonjs = format === 'cjs' + let reg = isCommonjs + ? /(^(echarts|numerify|utils-lite)|(\/core|\/utils|\/constants)$)/ + : /^(echarts)/ + const external = id => reg.test(id) + const globals = { 'echarts/lib/echarts': 'echarts' } + + const bundle = await rollup.rollup({ input, external, plugins }) + let { code } = await bundle.generate({ format, name, globals }) + if (isCommonjs) { + code = code.replace( + /require\('(.*)\/(utils|core|constants)'\)/g, + 'require(\'./$2\')' + ) + } + fs.writeFileSync(path.resolve(__dirname, distPath), code) } diff --git a/build/webpack.config.js b/build/webpack.config.js index 3d09766..7abc1c4 100755 --- a/build/webpack.config.js +++ b/build/webpack.config.js @@ -18,8 +18,7 @@ module.exports = { resolve: { extensions: ['.js', '.vue'], alias: { - 'vue$': 'vue/dist/vue.esm.js', - '@': './src' + 'vue$': 'vue/dist/vue.esm.js' } }, devServer: { diff --git a/docs/en/README.md b/docs/en/README.md index 1098269..5106d60 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -18,6 +18,11 @@ npm i v-charts echarts -S ``` +> when using bmap or amap need to add additional modules +>
`` +>
`` + + #### Example [online demo](https://jsfiddle.net/vue_echarts/hc4xhyva) diff --git a/docs/en/skill-demo.md b/docs/en/skill-demo.md index 7319d3c..c29ee99 100644 --- a/docs/en/skill-demo.md +++ b/docs/en/skill-demo.md @@ -8,7 +8,7 @@ call the echarts resize function. - + diff --git a/docs/install.md b/docs/install.md index 31d3d87..994990f 100644 --- a/docs/install.md +++ b/docs/install.md @@ -17,6 +17,10 @@ npm i v-charts echarts -S ``` +> 使用百度地图或高德地图时需要额外引入相应的模块 +>
`` +>
`` + ### cdn示例 #### 全部引入 diff --git a/docs/skill-demo.md b/docs/skill-demo.md index f0a5c9a..0ac4747 100644 --- a/docs/skill-demo.md +++ b/docs/skill-demo.md @@ -8,7 +8,7 @@