1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 13:41:19 +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 isProd = env === 'production'
const isUmd = target === 'umd' const isUmd = target === 'umd'
const isModule = target === 'module' const isModule = target === 'module'
const isCommonJs = target === 'cjs'
const input = `packages/${pkg.name}/src/index.ts` const input = `packages/${pkg.name}/src/index.ts`
const deps = [] const deps = []
.concat(pkg.dependencies ? Object.keys(pkg.dependencies) : []) .concat(pkg.dependencies ? Object.keys(pkg.dependencies) : [])
@@ -103,7 +104,7 @@ function configure(pkg, env, target) {
], ],
modules: false, modules: false,
targets: { targets: {
esmodules: true, esmodules: isModule,
}, },
}, },
], ],
@@ -116,7 +117,7 @@ function configure(pkg, env, target) {
? {} ? {}
: { : {
regenerator: false, regenerator: false,
useESModules: true, useESModules: isModule,
}, },
], ],
'@babel/plugin-proposal-class-properties', '@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) { if (isModule) {
return { return {
plugins, plugins,
@@ -157,13 +180,7 @@ function configure(pkg, env, target) {
file: `packages/${pkg.name}/${pkg.module}`, file: `packages/${pkg.name}/${pkg.module}`,
format: 'es', format: 'es',
sourcemap: true, 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 // 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 // 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 = {}) { function factory(pkg, options = {}) {
const isProd = process.env.NODE_ENV === 'production' const isProd = process.env.NODE_ENV === 'production'
return [ return [
configure(pkg, 'development', 'cjs', options),
configure(pkg, 'development', 'module', options), configure(pkg, 'development', 'module', options),
isProd && configure(pkg, 'development', 'umd', options), isProd && configure(pkg, 'development', 'umd', options),
isProd && configure(pkg, 'production', 'umd', options), isProd && configure(pkg, 'production', 'umd', options),

View File

@@ -8,7 +8,7 @@
"build": "yarn build:rollup && yarn build:next", "build": "yarn build:rollup && yarn build:next",
"build:next": "cd ./site && next build && next export", "build:next": "cd ./site && next build && next export",
"build:rollup": "rollup --config ./config/rollup/rollup.config.js", "build:rollup": "rollup --config ./config/rollup/rollup.config.js",
"clean": "rm -rf ./node_modules ./packages/*/{dist,lib,node_modules} ./site/{.next,out}", "clean": "rimraf ./node_modules ./packages/*/{dist,lib,node_modules} ./site/{.next,out}",
"fix": "yarn fix:prettier && yarn fix:eslint", "fix": "yarn fix:prettier && yarn fix:eslint",
"fix:eslint": "yarn lint:eslint --fix", "fix:eslint": "yarn lint:eslint --fix",
"fix:prettier": "yarn lint:prettier --write", "fix:prettier": "yarn lint:prettier --write",
@@ -69,6 +69,7 @@
"react-error-boundary": "^1.2.5", "react-error-boundary": "^1.2.5",
"react-router-dom": "^5.1.2", "react-router-dom": "^5.1.2",
"react-values": "^0.3.0", "react-values": "^0.3.0",
"rimraf": "^3.0.2",
"rollup": "^1.27.5", "rollup": "^1.27.5",
"rollup-plugin-babel": "^4.3.3", "rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-commonjs": "^10.1.0",

View File

@@ -9629,6 +9629,13 @@ rimraf@2.6.3:
dependencies: dependencies:
glob "^7.1.3" glob "^7.1.3"
rimraf@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
dependencies:
glob "^7.1.3"
ripemd160@^2.0.0, ripemd160@^2.0.1: ripemd160@^2.0.0, ripemd160@^2.0.1:
version "2.0.2" version "2.0.2"
resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c" resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c"