Skip to content

Commit

Permalink
Update build config
Browse files Browse the repository at this point in the history
  • Loading branch information
bondz committed Feb 19, 2019
1 parent 215168b commit 24a0649
Show file tree
Hide file tree
Showing 5 changed files with 3,183 additions and 757 deletions.
42 changes: 1 addition & 41 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
{
"ignore": ["node_modules/**"],
"env": {
"test": {
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
],
"react",
"stage-1"
],
"plugins": [
"transform-object-rest-spread",
"transform-react-remove-prop-types"
]
},
"development": {
"presets": [
[
"env",
{
"targets": {
"browsers": ["last 5 versions", "safari >= 7"]
},
"modules": false
}
],
"react",
"stage-1"
],
"plugins": [
"transform-object-rest-spread",
"external-helpers",
"transform-react-remove-prop-types"
]
}
}
"presets": [["@babel/env", { "loose": true }], "@babel/react"],
}
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/react-epic-spinners.cjs.min.js');
} else {
module.exports = require('./dist/react-epic-spinners.cjs.js');
}
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "react-epic-spinners",
"version": "0.2.1",
"main": "dist/react-epic-spinners.cjs.js",
"main": "./index.js",
"module": "dist/react-epic-spinners.esm.js",
"browser": "dist/react-epic-spinners.umd.js",
"browser": "dist/react-epic-spinners.umd.min.js",
"repository": {
"type": "git",
"url": "git@github.com:bondz/react-epic-spinners.git"
Expand All @@ -22,24 +22,25 @@
"styled-components": "^2.4.0"
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-external-helpers": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"@types/react": "^16.0.34",
"babel-core": "^6.26.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.12",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"jest": "^21.2.1",
"prop-types": "^15.6.0",
"raf": "^3.4.0",
"react-dom": "^16.0.0",
"rollup": "^0.54.1",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "8.2.3",
"rollup-plugin-node-resolve": "^3.0.2"
"rollup": "^0.68.1",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "9.2.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-size-snapshot": "^0.7.0",
"rollup-plugin-uglify": "^6.0.0"
},
"scripts": {
"build": "rollup -c",
Expand Down
129 changes: 104 additions & 25 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,122 @@
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import replace from 'rollup-plugin-replace';
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
import { uglify } from 'rollup-plugin-uglify';

import pkg from './package.json';

export default [
// browser-friendly UMD build
const input = 'src/index.js';
const globalName = 'ReactEpicSpinners';

function external(id) {
return !id.startsWith('.') && !id.startsWith('/');
}

const cjs = [
{
input,
output: { file: `dist/${pkg.name}.cjs.js`, format: 'cjs' },
external,
plugins: [
babel({ exclude: /node_modules/ }),
replace({ 'process.env.NODE_ENV': JSON.stringify('development') })
]
},
{
input: 'src/index.js',
input,
output: { file: `dist/${pkg.name}.cjs.min.js`, format: 'cjs' },
external,
plugins: [
babel({ exclude: /node_modules/ }),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
uglify()
]
}
];

const esm = [
{
input,
output: { file: `dist/${pkg.name}.esm.js`, format: 'esm' },
external,
plugins: [
babel({
exclude: /node_modules/,
runtimeHelpers: true,
plugins: [['@babel/transform-runtime', { useESModules: true }]]
}),
sizeSnapshot()
]
}
];

const globals = {
react: 'React',
'prop-types': 'PropTypes',
'styled-components': 'StyledComponents'
};

const umd = [
{
input,
output: {
file: pkg.browser,
file: `dist/${pkg.name}.umd.js`,
format: 'umd',
name: 'ReactEpicSpinners',
name: globalName,
globals
},
external,
plugins: [
resolve(),
commonjs(),
babel({
exclude: ['node_modules/**'],
exclude: /node_modules/,
}),
],
external: ['react', 'prop-types', 'styled-components'],
resolve(),
commonjs({
include: /node_modules/
}),
replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
sizeSnapshot()
]
},

// CommonJS (for Node) and ES module (for bundlers) build.
// (We could have three entries in the configuration array
// instead of two, but it's quicker to generate multiple
// builds from a single configuration where possible, using
// the `targets` option which can specify `dest` and `format`)
{
input: 'src/index.js',
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' },
],
input,
output: {
file: `dist/${pkg.name}.umd.min.js`,
format: 'umd',
name: globalName,
globals
},
external,
plugins: [
babel({
exclude: ['node_modules/**'],
exclude: /node_modules/,
}),
],
external: ['react', 'prop-types', 'styled-components'],
},
resolve(),
commonjs({
include: /node_modules/
}),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
sizeSnapshot(),
uglify()
]
}
];

let config;
switch (process.env.BUILD_ENV) {
case 'cjs':
config = cjs;
break;
case 'esm':
config = esm;
break;
case 'umd':
config = umd;
break;
default:
config = cjs.concat(esm).concat(umd);
}

export default config;
Loading

0 comments on commit 24a0649

Please sign in to comment.