|
|
import babel from 'rollup-plugin-babel' |
|
|
import builtins from 'rollup-plugin-node-builtins' |
|
|
import commonjs from 'rollup-plugin-commonjs' |
|
|
import globals from 'rollup-plugin-node-globals' |
|
|
import json from 'rollup-plugin-json' |
|
|
import replace from 'rollup-plugin-replace' |
|
|
import resolve from 'rollup-plugin-node-resolve' |
|
|
import typescript from 'rollup-plugin-typescript2' |
|
|
import { terser } from 'rollup-plugin-terser' |
|
|
import { startCase } from 'lodash' |
|
|
|
|
|
import Core from '../../packages/slate/package.json' |
|
|
import History from '../../packages/slate-history/package.json' |
|
|
import Hyperscript from '../../packages/slate-hyperscript/package.json' |
|
|
import DOM from '../../packages/slate-dom/package.json' |
|
|
import React from '../../packages/slate-react/package.json' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function configure(pkg, env, target) { |
|
|
const isProd = env === 'production' |
|
|
const isUmd = target === 'umd' |
|
|
const isModule = target === 'module' |
|
|
const isCommonJs = target === 'cjs' |
|
|
const input = `packages/${pkg.name}/src/index.ts` |
|
|
const deps = [] |
|
|
.concat(pkg.dependencies ? Object.keys(pkg.dependencies) : []) |
|
|
.concat(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []) |
|
|
|
|
|
|
|
|
const onwarn = warning => { |
|
|
if (warning.code !== 'CIRCULAR_DEPENDENCY') { |
|
|
console.warn(`(!) ${warning.message}`) |
|
|
} |
|
|
} |
|
|
|
|
|
const plugins = [ |
|
|
|
|
|
|
|
|
resolve({ |
|
|
browser: true, |
|
|
}), |
|
|
|
|
|
typescript({ |
|
|
abortOnError: false, |
|
|
tsconfig: `./packages/${pkg.name}/tsconfig.json`, |
|
|
|
|
|
|
|
|
clean: true, |
|
|
}), |
|
|
|
|
|
|
|
|
|
|
|
commonjs({ |
|
|
exclude: [`packages/${pkg.name}/src/**`], |
|
|
|
|
|
|
|
|
|
|
|
namedExports: { |
|
|
'react-dom': ['findDOMNode'], |
|
|
'react-dom/server': ['renderToStaticMarkup'], |
|
|
}, |
|
|
}), |
|
|
|
|
|
|
|
|
json(), |
|
|
|
|
|
|
|
|
|
|
|
replace({ |
|
|
'process.env.NODE_ENV': JSON.stringify(env), |
|
|
}), |
|
|
|
|
|
|
|
|
builtins(), |
|
|
|
|
|
|
|
|
babel({ |
|
|
runtimeHelpers: true, |
|
|
include: [`packages/${pkg.name}/src/**`], |
|
|
extensions: ['.js', '.ts', '.tsx'], |
|
|
presets: [ |
|
|
'@babel/preset-typescript', |
|
|
[ |
|
|
'@babel/preset-env', |
|
|
isUmd |
|
|
? { modules: false } |
|
|
: { |
|
|
exclude: [ |
|
|
'@babel/plugin-transform-regenerator', |
|
|
'@babel/transform-async-to-generator', |
|
|
], |
|
|
modules: false, |
|
|
targets: { |
|
|
esmodules: isModule, |
|
|
}, |
|
|
}, |
|
|
], |
|
|
'@babel/preset-react', |
|
|
], |
|
|
plugins: [ |
|
|
[ |
|
|
'@babel/plugin-transform-runtime', |
|
|
isUmd |
|
|
? {} |
|
|
: { |
|
|
regenerator: false, |
|
|
useESModules: isModule, |
|
|
}, |
|
|
], |
|
|
'@babel/plugin-proposal-class-properties', |
|
|
], |
|
|
}), |
|
|
|
|
|
|
|
|
globals(), |
|
|
|
|
|
|
|
|
|
|
|
isUmd && isProd && terser(), |
|
|
].filter(Boolean) |
|
|
|
|
|
if (isUmd) { |
|
|
return { |
|
|
plugins, |
|
|
input, |
|
|
onwarn, |
|
|
output: { |
|
|
format: 'umd', |
|
|
file: `packages/${pkg.name}/${isProd ? pkg.umdMin : pkg.umd}`, |
|
|
exports: 'named', |
|
|
name: startCase(pkg.name).replace(/ /g, ''), |
|
|
globals: pkg.umdGlobals, |
|
|
}, |
|
|
external: Object.keys(pkg.umdGlobals || {}), |
|
|
} |
|
|
} |
|
|
|
|
|
if (isCommonJs) { |
|
|
return { |
|
|
plugins, |
|
|
input, |
|
|
onwarn, |
|
|
output: [ |
|
|
{ |
|
|
file: `packages/${pkg.name}/${pkg.main}`, |
|
|
format: 'cjs', |
|
|
exports: 'named', |
|
|
sourcemap: true, |
|
|
}, |
|
|
], |
|
|
|
|
|
|
|
|
|
|
|
external: id => { |
|
|
return !!deps.find(dep => dep === id || id.startsWith(`${dep}/`)) |
|
|
}, |
|
|
} |
|
|
} |
|
|
|
|
|
if (isModule) { |
|
|
return { |
|
|
plugins, |
|
|
input, |
|
|
onwarn, |
|
|
output: [ |
|
|
{ |
|
|
file: `packages/${pkg.name}/${pkg.module}`, |
|
|
format: 'es', |
|
|
sourcemap: true, |
|
|
}, |
|
|
], |
|
|
|
|
|
|
|
|
|
|
|
external: id => { |
|
|
return !!deps.find(dep => dep === id || id.startsWith(`${dep}/`)) |
|
|
}, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function factory(pkg, options = {}) { |
|
|
const isProd = process.env.NODE_ENV === 'production' |
|
|
return [ |
|
|
configure(pkg, 'development', 'cjs', options), |
|
|
configure(pkg, 'development', 'module', options), |
|
|
isProd && configure(pkg, 'development', 'umd', options), |
|
|
isProd && configure(pkg, 'production', 'umd', options), |
|
|
].filter(Boolean) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default [ |
|
|
...factory(Core), |
|
|
...factory(History), |
|
|
...factory(Hyperscript), |
|
|
...factory(DOM), |
|
|
...factory(React), |
|
|
] |
|
|
|