Skip to content

Commit

Permalink
Attempts using multiple tsconfigs (not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
KikoCosmetics committed May 31, 2024
1 parent e1edd0a commit 776b0e9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
45 changes: 4 additions & 41 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import typescript from "@rollup/plugin-typescript";
import cleaner from "rollup-plugin-cleaner";
import terser from "@rollup/plugin-terser";
import pluginReplace from "@rollup/plugin-replace";
import { copyFile } from "fs/promises";
import { join, dirname, basename } from 'path';
import { glob } from 'glob';

const pkg = require("./package.json");

Expand All @@ -28,14 +25,14 @@ export default {
"./dist/"
]
}),
// Compile TypeScript files
// Compile TypeScript for CommonJS
typescript({
// tsconfig: "tsconfig.json"
}),
// Compile Typescript for ESNEXT
// typescript({tsconfig: "tsconfig.esnext.json"}),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Enable Terser
terser(),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
Expand All @@ -45,40 +42,6 @@ export default {
values: {
__BUILD_VRS__: () => pkg.version
}
}),
// copyAndRename("dist/index.d.ts", "dist/index.d.mts"),
copyAndRename('dist/**/*.d.ts', filename => filename.replace('.d.ts', '.d.mts'))
})
]
};
/*
function copyAndRename(src, dest) {
return {
name: "copy-and-rename",
writeBundle() {
copyFile(src, dest)
.catch((err) => {
console.error("copyAndRename: error copying file!", err);
});
}
};
}
*/

function copyAndRename(pattern, renameFn) {
return {
name: 'copy-and-rename',
async writeBundle() {
try {
const files = await glob(pattern);
await Promise.all(files.map(async (file) => {
console.info("WORKING ON FILE", file);
const filePath = dirname(file);
const dest = join(filePath, renameFn(basename(file)));
await copyFile(file, dest);
}));
} catch (copyError) {
console.error('Error copying files:', copyError);
}
}
};
}
31 changes: 31 additions & 0 deletions tsconfig.esnext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"module": "ESNext",
"target": "esnext",
"lib": [
"esnext"
],
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./src",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"strictNullChecks": false,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"ts-luxon": [
"./dist"
],
"ts-luxon/*": [
"./dist/*"
]
},
"esModuleInterop": true,
"outDir": "dist/esnext"
}
}
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"test"
],
"compilerOptions": {
"module": "es6",
"target": "es6",
"module": "CommonJS",
"target": "es5",
"lib": [
"es5"
],
Expand All @@ -31,6 +31,6 @@
]
},
"esModuleInterop": true,
"outDir": "dist"
"outDir": "dist/commonjs"
}
}

0 comments on commit 776b0e9

Please sign in to comment.