Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit d3e2359

Browse files
author
Federico Zivolo
committed
build: simplified build, and ship cjs in lib
1 parent 726ecb2 commit d3e2359

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

.babelrc

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
"env": {
55
"test": {
66
"presets": ["env", "stage-1", "react"]
7+
},
8+
"es": {
9+
"presets": [["env", { "modules": false }], "stage-1", "react"]
10+
},
11+
"cjs": {
12+
"presets": [["env", { "modules": "commonjs" }], "stage-1", "react"]
713
}
814
}
915
}

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package.json

package.json

+8-10
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@
55
"license": "MIT",
66
"author": "Travis Arnold <[email protected]> (http://souporserious.com)",
77
"homepage": "https://github.com/souporserious/react-popper",
8-
"main": "dist/react-popper.js",
9-
"umd:main": "dist/react-popper.umd.js",
10-
"module": "lib/index.js",
8+
"main": "lib/cjs/index.js",
9+
"module": "lib/es/index.js",
10+
"browser": "dist/react-popper.js",
1111
"typings": "typings/react-popper.d.ts",
1212
"files": [
1313
"dist",
1414
"lib",
1515
"typings/react-popper.d.ts"
1616
],
1717
"scripts": {
18-
"build": "npm run build:clean && npm run build:es && npm run build:umd && npm run build:cjs && npm run build:flow && npm run build:umd-min && npm run build:cjs-min",
18+
"build": "npm run build:clean && npm run build:es && npm run build:cjs && npm run build:browser && npm run build:flow",
1919
"build:clean": "rimraf dist/ && rimraf lib/",
20-
"build:es": "babel src --ignore '*.test.js,__mocks__' --out-dir lib",
21-
"build:umd": "rollup -c --output.format umd --output.name 'react-popper' --output.file dist/react-popper.umd.js",
22-
"build:cjs": "rollup -c --output.format cjs --output.name 'react-popper' --output.file dist/react-popper.js",
23-
"build:flow": "flow-copy-source --ignore '{__mocks__/*,*.test}.js' src lib",
24-
"build:umd-min": "MINIFY=true rollup -c --output.format umd --output.name 'react-popper' --output.file dist/react-popper.umd.min.js",
25-
"build:cjs-min": "MINIFY=true rollup -c --output.format cjs --output.name 'react-popper' --output.file dist/react-popper.min.js",
20+
"build:es": "BABEL_ENV=es babel src --ignore '*.test.js,__mocks__' --out-dir lib/es",
21+
"build:cjs": "BABEL_ENV=cjs babel src --ignore '*.test.js,__mocks__' --out-dir lib/cjs",
22+
"build:browser": "rollup -c",
23+
"build:flow": "flow-copy-source --ignore '{__mocks__/*,*.test}.js' src lib/es",
2624
"demo": "parcel --out-dir demo/dist demo/index.html",
2725
"test": "npm run test:eslint && npm run test:flow && npm run test:ts && npm run test:jest",
2826
"test:ts": "tsc --project ./typings/tests",

rollup.config.js

+48-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,55 @@
11
import babel from 'rollup-plugin-babel';
22
import minify from 'rollup-plugin-babel-minify';
33

4-
export default {
4+
const common = {
55
input: 'src/index.js',
6+
external: [
7+
'react',
8+
'react-dom',
9+
'popper.js',
10+
'create-react-context',
11+
'warning',
12+
],
13+
};
14+
15+
const commonOutput = {
16+
name: 'react-popper',
17+
sourcemap: true,
18+
globals: {
19+
react: 'react',
20+
'prop-types': 'PropTypes',
21+
'popper.js': 'PopperJS',
22+
'create-react-context': 'createContext',
23+
warning: 'warning',
24+
},
25+
};
26+
27+
const babelConfig = {
28+
babelrc: false,
29+
presets: [['env', { modules: false }], 'stage-1', 'react'],
630
plugins: [
7-
babel({
8-
babelrc: false,
9-
presets: [['env', { modules: false }], 'stage-1', 'react'],
10-
plugins: [
11-
'external-helpers',
12-
['transform-react-remove-prop-types', { mode: 'wrap' }],
13-
],
14-
}),
15-
process.env.MINIFY ? minify() : false,
16-
].filter(Boolean),
17-
external: ['react', 'react-dom', 'prop-types', 'popper.js'],
18-
output: {
19-
sourcemap: true,
20-
globals: {
21-
react: 'react',
22-
'prop-types': 'PropTypes',
23-
'popper.js': 'PopperJS',
31+
'external-helpers',
32+
['transform-react-remove-prop-types', { mode: 'wrap' }],
33+
],
34+
};
35+
36+
export default [
37+
{
38+
...common,
39+
plugins: [babel(babelConfig)],
40+
output: {
41+
...commonOutput,
42+
format: 'umd',
43+
file: 'dist/react-popper.js',
2444
},
2545
},
26-
};
46+
{
47+
...common,
48+
plugins: [babel(babelConfig), minify()],
49+
output: {
50+
...commonOutput,
51+
format: 'umd',
52+
file: 'dist/react-popper.min.js',
53+
},
54+
},
55+
];

0 commit comments

Comments
 (0)