Skip to content

Commit

Permalink
change bundler for better tree shaking support
Browse files Browse the repository at this point in the history
  • Loading branch information
mdtanrikulu committed Dec 31, 2023
1 parent 353eae0 commit d6b2310
Show file tree
Hide file tree
Showing 5 changed files with 453 additions and 163 deletions.
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
"node": ">=12"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build && ./patch.sh",
"start": "rollup -c --watch",
"build": "rollup -c",
"build:demo": "node ./example/build.js",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build && ./patch.sh",
"size": "size-limit"
},
"husky": {
Expand All @@ -39,7 +38,7 @@
"author": "Muhammed Tanrıkulu <[email protected]>",
"size-limit": [
{
"path": "dist/ens-avatar.cjs.production.min.js",
"path": "dist/index.js",
"limit": "200 KB",
"ignore": [
"jsdom"
Expand All @@ -54,14 +53,16 @@
}
],
"devDependencies": {
"@size-limit/preset-small-lib": "^7.0.5",
"@types/dompurify": "^2.3.3",
"@types/jsdom": "^16.2.14",
"@rollup/plugin-typescript": "^11.1.5",
"@size-limit/preset-small-lib": "^11.0.1",
"@types/dompurify": "^3.0.5",
"@types/jsdom": "^21.1.6",
"@types/url-join": "^4.0.1",
"dotenv": "^16.0.0",
"dotenv": "^16.3.1",
"esbuild": "^0.14.21",
"nock": "^13.2.2",
"size-limit": "^7.0.5",
"rollup": "^4.9.1",
"size-limit": "^11.0.1",
"tsdx": "^0.14.1",
"typescript": "^4.5.5"
},
Expand All @@ -78,6 +79,6 @@
"url-join": "^4.0.1"
},
"volta": {
"node": "16.14.0"
"node": "18.14.0"
}
}
34 changes: 0 additions & 34 deletions patch.sh

This file was deleted.

51 changes: 51 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import fs from 'fs';
import path from 'path';
import tsPlugin from '@rollup/plugin-typescript';

export default {
input: 'src/index.ts',
output: [
{
format: 'cjs',
file: './dist/index.js',
},
{
format: 'es',
dir: 'dist',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: chunk => {
return `${chunk.name === 'index' ? 'index.esm' : chunk.name}.js`;
},
},
],
plugins: [
tsPlugin({
declarationDir: './dist',
sourceMap: false,
}),
removeDist(),
],
};

function removeDist(options = {}) {
const { hook = 'buildStart', buildDir = 'dist' } = options;

return {
name: 'remove-dist',
[hook]: async () => {
const folderPath = path.join(process.cwd(), buildDir);
fs.accessSync(folderPath, fs.F_OK);
try {
fs.rmSync(folderPath, { recursive: true, force: true });
} catch (err) {
if (err.code !== 'ENOENT') throw err;
try {
fs.rmSync(folderPath, { recursive: true, force: true });
} catch (innerErr) {
console.log('An error occurred while removing the folder:', innerErr);
}
}
},
};
}
14 changes: 0 additions & 14 deletions tsdx.config.js

This file was deleted.

Loading

0 comments on commit d6b2310

Please sign in to comment.