Skip to content

Commit

Permalink
feat: differentiate external for cjs and esm builds
Browse files Browse the repository at this point in the history
  • Loading branch information
robertu7 committed Mar 24, 2023
1 parent dda372e commit c62e5eb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
3 changes: 3 additions & 0 deletions bin/test-cjs-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { normalizeArticleHTML } from '../dist/index.cjs'

console.log(normalizeArticleHTML('<b>Strong</b>'))
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@matters/matters-editor",
"version": "0.2.0-alpha.25",
"version": "0.2.0-alpha.26",
"description": "Editor for matters.news",
"author": "https://github.com/thematters",
"homepage": "https://github.com/thematters/matters-editor",
Expand Down
73 changes: 44 additions & 29 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@ import generatePackageJson from 'rollup-plugin-generate-package-json'

const packageJson = require('./package.json')
const sourcemap = false
const external = [...Object.keys(packageJson.peerDependencies), /@tiptap\/*/]
const cjsExternal = [...Object.keys(packageJson.peerDependencies)]
const esmExternal = [
...Object.keys(packageJson.peerDependencies),
/@tiptap\/.*/,
]
const plugins = [
resolve(),
commonjs(),
typescript({ tsconfig: './tsconfig.json' }),
// terser(),
terser(),
]

const makeGeneratePackageJson = (name) => {
return generatePackageJson({
baseContents: {
name: `${packageJson.name}/${name}`,
private: true,
main: './index.cjs',
module: './index.esm.js',
types: `./types/src/${name}/index.d.ts`,
},
})
}

export default [
// main
{
Expand All @@ -26,14 +42,21 @@ export default [
sourcemap,
name: packageJson.name,
},
],
plugins,
external: cjsExternal,
},
{
input: 'src/index.ts',
output: [
{
file: packageJson.module,
format: 'esm',
sourcemap,
},
],
plugins,
external,
external: esmExternal,
},
// editors
{
Expand All @@ -44,25 +67,21 @@ export default [
format: 'cjs',
sourcemap,
},
],
plugins: [...plugins, makeGeneratePackageJson('editors')],
external: cjsExternal,
},
{
input: 'src/editors/index.ts',
output: [
{
file: 'dist/editors/index.esm.js',
format: 'esm',
sourcemap,
},
],
plugins: [
...plugins,
generatePackageJson({
baseContents: {
name: `${packageJson.name}/editors`,
private: true,
main: './index.cjs',
module: './index.esm.js',
types: './types/src/editors/index.d.ts',
},
}),
],
external,
plugins: [...plugins, makeGeneratePackageJson('editors')],
external: esmExternal,
},
// transformers
{
Expand All @@ -73,25 +92,21 @@ export default [
format: 'cjs',
sourcemap,
},
],
plugins: [...plugins, makeGeneratePackageJson('transformers')],
external: cjsExternal,
},
{
input: 'src/transformers/index.ts',
output: [
{
file: 'dist/transformers/index.esm.js',
format: 'esm',
sourcemap,
},
],
plugins: [
...plugins,
generatePackageJson({
baseContents: {
name: `${packageJson.name}/transformers`,
private: true,
main: './index.cjs',
module: './index.esm.js',
types: './types/src/transformers/index.d.ts',
},
}),
],
external,
plugins: [...plugins, makeGeneratePackageJson('transformers')],
external: esmExternal,
},
// types
{
Expand Down

0 comments on commit c62e5eb

Please sign in to comment.