Skip to content

Commit

Permalink
feat: update rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
kmkzt committed Mar 12, 2020
1 parent 3b65823 commit 1b7aa42
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 30 deletions.
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest'
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest'
},
testRegex: '(\\.|/)(test|spec)\\.(t|j)sx?$',
moduleNameMapper: {
Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"type": "module",
"types": "lib/index.d.ts",
"main": "lib/index.cjs.js",
"module": "lib/index.mjs",
"module": "lib/index.esm.js",
"browser": "lib/index.min.js",
"files": [
"lib/**/*.{js,ts}",
Expand Down Expand Up @@ -45,10 +45,16 @@
},
"devDependencies": {
"@babel/core": "7.8.3",
"@babel/plugin-proposal-class-properties": "7.8.3",
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/plugin-transform-runtime": "7.8.3",
"@babel/polyfill": "7.8.3",
"@babel/preset-env": "7.8.3",
"@babel/preset-typescript": "7.8.3",
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-json": "4.0.2",
"@rollup/plugin-node-resolve": "7.1.1",
"@rollup/plugin-replace": "2.3.1",
"@types/autoprefixer": "9.6.1",
"@types/babel-core": "6.25.6",
"@types/babel__core": "7.1.3",
Expand All @@ -73,10 +79,9 @@
"@typescript-eslint/parser": "2.16.0",
"@typescript-eslint/typescript-estree": "2.16.0",
"autoprefixer": "9.7.4",
"babel-core": "6.26.3",
"babel-jest": "24.9.0",
"babel-loader": "8.0.6",
"babel-preset-es2015": "6.24.1",
"babel-plugin-annotate-pure-calls": "0.4.0",
"css-loader": "3.4.2",
"eslint": "6.8.0",
"eslint-config-prettier": "6.9.0",
Expand All @@ -98,13 +103,12 @@
"resolve-url-loader": "3.1.0",
"rimraf": "3.0.0",
"rollup": "1.31.0",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-typescript": "1.0.1",
"rollup-plugin-babel": "4.4.0",
"rollup-plugin-size-snapshot": "0.11.0",
"rollup-plugin-sourcemaps": "0.5.0",
"rollup-plugin-terser": "5.2.0",
"sass-loader": "8.0.0",
"style-loader": "1.1.3",
"ts-jest": "24.3.0",
"ts-loader": "6.2.1",
"tsconfig-paths-webpack-plugin": "3.2.0",
"two.js": "0.7.0-stable.1",
Expand Down
121 changes: 100 additions & 21 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,119 @@
// yarn
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import typescript from 'rollup-plugin-typescript'
import nodeResolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import commonjs from '@rollup/plugin-commonjs'
import babel from 'rollup-plugin-babel'
// import json from "@rollup/plugin-json"
import sourceMaps from 'rollup-plugin-sourcemaps'
import { terser } from 'rollup-plugin-terser'
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
import pkg from './package.json'

const common = {
input: 'src/index.ts',
external: ['two.js']
const extensions = ['.js', '.jsx', '.ts', '.tsx', '.json']
const external = id => !id.startsWith('.') && !id.startsWith('/')

const getBabelOptions = ({ useESModules }) => ({
extensions,
babelrc: false,
exclude: '**/node_modules/**',
runtimeHelpers: true,
presets: [
['@babel/preset-env', { loose: true }],
// react
// ['@babel/preset-react', { useBuiltIns: true }],
'@babel/preset-typescript'
],
plugins: [
// react
// ['transform-react-remove-prop-types', { removeImport: true }],
'@babel/plugin-proposal-class-properties',
// TODO: optimize bundle size
// 'babel-plugin-annotate-pure-calls',
['@babel/plugin-transform-runtime', { useESModules }]
]
})
const input = './src/index.ts'
const globals = {
'two.js': 'Two'
}
export default [
// browser-friendly UMD build
/**
* umd
*/
{
...common,
input,
output: {
name: pkg.name,
file: pkg.browser,
format: 'umd',
globals: {
'two.js': 'Two'
}
name: pkg.name,
globals,
exports: 'named',
sourcemap: false
},
external: Object.keys(globals),
plugins: [
resolve(),
nodeResolve({ extensions }),
babel(getBabelOptions({ useESModules: true })),
commonjs(),
typescript(),
terser({ output: { comments: /Copyright/i } })
sourceMaps(),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
terser(),
sizeSnapshot()
]
},

/**
* umd(development)
*/
// {
// input,
// output: {
// file: pkg.browser,
// format: 'umd',
// name: pkg.name,
// globals,
// exports: 'named',
// sourcemap: false
// },
// external: Object.keys(globals),
// plugins: [
// babel(getBabelOptions({ useESModules: true })),
// nodeResolve({ extensions }),
// commonjs(),
// replace({ 'process.env.NODE_ENV': JSON.stringify('development') }),
// terser()
// ]
// },
/**
* cjs
*/
{
...common,
plugins: [typescript()],
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' }
input,
output: {
file: pkg.main,
format: 'cjs',
exports: 'named',
sourcemap: true
},
external,
plugins: [
sourceMaps(),
babel(getBabelOptions({ useESModules: false })),
nodeResolve({ extensions }),
sizeSnapshot()
]
},
/**
* esm
*/
{
input,
output: { file: pkg.module, format: 'esm', sourcemap: true },
external,
plugins: [
sourceMaps(),
babel(getBabelOptions({ useESModules: true })),
nodeResolve({ extensions }),
sizeSnapshot()
]
}
]
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"downlevelIteration": true,
"declaration": true,
"declarationDir": "./lib",
"emitDeclarationOnly": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"noEmitOnError": true,
Expand Down

0 comments on commit 1b7aa42

Please sign in to comment.