Skip to content

Commit

Permalink
add tree shaking example
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed May 19, 2020
1 parent bb822a5 commit 889cfff
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ npm-debug.log*

*.tgz
/.vscode

/sample_treeshake/build
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
16 changes: 16 additions & 0 deletions sample_treeshake/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
modules: false,
},
],
],
env: {
test: {
presets: [['@babel/preset-env']],
},
},
plugins: ['@babel/plugin-transform-runtime'],
};
12 changes: 12 additions & 0 deletions sample_treeshake/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Box Plot Chart</title>
</head>
<body>
<div id="container" style="width: 75%;">
<canvas id="canvas"></canvas>
</div>
<script src="build/index.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions sample_treeshake/rollup.config.js
Original file line number Diff line number Diff line change
@@ -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' })],
},
];
17 changes: 17 additions & 0 deletions sample_treeshake/src/index.js
Original file line number Diff line number Diff line change
@@ -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()),
],
},
],
},
});
1 change: 0 additions & 1 deletion samples/default_esm.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
}
</script>
<script type="module-shim">
import Chart from 'chart.js';
import { BoxPlotChart } from '@sgratzl/chartjs-chart-boxplot';

const chart = new BoxPlotChart(document.getElementById('canvas'), {
Expand Down

0 comments on commit 889cfff

Please sign in to comment.