Skip to content

Commit

Permalink
feat(rollup): simpler rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
chambo-e committed Sep 28, 2020
1 parent bdde233 commit 2cb1400
Show file tree
Hide file tree
Showing 8 changed files with 784 additions and 232 deletions.
2 changes: 0 additions & 2 deletions .browserslistrc

This file was deleted.

4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module.exports = {
'emotion/no-vanilla': 'error',
'emotion/import-from-emotion': 'error',
'emotion/syntax-preference': ['error', 'string'],
'import/no-extraneous-dependencies': [
'error',
{ devDependencies: ['rollup.config.js'] },
],
},
env: {
browser: true,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
dist/
.idea/
.DS_Store
.eslintcache
22 changes: 0 additions & 22 deletions babel.config.js

This file was deleted.

1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] }
50 changes: 38 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,71 @@
"yarn": ">=1.22.4"
},
"sideEffects": false,
"main": "dist/scaleway-ui.cjs.js",
"module": "dist/scaleway-ui.es.js",
"jsnext:main": "dist/scaleway-ui.es.js",
"main": "dist/index.js",
"browser": "dist/index.js",
"module": "dist/module.js",
"jsnext:main": "dist/module.js",
"scripts": {
"build": "rollup -c",
"build:profile": "cross-env PROFILE=true rollup -c",
"dev": "docz dev",
"docz:build": "docz build",
"format": "prettier --write '**/*.{js,json,md,mdx}'",
"lint": "eslint .",
"lint": "eslint --cache .",
"prebuild": "shx rm -rf dist",
"prepublishOnly": "yarn build",
"release": "standard-version",
"transfer": "yarn build && cp -f ./dist/* ../shire/node_modules/@scaleway/ui/dist"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged",
"pre-push": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"prettier --write",
"eslint --fix"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"peerDependencies": {
"@emotion/core": "^10.0.28",
"@emotion/styled": "^10.0.27",
"@smooth-ui/core-em": "^10.0.0",
"emotion-theming": "^10.0.27",
"react": "^16.13.1",
"react-countup": "^4.3.3",
"react-dom": "^16.13.1",
"react-toastify": "^6.0.8"
"react-dom": "^16.13.1"
},
"devDependencies": {
"@babel/core": "^7.11.4",
"@babel/node": "^7.10.5",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.11.5",
"@babel/preset-env": "^7.11.0",
"@babel/preset-react": "^7.10.4",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@emotion/babel-preset-css-prop": "^10.0.27",
"@emotion/core": "^10.0.28",
"@emotion/styled": "^10.0.27",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@smooth-ui/core-em": "^10.1.0",
"babel-eslint": "^10.1.0",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"babel-plugin-emotion": "^10.0.33",
"babel-plugin-module-resolver": "^4.0.0",
"builtin-modules": "^3.1.0",
"cross-env": "^7.0.2",
"css-loader": "^3.6.0",
"docz": "^1.3.2",
"docz-theme-default": "^1.2.0",
Expand All @@ -62,22 +88,22 @@
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.0",
"husky": "^4.3.0",
"lint-staged": "^10.4.0",
"prettier": "^2.1.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"read-pkg": "^5.2.0",
"rollup": "^2.26.5",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-analyzer": "^3.3.0",
"rollup-plugin-postcss": "^3.1.8",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.4",
"shx": "^0.3.2",
"standard-version": "^9.0.0",
"style-loader": "^1.2.1",
"zxcvbn": "^4.4.2"
},
"dependencies": {
"@babel/runtime": "^7.11.2",
"docker-names": "^1.1.1",
"framer-motion": "^1.11.1",
"polished": "^3.6.5",
Expand Down
152 changes: 59 additions & 93 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,109 +1,75 @@
/* eslint-disable import/no-extraneous-dependencies */
import path from 'path'
import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import commonjs from 'rollup-plugin-commonjs'
import readPkg from 'read-pkg'
import babel from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import builtins from 'builtin-modules'
import postcss from 'rollup-plugin-postcss'
import { uglify } from 'rollup-plugin-uglify'
import pkg from './package.json'
import analyze from 'rollup-plugin-analyzer'

function getConfig() {
const name = 'scalewayUi'
const buildName = 'scaleway-ui'
const PROFILE = !!process.env.PROFILE

const SOURCE_DIR = path.resolve(__dirname, 'src')
const DIST_DIR = path.resolve(__dirname, 'dist')
export default async () => {
const pkg = await readPkg()

const baseConfig = {
input: `${SOURCE_DIR}/index.js`,
const targets = pkg.browser
? `
> 1%,
last 2 versions
`
: { node: '14' }

const external = id =>
[
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
...(pkg.browser ? [] : builtins),
].find(dep => new RegExp(dep).test(id))

return {
input: './src/index.js',
plugins: [
babel({
babelHelpers: 'runtime',
babelrc: false,
exclude: 'node_modules/**',
configFile: path.join(__dirname, 'babel.config.js'),
presets: [
['@babel/env', { modules: false, targets, loose: true }],
'@babel/preset-react',
[
'@emotion/babel-preset-css-prop',
{ autoLabel: true, labelFormat: '[filename]--[local]' },
],
],
plugins: [
'babel-plugin-emotion',
'babel-plugin-annotate-pure-calls',
['@babel/plugin-proposal-class-properties', { loose: true }],
['babel-plugin-module-resolver', { root: ['./src'] }],
'@babel/plugin-transform-runtime',
],
}),
postcss({
plugins: [],
}),
],
}

const esConfig = {
...baseConfig,
...{
output: {
file: `${DIST_DIR}/${buildName}.es.js`,
format: 'es',
},
external: [
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.dependencies || {}),
],
plugins: [...baseConfig.plugins, resolve()],
},
}

const cjsConfig = {
...esConfig,
...{
output: {
file: `${DIST_DIR}/${buildName}.cjs.js`,
format: 'cjs',
},
},
}

const globals = {
polished: 'polished',
'prop-types': 'PropTypes',
'emotion-theming': 'emotionTheming',
'@emotion/core': 'emotion',
react: 'React',
'react-dom': 'ReactDom',
}

const umdConfig = {
...baseConfig,
...{
output: {
name,
file: `${DIST_DIR}/${buildName}.js`,
resolve({
preferBuiltins: true,
}),
commonjs({
include: '**/node_modules/**',
}),
PROFILE && analyze({ summaryOnly: true }),
].filter(Boolean),
external,
output: [
{
format: 'umd',
globals,
exports: 'named',
sourcemap: false,
name: pkg.name,
file: 'dist/index.js',
},
external: Object.keys(globals),
plugins: [...baseConfig.plugins, resolve({ browser: true }), commonjs()],
},
}

const minConfig = {
...umdConfig,
...{
output: {
...umdConfig.output,
file: `${DIST_DIR}/${buildName}.min.js`,
{
format: 'es',
file: 'dist/module.js',
},
plugins: [
...umdConfig.plugins,
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
},
}),
],
},
}

if (process.env.WATCH_MODE) {
return [esConfig, cjsConfig]
],
}

return [esConfig, cjsConfig, umdConfig, minConfig]
}

export default getConfig()
Loading

0 comments on commit 2cb1400

Please sign in to comment.