Skip to content

Commit 92d18b8

Browse files
author
foisonocean
committed
use rollup to build for different module system
cjs/esm/umd
1 parent 82baf01 commit 92d18b8

File tree

7 files changed

+130
-210
lines changed

7 files changed

+130
-210
lines changed

.babelrc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
{
2-
"plugins": ["transform-class-properties", "transform-object-rest-spread"],
2+
"plugins": [
3+
"transform-class-properties",
4+
"transform-object-rest-spread",
5+
"external-helpers"
6+
],
37
"presets": [
48
"react",
5-
"latest"
9+
["latest", {
10+
"es2015": {
11+
"loose": true,
12+
"modules": false
13+
}
14+
}]
615
]
716
}

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ static/
1212

1313
# VS Code
1414
#
15-
.vscode
16-
typings
15+
.vscode/
16+
typings/
17+
18+
# Compiled files
19+
#
20+
lib/
21+
es/
22+
umd/

lib/ReactDynamicFont.js

Lines changed: 0 additions & 140 deletions
This file was deleted.

lib/index.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
{
22
"name": "react-dynamic-font",
3-
"version": "0.0.4",
3+
"version": "0.0.6",
44
"description": "make your text does not wrap and dynamically adjust the font size",
55
"main": "lib/index.js",
6+
"module": "es/index.js",
7+
"umd": "umd/react-dynamic-font.js",
8+
"files": [
9+
"lib",
10+
"es",
11+
"umd"
12+
],
613
"scripts": {
714
"start": "node ./demo/server.js",
8-
"babel-build": "babel ./src --out-dir ./lib",
915
"lint": "eslint src demo",
10-
"clean": "rimraf lib",
11-
"build": "run-s clean babel-build",
16+
"clean": "rimraf lib es umd",
17+
"build:rollup": "rollup -c",
18+
"build": "run-s lint clean build:rollup",
1219
"precommit": "run-s lint",
13-
"prepush": "run-s lint"
20+
"prepush": "run-s lint",
21+
"prepublish": "run-s build"
1422
},
1523
"repository": {
1624
"type": "git",
@@ -34,10 +42,10 @@
3442
"react-dom": "^0.14.0 || ^15.0.0"
3543
},
3644
"devDependencies": {
37-
"babel-cli": "^6.26.0",
3845
"babel-core": "^6.26.0",
3946
"babel-eslint": "^8.0.1",
4047
"babel-loader": "^7.1.2",
48+
"babel-plugin-external-helpers": "^6.22.0",
4149
"babel-plugin-transform-class-properties": "^6.24.1",
4250
"babel-plugin-transform-object-rest-spread": "^6.26.0",
4351
"babel-polyfill": "^6.26.0",
@@ -59,6 +67,9 @@
5967
"react-dom": "^15.6.2",
6068
"react-hot-loader": "^3.1.1",
6169
"rimraf": "^2.6.2",
70+
"rollup": "^0.50.0",
71+
"rollup-plugin-babel": "^3.0.2",
72+
"rollup-plugin-uglify": "^2.0.1",
6273
"style-loader": "^0.19.0",
6374
"webpack": "^3.7.1",
6475
"webpack-dev-server": "^2.9.2"

rollup.config.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import babel from 'rollup-plugin-babel';
2+
import uglify from 'rollup-plugin-uglify';
3+
4+
import packageInfo from './package.json';
5+
6+
const baseConfig = {
7+
input: 'src/index.js',
8+
external: ['react', 'react-dom'],
9+
plugins: [
10+
babel({
11+
exclude: 'node_modules/**',
12+
}),
13+
],
14+
};
15+
16+
const commonjsConfig = Object.assign({}, baseConfig, {
17+
output: {
18+
file: packageInfo.main,
19+
format: 'cjs',
20+
},
21+
});
22+
23+
const esConfig = Object.assign({}, baseConfig, {
24+
output: {
25+
file: packageInfo.module,
26+
format: 'es',
27+
},
28+
});
29+
30+
const umdConfig = Object.assign({}, baseConfig, {
31+
name: 'ReactDynamicFont',
32+
globals: {
33+
react: 'React',
34+
'react-dom': 'ReactDOM',
35+
},
36+
output: {
37+
file: packageInfo.umd,
38+
format: 'umd',
39+
},
40+
plugins: [
41+
...baseConfig.plugins,
42+
uglify(),
43+
],
44+
});
45+
46+
export default [
47+
commonjsConfig,
48+
esConfig,
49+
umdConfig,
50+
];

0 commit comments

Comments
 (0)