const configs = {
esm: {
- file: resolve(`dist/${name}.esm.js`),
+ file: resolve(`dist/${name}.esm-bundler.js`),
format: `es`
},
cjs: {
file: resolve(`dist/${name}.cjs.js`),
format: `cjs`
},
- umd: {
- file: resolve(`dist/${name}.umd.js`),
- format: `umd`
+ global: {
+ file: resolve(`dist/${name}.global.js`),
+ format: `iife`
},
'esm-browser': {
file: resolve(`dist/${name}.esm-browser.js`),
const defaultFormats = ['esm', 'cjs']
const inlineFromats = process.env.FORMATS && process.env.FORMATS.split(',')
const packageFormats = inlineFromats || packageOptions.formats || defaultFormats
-const packageConfigs = packageFormats.map(format => createConfig(configs[format]))
+const packageConfigs = packageFormats.map(format =>
+ createConfig(configs[format])
+)
if (process.env.NODE_ENV === 'production') {
packageFormats.forEach(format => {
if (format === 'cjs') {
packageConfigs.push(createProductionConfig(format))
}
- if (format === 'umd' || format === 'esm-browser') {
+ if (format === 'global' || format === 'esm-browser') {
packageConfigs.push(createMinifiedConfig(format))
}
})
function createConfig(output, plugins = []) {
const isProductionBuild = /\.prod\.js$/.test(output.file)
- const isUMDBuild = /\.umd(\.prod)?\.js$/.test(output.file)
+ const isGlobalBuild = /\.global(\.prod)?\.js$/.test(output.file)
const isBunlderESMBuild = /\.esm\.js$/.test(output.file)
const isBrowserESMBuild = /esm-browser(\.prod)?\.js$/.test(output.file)
- if (isUMDBuild) {
+ if (isGlobalBuild) {
output.name = packageOptions.name
}
return {
input: resolve(`src/index.ts`),
- // UMD and Browser ESM builds inlines everything so that they can be
+ // Global and Browser ESM builds inlines everything so that they can be
// used alone.
- external: isUMDBuild || isBrowserESMBuild
- ? []
- : Object.keys(aliasOptions),
+ external:
+ isGlobalBuild || isBrowserESMBuild ? [] : Object.keys(aliasOptions),
plugins: [
tsPlugin,
aliasPlugin,
function createReplacePlugin(isProduction, isBunlderESMBuild) {
return replace({
__DEV__: isBunlderESMBuild
- // preserve to be handled by bundlers
- ? `process.env.NODE_ENV !== 'production'`
- // hard coded dev/prod builds
- : !isProduction,
+ ? // preserve to be handled by bundlers
+ `process.env.NODE_ENV !== 'production'`
+ : // hard coded dev/prod builds
+ !isProduction,
// compatibility builds
__COMPAT__: !!process.env.COMPAT
})
function createProductionConfig(format) {
return createConfig({
file: resolve(`dist/${name}.${format}.prod.js`),
- format: /^esm/.test(format) ? 'es' : format
+ format: configs[format].format
})
}
function createMinifiedConfig(format) {
const { terser } = require('rollup-plugin-terser')
- const isESM = /^esm/.test(format)
return createConfig(
{
file: resolve(`dist/${name}.${format}.prod.js`),
- format: isESM ? 'es' : format
+ format: configs[format].format
},
[
terser({
- module: isESM
+ module: /^esm/.test(format)
})
]
)
Run Rollup in watch mode for development.
To specific the package to watch, simply pass its name and the desired build
-formats to watch (defaults to "umd"):
+formats to watch (defaults to "global"):
```
# name supports fuzzy match. will watch all packages with name containing "dom"
execa(
'rollup',
- ['-wc', '--environment', `TARGET:${target},FORMATS:${formats || 'umd'}`],
+ ['-wc', '--environment', `TARGET:${target},FORMATS:${formats || 'global'}`],
{
stdio: 'inherit'
}