Skip to content

Commit b94420d

Browse files
committed
Use rollup and babel to generate the builds
Expose es6 build.
1 parent c1a1f2f commit b94420d

File tree

6 files changed

+350
-21
lines changed

6 files changed

+350
-21
lines changed

.babelrc

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
{
2-
"presets": [
3-
"es2015",
4-
"react",
5-
"stage-1"
6-
]
2+
"env": {
3+
"development": {
4+
"presets": [
5+
["es2015", { "modules": "commonjs", "loose": true }],
6+
"react",
7+
"stage-1"
8+
]
9+
},
10+
"rollup": {
11+
"presets": [
12+
["es2015", { "modules": false, "loose": true }],
13+
"react",
14+
"stage-1"
15+
],
16+
"plugins": [
17+
"external-helpers"
18+
]
19+
},
20+
"jsnext": {
21+
"presets": [
22+
["es2015", { "modules": false, "loose": true }],
23+
"react",
24+
"stage-1"
25+
]
26+
}
27+
}
728
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ node_modules
1919
# Build directories
2020
lib
2121
dist
22+
es
2223

2324
# Example build directory
2425
example/dist

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ src
66
.eslintrc
77
.travis.yml
88
bower.json
9+
rollup.config.js

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "2.5.7",
44
"description": "react-chartjs-2",
55
"main": "lib/index.js",
6+
"module": "es/index.js",
7+
"jsnext:main": "es/index.js",
68
"author": "Jeremy Ayerst",
79
"homepage": "https://github.com/jerairrest/react-chartjs-2",
810
"repository": {
@@ -19,8 +21,10 @@
1921
},
2022
"devDependencies": {
2123
"@kadira/storybook": "^2.35.3",
24+
"babel-cli": "^6.26.0",
2225
"babel-core": "^6.18.2",
2326
"babel-eslint": "^4.1.3",
27+
"babel-plugin-external-helpers": "^6.22.0",
2428
"babel-preset-es2015": "^6.13.2",
2529
"babel-preset-react": "^6.11.1",
2630
"babel-preset-stage-1": "^6.13.0",
@@ -44,6 +48,12 @@
4448
"react-addons-test-utils": "^15.3.2",
4549
"react-component-gulp-tasks": "git+https://github.com/gor181/react-component-gulp-tasks.git",
4650
"react-dom": "^0.14 || ^15.0.0-rc || ^15.0",
51+
"rimraf": "^2.6.1",
52+
"rollup": "^0.47.6",
53+
"rollup-plugin-babel": "^3.0.2",
54+
"rollup-plugin-commonjs": "^8.1.0",
55+
"rollup-plugin-node-resolve": "^3.0.0",
56+
"rollup-plugin-uglify": "^2.0.1",
4757
"sinon": "^1.17.6"
4858
},
4959
"peerDependencies": {
@@ -57,7 +67,12 @@
5767
"chart.js": "global:Chart"
5868
},
5969
"scripts": {
60-
"build": "gulp clean && cross-env NODE_ENV=production gulp build",
70+
"clean": "rimraf lib es dist",
71+
"build:cjs": "babel src --out-dir lib",
72+
"build:es": "cross-env BABEL_ENV=jsnext babel src --out-dir es",
73+
"build:umd": "cross-env BABEL_ENV=rollup NODE_ENV=development rollup -c -o dist/react-chartjs-2.js",
74+
"build:umd:min": "cross-env BABEL_ENV=rollup NODE_ENV=production rollup -c -o dist/react-chartjs-2.min.js",
75+
"build": "npm run clean && npm run build:cjs && npm run build:es && npm run build:umd && npm run build:umd:min",
6176
"examples": "gulp dev:server",
6277
"lint": "eslint ./; true",
6378
"publish:site": "cross-env NODE_ENV=production gulp publish:examples",

rollup.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import nodeResolve from 'rollup-plugin-node-resolve';
2+
import babel from 'rollup-plugin-babel';
3+
import commonjs from 'rollup-plugin-commonjs';
4+
import uglify from 'rollup-plugin-uglify';
5+
6+
const env = process.env.NODE_ENV;
7+
8+
const config = {
9+
entry: 'src/index.js',
10+
external: ['chart.js', 'react'],
11+
globals: {
12+
'chart.js': 'Chart',
13+
react: 'React'
14+
},
15+
exports: 'named',
16+
format: 'umd',
17+
moduleName: 'ReactChartjs2',
18+
plugins: [
19+
nodeResolve(),
20+
babel({
21+
exclude: '**/node_modules/**',
22+
}),
23+
commonjs(),
24+
],
25+
};
26+
27+
if (env === 'production') {
28+
config.plugins.push(
29+
uglify({
30+
compress: {
31+
pure_getters: true,
32+
unsafe: true,
33+
unsafe_comps: true,
34+
warnings: false
35+
},
36+
}),
37+
);
38+
}
39+
40+
export default config;

0 commit comments

Comments
 (0)