From 889cfff3032b4d2d8caa0a7f99f934a112f89d92 Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Tue, 19 May 2020 10:58:47 +0200 Subject: [PATCH] add tree shaking example --- .gitignore | 2 ++ package.json | 3 ++- sample_treeshake/babel.config.js | 16 ++++++++++++++++ sample_treeshake/index.html | 12 ++++++++++++ sample_treeshake/rollup.config.js | 18 ++++++++++++++++++ sample_treeshake/src/index.js | 17 +++++++++++++++++ samples/default_esm.html | 1 - 7 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 sample_treeshake/babel.config.js create mode 100644 sample_treeshake/index.html create mode 100644 sample_treeshake/rollup.config.js create mode 100644 sample_treeshake/src/index.js diff --git a/.gitignore b/.gitignore index a687ffb..a46a8ba 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ npm-debug.log* *.tgz /.vscode + +/sample_treeshake/build \ No newline at end of file diff --git a/package.json b/package.json index 9883b47..f4bb7fd 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,8 @@ "prepare": "npm run build:dev", "prepublishOnly": "npm run build:prod", "release": "release-it --disable-metrics --npm.skipChecks", - "release:pre": "release-it --disable-metrics --npm.skipChecks --preRelease=alpha --npm.tag=next" + "release:pre": "release-it --disable-metrics --npm.skipChecks --preRelease=alpha --npm.tag=next", + "sample": "cd sample_treeshake && rollup -c" }, "dependenciesMeta": { "chart.js": { diff --git a/sample_treeshake/babel.config.js b/sample_treeshake/babel.config.js new file mode 100644 index 0000000..bc7bd37 --- /dev/null +++ b/sample_treeshake/babel.config.js @@ -0,0 +1,16 @@ +module.exports = { + presets: [ + [ + '@babel/preset-env', + { + modules: false, + }, + ], + ], + env: { + test: { + presets: [['@babel/preset-env']], + }, + }, + plugins: ['@babel/plugin-transform-runtime'], +}; diff --git a/sample_treeshake/index.html b/sample_treeshake/index.html new file mode 100644 index 0000000..7cfd4e2 --- /dev/null +++ b/sample_treeshake/index.html @@ -0,0 +1,12 @@ + + + + Box Plot Chart + + +
+ +
+ + + diff --git a/sample_treeshake/rollup.config.js b/sample_treeshake/rollup.config.js new file mode 100644 index 0000000..53022ba --- /dev/null +++ b/sample_treeshake/rollup.config.js @@ -0,0 +1,18 @@ +// rollup.config.js +import pnp from 'rollup-plugin-pnp-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import resolve from '@rollup/plugin-node-resolve'; +import babel from '@rollup/plugin-babel'; + +export default [ + { + input: 'src/index.js', + output: { + file: 'build/index.js', + name: 'BoxPlotExample', + format: 'umd', + }, + external: [], + plugins: [commonjs(), pnp(), resolve(), babel({ babelHelpers: 'runtime' })], + }, +]; diff --git a/sample_treeshake/src/index.js b/sample_treeshake/src/index.js new file mode 100644 index 0000000..6000e57 --- /dev/null +++ b/sample_treeshake/src/index.js @@ -0,0 +1,17 @@ +import { BoxPlotChart } from '../../src'; + +new BoxPlotChart(document.getElementById('canvas'), { + data: { + labels: ['A'], + datasets: [ + { + label: 'Test', + data: [ + Array(100) + .fill(0) + .map(() => Math.random()), + ], + }, + ], + }, +}); diff --git a/samples/default_esm.html b/samples/default_esm.html index 6945349..a7ebc19 100644 --- a/samples/default_esm.html +++ b/samples/default_esm.html @@ -17,7 +17,6 @@ }