Skip to content

Commit

Permalink
build: simplified build, and ship cjs in lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Zivolo committed Apr 5, 2018
1 parent 726ecb2 commit d3e2359
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"env": {
"test": {
"presets": ["env", "stage-1", "react"]
},
"es": {
"presets": [["env", { "modules": false }], "stage-1", "react"]
},
"cjs": {
"presets": [["env", { "modules": "commonjs" }], "stage-1", "react"]
}
}
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package.json
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
"license": "MIT",
"author": "Travis Arnold <[email protected]> (http://souporserious.com)",
"homepage": "https://github.com/souporserious/react-popper",
"main": "dist/react-popper.js",
"umd:main": "dist/react-popper.umd.js",
"module": "lib/index.js",
"main": "lib/cjs/index.js",
"module": "lib/es/index.js",
"browser": "dist/react-popper.js",
"typings": "typings/react-popper.d.ts",
"files": [
"dist",
"lib",
"typings/react-popper.d.ts"
],
"scripts": {
"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",
"build": "npm run build:clean && npm run build:es && npm run build:cjs && npm run build:browser && npm run build:flow",
"build:clean": "rimraf dist/ && rimraf lib/",
"build:es": "babel src --ignore '*.test.js,__mocks__' --out-dir lib",
"build:umd": "rollup -c --output.format umd --output.name 'react-popper' --output.file dist/react-popper.umd.js",
"build:cjs": "rollup -c --output.format cjs --output.name 'react-popper' --output.file dist/react-popper.js",
"build:flow": "flow-copy-source --ignore '{__mocks__/*,*.test}.js' src lib",
"build:umd-min": "MINIFY=true rollup -c --output.format umd --output.name 'react-popper' --output.file dist/react-popper.umd.min.js",
"build:cjs-min": "MINIFY=true rollup -c --output.format cjs --output.name 'react-popper' --output.file dist/react-popper.min.js",
"build:es": "BABEL_ENV=es babel src --ignore '*.test.js,__mocks__' --out-dir lib/es",
"build:cjs": "BABEL_ENV=cjs babel src --ignore '*.test.js,__mocks__' --out-dir lib/cjs",
"build:browser": "rollup -c",
"build:flow": "flow-copy-source --ignore '{__mocks__/*,*.test}.js' src lib/es",
"demo": "parcel --out-dir demo/dist demo/index.html",
"test": "npm run test:eslint && npm run test:flow && npm run test:ts && npm run test:jest",
"test:ts": "tsc --project ./typings/tests",
Expand Down
67 changes: 48 additions & 19 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
import babel from 'rollup-plugin-babel';
import minify from 'rollup-plugin-babel-minify';

export default {
const common = {
input: 'src/index.js',
external: [
'react',
'react-dom',
'popper.js',
'create-react-context',
'warning',
],
};

const commonOutput = {
name: 'react-popper',
sourcemap: true,
globals: {
react: 'react',
'prop-types': 'PropTypes',
'popper.js': 'PopperJS',
'create-react-context': 'createContext',
warning: 'warning',
},
};

const babelConfig = {
babelrc: false,
presets: [['env', { modules: false }], 'stage-1', 'react'],
plugins: [
babel({
babelrc: false,
presets: [['env', { modules: false }], 'stage-1', 'react'],
plugins: [
'external-helpers',
['transform-react-remove-prop-types', { mode: 'wrap' }],
],
}),
process.env.MINIFY ? minify() : false,
].filter(Boolean),
external: ['react', 'react-dom', 'prop-types', 'popper.js'],
output: {
sourcemap: true,
globals: {
react: 'react',
'prop-types': 'PropTypes',
'popper.js': 'PopperJS',
'external-helpers',
['transform-react-remove-prop-types', { mode: 'wrap' }],
],
};

export default [
{
...common,
plugins: [babel(babelConfig)],
output: {
...commonOutput,
format: 'umd',
file: 'dist/react-popper.js',
},
},
};
{
...common,
plugins: [babel(babelConfig), minify()],
output: {
...commonOutput,
format: 'umd',
file: 'dist/react-popper.min.js',
},
},
];

0 comments on commit d3e2359

Please sign in to comment.