-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters