Skip to content

Commit 58e8842

Browse files
committed
update build script with rollup
1 parent 8c21ef0 commit 58e8842

File tree

5 files changed

+90
-9
lines changed

5 files changed

+90
-9
lines changed

.babelrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"presets": [ "env", "react" ]
2+
"presets": [
3+
["env", {
4+
"modules": false
5+
}],
6+
"react"
7+
]
38
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ coverage
88

99
# production
1010
lib
11+
dist
1112

1213
# misc
1314
.DS_Store

package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
"license": "MIT",
1515
"author": "jose miguel bejarano",
1616
"files": [
17-
"lib"
17+
"dist"
1818
],
19-
"main": "lib/index.js",
19+
"main": "dist/react-currency-formatter.cjs.js",
20+
"module": "dist/react-currency-formatter.esm.js",
21+
"browser": "dist/react-currency-formatter.umd.js",
2022
"repository": {
2123
"type": "git",
2224
"url": "https://github.com/xDae/react-currency-formatter.git"
2325
},
2426
"scripts": {
25-
"build": "rimraf lib && babel src --out-dir lib --ignore test.js --copy-files",
27+
"build": "rimraf dist && rollup -c",
2628
"build-storybook": "build-storybook -o docs",
2729
"publish": "np",
2830
"start": "npm run storybook",
@@ -42,6 +44,7 @@
4244
"babel-core": "^6.26.0",
4345
"babel-eslint": "^8.0.1",
4446
"babel-jest": "^21.2.0",
47+
"babel-plugin-external-helpers": "^6.22.0",
4548
"babel-preset-env": "^1.6.0",
4649
"babel-preset-react": "^6.24.1",
4750
"codecov": "^2.3.0",
@@ -59,7 +62,12 @@
5962
"react-dev-utils": "^4.1.0",
6063
"react-dom": "^16.0.0",
6164
"react-test-renderer": "^16.0.0",
62-
"rimraf": "^2.6.2"
65+
"rimraf": "^2.6.2",
66+
"rollup": "^0.50.0",
67+
"rollup-plugin-babel": "^3.0.2",
68+
"rollup-plugin-commonjs": "^8.0.2",
69+
"rollup-plugin-node-resolve": "^3.0.0",
70+
"rollup-plugin-replace": "^2.0.0"
6371
},
6472
"peerDependencies": {
6573
"react": "16.x"
@@ -70,9 +78,11 @@
7078
"js",
7179
"json"
7280
],
73-
"setupFiles": ["<rootDir>/src/setupTests"],
81+
"setupFiles": [
82+
"<rootDir>/src/setupTests"
83+
],
7484
"testPathIgnorePatterns": [
75-
"<rootDir>/(lib|docs|node_modules)/"
85+
"<rootDir>/(dist|docs|node_modules)/"
7686
]
7787
}
7888
}

rollup.config.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import resolve from 'rollup-plugin-node-resolve';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import replace from 'rollup-plugin-replace';
4+
import babel from 'rollup-plugin-babel';
5+
import pkg from './package.json';
6+
7+
export default [
8+
// browser-friendly UMD build
9+
{
10+
input: 'src/index.js',
11+
output: {
12+
file: pkg.browser,
13+
format: 'umd'
14+
},
15+
name: 'reactCurrencyFormatter',
16+
external: ['react', 'prop-types'],
17+
globals: {
18+
'react': 'React',
19+
'prop-types': 'PropTypes'
20+
},
21+
plugins: [
22+
resolve(),
23+
commonjs({
24+
namedExports: {
25+
'node_modules/react/react.js': ['Component']
26+
}
27+
}),
28+
babel({
29+
plugins: ['external-helpers'],
30+
exclude: ['node_modules/**']
31+
})
32+
]
33+
},
34+
35+
// CommonJS (for Node) and ES module (for bundlers) build.
36+
// (We could have three entries in the configuration array
37+
// instead of two, but it's quicker to generate multiple
38+
// builds from a single configuration where possible, using
39+
// the `targets` option which can specify `dest` and `format`)
40+
{
41+
input: 'src/index.js',
42+
external: ['react', 'prop-types'],
43+
globals: {
44+
'react': 'React',
45+
'prop-types': 'PropTypes'
46+
},
47+
output: [
48+
{ file: pkg.main, format: 'cjs' },
49+
{ file: pkg.module, format: 'es' }
50+
],
51+
plugins: [
52+
resolve(),
53+
commonjs({
54+
namedExports: {
55+
'node_modules/react/react.js': ['Component']
56+
}
57+
}),
58+
babel({
59+
plugins: ['external-helpers'],
60+
exclude: ['node_modules/**']
61+
}),
62+
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
63+
]
64+
}
65+
];

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import locales from './locales';
55
import defaultLocales from './default-locales';
66
import symbols from './symbols';
77

8-
class ReactCurrencyFormatter extends Component {
8+
class ReactCurrencyFormatter extends React.Component {
99
getFormatter(options) {
1010
let locale, currency, symbol, pattern, decimal, group;
1111

0 commit comments

Comments
 (0)