Skip to content

Commit

Permalink
cleanup of rollup / tsconfig infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
planttheidea committed Sep 29, 2022
1 parent 086f1f5 commit cd6e816
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 103 deletions.
2 changes: 1 addition & 1 deletion benchmark/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const simpleObject = {
const complexObject = Object.assign({}, simpleObject, {
array: ['foo', { bar: 'baz' }],
arrayBuffer: new ArrayBuffer(8),
buffer: new Buffer('this is a test buffer'),
buffer: Buffer.from('this is a test buffer'),
dataView: new DataView(new ArrayBuffer(16)),
date: new Date(),
error: new Error('boom'),
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
roots: ['<rootDir>'],
testRegex: '/__tests__/.*\\.(ts|tsx)$',
transform: {
'\\.(ts|tsx)$': 'ts-jest',
'\\.(ts|tsx)$': ['ts-jest', { tsconfig: 'tsconfig/base.json' }],
},
verbose: true,
};
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@
"url": "git+https://github.com/planttheidea/fast-copy.git"
},
"scripts": {
"benchmark": "npm run build:files && node benchmark/index.cjs",
"build": "npm run build:files && npm run build:types",
"build:files": "NODE_ENV=production rollup -c",
"build:types": "tsc -p ./tsconfig.cjs.json && tsc -p ./tsconfig.esm.json && tsc -p ./tsconfig.umd.json && tsc -p ./tsconfig.minified.json",
"benchmark": "npm run clean && npm run build:cjs && node benchmark/index.cjs",
"build": "npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:min",
"build:cjs": "NODE_ENV=production rollup -c rollup/config.cjs.js && tsc -p ./tsconfig/cjs.json",
"build:esm": "NODE_ENV=production rollup -c rollup/config.esm.js && tsc -p ./tsconfig/esm.json",
"build:min": "NODE_ENV=production rollup -c rollup/config.min.js && tsc -p ./tsconfig/min.json",
"build:umd": "NODE_ENV=production rollup -c rollup/config.umd.js && tsc -p ./tsconfig/umd.json",
"clean": "rimraf dist",
"dev": "NODE_ENV=development webpack-dev-server --config=webpack/webpack.config.js",
"dist": "npm run clean && npm run build",
Expand Down
62 changes: 0 additions & 62 deletions rollup.config.js

This file was deleted.

38 changes: 38 additions & 0 deletions rollup/config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import path from 'path';
import tsc from 'typescript';
import { fileURLToPath } from 'url';
import pkg from '../package.json';

const ROOT = fileURLToPath(new URL('..', import.meta.url));

const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
const globals = external.reduce((globals, name) => {
globals[name] = name;

return globals;
}, {});

export default {
external,
input: 'src/index.ts',
output: {
exports: 'named',
globals,
name: pkg.name,
sourcemap: true,
},
plugins: [
nodeResolve({
mainFields: ['module', 'browser', 'main'],
}),
typescript({
tsconfig: path.resolve(ROOT, 'tsconfig', 'base.json'),
typescript: tsc,
}),
],
};
11 changes: 11 additions & 0 deletions rollup/config.cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import baseConfig from './config.base';
import pkg from '../package.json';

export default {
...baseConfig,
output: {
...baseConfig.output,
file: pkg.main,
format: 'cjs',
},
};
11 changes: 11 additions & 0 deletions rollup/config.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import baseConfig from './config.base';
import pkg from '../package.json';

export default {
...baseConfig,
output: {
...baseConfig.output,
file: pkg.module,
format: 'es',
},
};
13 changes: 13 additions & 0 deletions rollup/config.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import baseConfig from './config.base';
import { terser } from 'rollup-plugin-terser';
import pkg from '../package.json';

export default {
...baseConfig,
output: {
...baseConfig.output,
file: pkg.browser.replace('umd', 'min').replace('.js', '.min.js'),
format: 'umd',
},
plugins: [...baseConfig.plugins, terser()],
};
11 changes: 11 additions & 0 deletions rollup/config.umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import baseConfig from './config.base';
import pkg from '../package.json';

export default {
...baseConfig,
output: {
...baseConfig.output,
file: pkg.browser,
format: 'umd',
},
};
8 changes: 0 additions & 8 deletions tsconfig.cjs.json

This file was deleted.

8 changes: 0 additions & 8 deletions tsconfig.esm.json

This file was deleted.

8 changes: 0 additions & 8 deletions tsconfig.minified.json

This file was deleted.

8 changes: 0 additions & 8 deletions tsconfig.umd.json

This file was deleted.

3 changes: 2 additions & 1 deletion tsconfig.json → tsconfig/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"moduleResolution": "Node",
"noImplicitAny": true,
"outDir": "./dist",
"skipLibCheck": true,
"sourceMap": true,
"inlineSources": true,
"target": "es5",
"types": ["jest", "node", "react"]
},
"exclude": ["node_modules"],
"include": ["src/*", "__tests__/*"]
"include": ["../src/*", "../__tests__/*"]
}
8 changes: 8 additions & 0 deletions tsconfig/cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./declarations.json",
"compilerOptions": {
"declarationDir": "../dist/cjs/types",
"module": "CommonJS",
"outDir": "../dist/cjs"
}
}
4 changes: 2 additions & 2 deletions tsconfig.declarations.json → tsconfig/declarations.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "./tsconfig.json",
"extends": "./base.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["src/*"]
"include": ["../src/*"]
}
8 changes: 8 additions & 0 deletions tsconfig/esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./declarations.json",
"compilerOptions": {
"declarationDir": "../dist/esm/types",
"module": "ESNext",
"outDir": "../dist/esm"
}
}
8 changes: 8 additions & 0 deletions tsconfig/min.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./declarations.json",
"compilerOptions": {
"declarationDir": "../dist/min/types",
"module": "UMD",
"outDir": "../dist/min"
}
}
8 changes: 8 additions & 0 deletions tsconfig/umd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./declarations.json",
"compilerOptions": {
"declarationDir": "../dist/umd/types",
"module": "UMD",
"outDir": "../dist/umd"
}
}
1 change: 1 addition & 0 deletions webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default {
include: [path.resolve(ROOT, 'src'), /DEV_ONLY/],
loader: 'ts-loader',
options: {
configFile: path.resolve(ROOT, 'tsconfig', 'base.json'),
reportFiles: ['src/*.{ts|tsx}'],
},
test: /\.tsx?$/,
Expand Down

0 comments on commit cd6e816

Please sign in to comment.