Skip to content

Commit

Permalink
Simplify the Rollup build to one command.
Browse files Browse the repository at this point in the history
  • Loading branch information
timdorr committed Sep 25, 2018
1 parent f43a085 commit 3acb007
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 76 deletions.
24 changes: 0 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,6 @@ Running the `build` task will create a CommonJS module-per-module build, a ES Mo
npm run build
```

To create just a CommonJS module-per-module build:

```
npm run build:commonjs
```

The result will be in the `lib` folder.

To create just a ES Modules build:

```
npm run build:es
```

The result will be in the `es` folder.

To create just a UMD build:
```
npm run build:umd
npm run build:umd:min
```

The result will be in the `dist` folder.

### Testing and Linting

To only run linting:
Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" index.d.ts",
"format:check": "prettier --list-different \"{src,test}/**/*.{js,ts}\" index.d.ts",
"lint": "eslint src test",
"pretest": "npm run build:commonjs",
"pretest": "npm run build",
"test": "cross-env BABEL_ENV=commonjs jest",
"test:watch": "npm test -- --watch",
"test:cov": "npm test -- --coverage",
"build:commonjs": "cross-env NODE_ENV=cjs rollup -c -o lib/redux.js",
"build:es": "cross-env BABEL_ENV=es NODE_ENV=es rollup -c -o es/redux.js",
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -o dist/redux.js",
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -o dist/redux.min.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
"build": "rollup -c",
"prepare": "npm run clean && npm run format:check && npm run lint && npm test && npm run build",
"examples:lint": "eslint examples",
"examples:test": "cross-env CI=true babel-node examples/testAll.js"
Expand Down
121 changes: 75 additions & 46 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,78 @@ import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import { terser } from 'rollup-plugin-terser'

const env = process.env.NODE_ENV
const config = {
input: 'src/index.js',
plugins: []
}

if (env === 'es' || env === 'cjs') {
config.output = { format: env, indent: false }
config.external = ['symbol-observable']
config.plugins.push(
babel({
plugins: ['external-helpers'],
})
)
}

if (env === 'development' || env === 'production') {
config.output = { format: 'umd', name: 'Redux', indent: false }
config.plugins.push(
nodeResolve({
jsnext: true
}),
babel({
exclude: 'node_modules/**',
plugins: ['external-helpers'],
}),
replace({
'process.env.NODE_ENV': JSON.stringify(env)
})
)
}

if (env === 'production') {
config.plugins.push(
terser({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false
}
})
)
}

export default config
export default [
{
input: 'src/index.js',
output: { file: 'lib/redux.js', format: 'cjs', indent: false },
external: ['symbol-observable'],
plugins: [
babel({
plugins: ['external-helpers']
})
]
},
{
input: 'src/index.js',
output: { file: 'es/redux.js', format: 'es', indent: false },
external: ['symbol-observable'],
plugins: [
babel({
env: 'es',
plugins: ['external-helpers']
})
]
},
{
input: 'src/index.js',
output: {
file: 'dist/redux.js',
format: 'umd',
name: 'Redux',
indent: false
},
plugins: [
nodeResolve({
jsnext: true
}),
babel({
env: 'es',
exclude: 'node_modules/**',
plugins: ['external-helpers']
}),
replace({
'process.env.NODE_ENV': JSON.stringify('development')
})
]
},
{
input: 'src/index.js',
output: {
file: 'dist/redux.min.js',
format: 'umd',
name: 'Redux',
indent: false
},
plugins: [
nodeResolve({
jsnext: true
}),
babel({
env: 'es',
exclude: 'node_modules/**',
plugins: ['external-helpers']
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
terser({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false
}
})
]
}
]

0 comments on commit 3acb007

Please sign in to comment.