Skip to content

Commit

Permalink
- Now for cjs and esm modules bundled differently;
Browse files Browse the repository at this point in the history
- ESM version now has ESNext lang level;
- CJS version now has ES3 lang level;
  • Loading branch information
xobotyi committed Jun 28, 2019
1 parent 6369f45 commit 600328d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 49 deletions.
111 changes: 63 additions & 48 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,70 @@ import babel from "rollup-plugin-babel";
import ts from "rollup-plugin-typescript2";
import pkg from "./package.json";

export default {
input: "./src/index.ts",
const ownKeys = Object.getOwnPropertyNames;
const externalDependencies = Array.from(new Set(ownKeys(pkg.peerDependencies).concat(ownKeys(pkg.dependencies))));

output: [
{
dir: "dist/cjs",
extend: true,
format: "cjs",
exports: "named"
},
{
dir: "dist/esm",
extend: true,
format: "esm",
exports: "named"
}
],

external: ["react", "prop-types", "cnbuilder", "react-draggable", "zoom-level", "is-number", "is-fun"],

plugins: [
ts({
clean: true,
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
module: "esnext",
target: "esnext",
declaration: true,
declarationDir: "dist/types"
}
export default [
{
input: "./src/index.ts",
output: [
{
file: pkg.main,
format: "cjs",
exports: "named"
}
}),
babel({
babelrc: false,
exclude: "node_modules/**",
extensions: [".ts", ".tsx", ".js", ".jsx"],
presets: [
[
"@babel/preset-env",
{
targets: {
esmodules: false,
chrome: "52",
ie: "10"
}
],
external: externalDependencies,
plugins: [
ts({
clean: true,
tsconfigOverride: {
compilerOptions: {
module: "esnext",
target: "es5",
declaration: false
}
}
}),
babel({
babelrc: false,
exclude: "node_modules/**",
extensions: [".ts", ".tsx", ".js", ".jsx"],
presets: [
[
"@babel/preset-env",
{
targets: {
ie: "9"
}
}
]
]
]
})
]
};
})
]
},
{
input: "./src/index.ts",
output: [
{
file: pkg.module,
format: "esm"
}
],
external: externalDependencies,
plugins: [
ts({
clean: true,
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
module: "esnext",
target: "esnext",
declaration: true,
declarationDir: __dirname + "/dist/types"
}
}
})
]
}
];
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"noImplicitReturns": true,
"strictNullChecks": true,
"alwaysStrict": true,
"declaration": true,
"declaration": false,
"target": "esnext",
"module": "commonjs",
"jsx": "react",
Expand Down

0 comments on commit 600328d

Please sign in to comment.