Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build System: added rollup to produce es2015 & es5 imports, flattened types file #199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
coverage
typings
29 changes: 22 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
{
"version": "1.9.1",
"version": "2.0.0",
"license": "MIT",
"main": "dist/index.js",
"main": "dist/index.cjs",
"typings": "dist/index.d.ts",
"module": "dist/esm/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"default": "./dist/index.js"
},
"./es2015": {
"types": "./dist/es2015/index.d.ts",
"require": "./dist/es2015/index.cjs",
"import": "./dist/es2015/index.mjs",
"default": "./dist/es2015/index.js"
}
},
"files": [
"dist",
"src"
Expand All @@ -12,9 +26,7 @@
"node": ">=10"
},
"scripts": {
"build": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc",
"build:esm": "tsc --module es2015 --outDir dist/esm",
"build": "tsc --project tsconfig.d.json && NODE_ENV=production rollup -c rollup.config.js",
"test": "tsdx test --notify --verbose",
"lint": "tsdx lint",
"prepack": "yarn build",
Expand Down Expand Up @@ -65,7 +77,10 @@
"mongodb": "^3.6.6",
"publish-please": "^5.5.2",
"tsdx": "^0.14.1",
"typescript": "^4.2.4"
"typescript": "^4.2.4",
"rollup": "^2.79.0",
"rollup-plugin-typescript2": "^0.33.0",
"rollup-plugin-dts": "^4.2.2"
},
"dependencies": {
"copy-anything": "^3.0.2"
Expand Down
105 changes: 105 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
'use strict';

var path = require('path');
var tsc = require('rollup-plugin-typescript2');
var dts = require('rollup-plugin-dts').default;
var rollup = require('rollup');

var cwd = path.join(__dirname);
var shared = {
external: /^copy-anything$/,
input: {
index: path.join(__dirname, 'src', 'index.ts')
},
plugins: [
tsc({
cwd: cwd,
tsconfig: path.join(cwd, 'tsconfig.json'),
check: true,
clean: true
})
]
};
var outDir = path.join(__dirname, 'dist');
var outDirES2015 = path.join(__dirname, 'dist', 'es2015');

var es5Settings = Object.assign({}, shared, {
output: [
{
dir: outDir,
format: 'esm',
entryFileNames: '[name].mjs',
chunkFileNames: '[name].mjs',
hoistTransitiveImports: false,
sourcemap: true
},
{
dir: outDir,
format: 'cjs',
entryFileNames: '[name].cjs',
chunkFileNames: '[name].cjs',
hoistTransitiveImports: false,
sourcemap: true,
exports: 'auto'
},
{
dir: outDir,
format: 'esm',
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
hoistTransitiveImports: false,
sourcemap: true
}
]
});

var es2015Settings = Object.assign({}, shared, {
plugins: [
tsc({
cwd: cwd,
tsconfig: path.join(cwd, 'tsconfig.es2015.json'),
check: true,
clean: true,
})
],
output: es5Settings.output.map(function mapper(conf) {
var shallow = Object.assign({}, conf);
shallow.dir = outDirES2015;
return shallow;
})
})

module.exports = rollup.defineConfig([
es5Settings,
es2015Settings,
{
input: {
index: path.join(cwd, 'typings', 'index.d.ts')
},
plugins: [
dts({
compilerOptions: {
module: 99,
moduleResolution: 99,
esModuleInterop: true,
allowSyntheticDefaultImports: true,
lib: ['dom', 'esnext']
}
})
],
output: [
{
dir: outDir,
format: 'esm',
entryFileNames: '[name].d.ts',
chunkFileNames: '[name].d.ts'
},
{
dir: outDirES2015,
format: 'esm',
entryFileNames: '[name].d.ts',
chunkFileNames: '[name].d.ts'
},
]
}
]);
22 changes: 22 additions & 0 deletions tsconfig.d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"include": ["src"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"],
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"lib": ["esnext"],
"importHelpers": false,
"declaration": true,
"sourceMap": true,
"emitDeclarationOnly": true,
"declarationDir": "./typings",
"moduleResolution": "node",
"strict": true,
"noUnusedLocals": true,
"forceConsistentCasingInFileNames": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true
}
}
21 changes: 21 additions & 0 deletions tsconfig.es2015.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"include": ["src"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"],
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"target": "ES2015",
"module": "ESNext",
"lib": ["esnext"],
"importHelpers": false,
"declaration": false,
"sourceMap": true,
"rootDir": "./src",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"esModuleInterop": true
}
}
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"include": ["src"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"],
"compilerOptions": {
"module": "CommonJS",
"target": "ES5",
"module": "ESNext",
"lib": ["esnext"],
"importHelpers": false,
"declaration": true,
"declaration": false,
"sourceMap": true,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down
Loading