From dce3939a048a2cc4bb17ef94cb800796939b9efd Mon Sep 17 00:00:00 2001 From: donecarlo Date: Sat, 22 Aug 2026 10:17:37 +0800 Subject: [PATCH 1/3] chore: add webpack guides --- guides/webpack.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 guides/webpack.md diff --git a/guides/webpack.md b/guides/webpack.md new file mode 100644 index 0000000..a04df4a --- /dev/null +++ b/guides/webpack.md @@ -0,0 +1,71 @@ +--- +title: Webpack +stack: Bundler +description: Update webpack to output ES Modules +--- + +webpack is one of the early bundlers for the JavaScript ecosystem. Currently, support for ESM-format outputs is still under `experiements` + +## 1. Mark the package as ESM + +Add `type: "module"` to your `package.json`. Every `.js` file in the package is +now treated as an ES module. + +```json +{ + "name": "my-package", + "type": "module" +} +``` + +Any file that genuinely still has to be CommonJS (for example, a legacy config +file for another tool) can keep the `.cjs` extension. + +## 2. Emit a single ESM bundle + +In webpack 5, enable module output and set the library to `module`: + +```js +export default { + mode: 'production', + entry: './src/index.js', + experiments: { + outputModule: true + }, + output: { + filename: 'index.js', + module: true, + library: { + type: 'module' + }, + chunkFormat: 'module' + } +}; +``` + +If you had a separate CommonJS build, remove it and keep just the ESM output. +For config files that must stay CommonJS, rename them to `.cjs` instead of `.js`. + +## 3. Point `exports` at the bundle + +Replace `main` with an `exports` field. This is what lets Node.js and bundlers +resolve your package, and it stops deep imports into your `dist` folder from +becoming part of your public API by accident. + +```json +{ + "exports": { + ".": "./dist/index.js" + }, + "files": ["dist"] +} +``` + +## 4. Check the result + +Run [publint](https://publint.dev) to catch problems with leftover CommonJS +references, publishing config, and other package metadata issues. + +```sh +npx publint +``` \ No newline at end of file From 5f851390cf5fb7692d8600e192ac29377a939001 Mon Sep 17 00:00:00 2001 From: donecarlo Date: Sun, 23 Aug 2026 20:05:10 +0800 Subject: [PATCH 2/3] chore: formatting --- guides/webpack.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/webpack.md b/guides/webpack.md index a04df4a..20bad43 100644 --- a/guides/webpack.md +++ b/guides/webpack.md @@ -68,4 +68,4 @@ references, publishing config, and other package metadata issues. ```sh npx publint -``` \ No newline at end of file +``` From c7ae32c67acc8db1d9fbba8389063c7c484faf22 Mon Sep 17 00:00:00 2001 From: Dan Carlo Canlas Date: Thu, 3 Sep 2026 15:32:51 +0800 Subject: [PATCH 3/3] Update guides/webpack.md Co-authored-by: James Garbutt <43081j@users.noreply.github.com> --- guides/webpack.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/webpack.md b/guides/webpack.md index 20bad43..eeb575b 100644 --- a/guides/webpack.md +++ b/guides/webpack.md @@ -4,7 +4,7 @@ stack: Bundler description: Update webpack to output ES Modules --- -webpack is one of the early bundlers for the JavaScript ecosystem. Currently, support for ESM-format outputs is still under `experiements` +webpack is one of the early bundlers for the JavaScript ecosystem. Currently, support for ESM-format outputs is still under `experiments` ## 1. Mark the package as ESM