1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 10:29:48 +02:00

Bugfix/fix bundles (#3673)

* fix index.js main bundles to be commonjs instead of modules

* Change rm -rf to rimraf to be cross os compatible

* add rimraf as  dependency

Co-authored-by: damareyoh <chackerman@wsu.edu>
This commit is contained in:
Cameron Ackerman
2020-05-11 10:18:00 -07:00
committed by GitHub
parent 08f7ef588c
commit 07c375f82e
3 changed files with 36 additions and 10 deletions

View File

@@ -22,6 +22,7 @@ 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) : [])
@@ -103,7 +104,7 @@ function configure(pkg, env, target) {
],
modules: false,
targets: {
esmodules: true,
esmodules: isModule,
},
},
],
@@ -116,7 +117,7 @@ function configure(pkg, env, target) {
? {}
: {
regenerator: false,
useESModules: true,
useESModules: isModule,
},
],
'@babel/plugin-proposal-class-properties',
@@ -147,6 +148,28 @@ function configure(pkg, env, target) {
}
}
if (isCommonJs) {
return {
plugins,
input,
onwarn,
output: [
{
file: `packages/${pkg.name}/${pkg.main}`,
format: 'cjs',
exports: 'named',
sourcemap: true,
},
],
// We need to explicitly state which modules are external, meaning that
// they are present at runtime. In the case of non-UMD configs, this means
// all non-Slate packages.
external: id => {
return !!deps.find(dep => dep === id || id.startsWith(`${dep}/`))
},
}
}
if (isModule) {
return {
plugins,
@@ -157,13 +180,7 @@ function configure(pkg, env, target) {
file: `packages/${pkg.name}/${pkg.module}`,
format: 'es',
sourcemap: true,
},
{
file: `packages/${pkg.name}/${pkg.main}`,
format: 'cjs',
exports: 'named',
sourcemap: true,
},
}
],
// We need to explicitly state which modules are external, meaning that
// they are present at runtime. In the case of non-UMD configs, this means
@@ -182,6 +199,7 @@ function configure(pkg, env, target) {
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),