Skip to content

Commit 32ec60f

Browse files
committed
Replaced post-processing "use client" build step with Parcel plug-in
1 parent b5d3d0e commit 32ec60f

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

.parcelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "@parcel/config-default",
3+
"optimizers": {
4+
"*.{js,mjs,cjs}": ["./parcel-optimizer-use-client.js"]
5+
}
6+
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"clear:builds": "rm -rf ./dist",
2222
"clear:parcel-cache": "rm -rf ./.parcel-cache",
2323
"clear:node_modules": "rm -rf ./node_modules",
24-
"prerelease": "rm -rf ./.parcel-cache && parcel build && ./postprocess.js",
24+
"prerelease": "rm -rf ./.parcel-cache && parcel build",
2525
"prettier": "prettier --write \"**/*.{css,html,js,json,jsx,ts,tsx}\"",
2626
"prettier:ci": "prettier --check \"**/*.{css,html,js,json,jsx,ts,tsx}\"",
2727
"test": "jest",
@@ -33,9 +33,13 @@
3333
"@babel/runtime": "^7.12.5"
3434
},
3535
"devDependencies": {
36+
"@parcel/config-default": "^2.9.0",
3637
"@parcel/core": "^2.9.0",
3738
"@parcel/packager-ts": "^2.9.0",
39+
"@parcel/plugin": "^2.9.0",
40+
"@parcel/source-map": "^2.1.1",
3841
"@parcel/transformer-typescript-types": "^2.9.0",
42+
"@parcel/utils": "^2.9.0",
3943
"@types/jest": "^26.0.15",
4044
"@types/react": "^18",
4145
"@types/react-dom": "^18",

parcel-optimizer-use-client.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { Optimizer } = require("@parcel/plugin");
2+
const { default: SourceMap } = require("@parcel/source-map/dist/node.js");
3+
const { blobToBuffer } = require("@parcel/utils");
4+
5+
module.exports = new Optimizer({
6+
async optimize({ contents, map, options }) {
7+
let correctMap;
8+
if (map != null) {
9+
correctMap = new SourceMap(options.projectRoot);
10+
correctMap.addSourceMap(map, 2); // Offset lines by 2
11+
}
12+
return {
13+
contents: `"use client";\n\n` + (await blobToBuffer(contents)).toString(),
14+
map: correctMap,
15+
};
16+
},
17+
});

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

postprocess.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)