ESBuild is a next-gen JavaScript bundler which is about 100x faster than Parcel. In addition, it understands some modern patterns that Parcel doesn't, so it makes sense to switch. You can also use it to compile TypeScript adapters faster.
Follow these steps to do use ESBuild in your adapter:
-
If you've been using Parcel before:
npm uninstall -D @babel/cli @babel/core parcel-bundler
-
If you've been using Parcel before: remove the
.babelrc
file -
Edit
admin/tsconfig.json
:- // Support React - both must be here because parcel v1 does not - // evaluate the "extends" option - "jsx": "react", - "esModuleInterop": true + "jsx": "react" },
-
Install or update
@iobroker/adapter-dev
usingnpm i -D @iobroker/adapter-dev
-
Update package.json scripts:
- If you want to compile TypeScript only (note: you can stick to compiling with
tsc
if you like):You can omit the duplicate scripts which end in- "prebuild": "rimraf ./build", - "build:ts": "tsc -p tsconfig.build.json", - "build": "npm run build:ts", - "watch:ts": "tsc -p tsconfig.build.json --watch", - "watch": "npm run watch:ts", + "prebuild": "rimraf build", + "build": "build-adapter ts", + "watch": "build-adapter ts --watch", + "prebuild:ts": "rimraf build", + "build:ts": "build-adapter ts", + "watch:ts": "build-adapter ts --watch",
:ts
, but leaving them in makes it easier to transition to React later. - If you want to compile React only:
You can omit the duplicate scripts which end in
- "watch:parcel": "parcel admin/src/index.jsx -d admin/build", - "build:parcel": "parcel build admin/src/index.jsx -d admin/build", - "build": "npm run build:parcel", + "prebuild": "rimraf admin/build", + "build": "build-adapter react", + "watch": "build-adapter react --watch", + "prebuild:react": "rimraf admin/build", + "build:react": "build-adapter react", + "watch:react": "build-adapter react --watch",
:react
, but leaving them in makes it easier to add TypeScript compilation later. - If you want to compile both TypeScript and React
- "prebuild": "rimraf ./build", - "build:parcel": "parcel build admin/src/index.tsx -d admin/build", - "build:ts": "tsc -p tsconfig.build.json", - "build": "npm run build:ts && npm run build:parcel", - "watch:parcel": "parcel admin/src/index.tsx -d admin/build", - "watch:ts": "tsc -p tsconfig.build.json --watch", - "watch": "npm run watch:ts", + "prebuild": "rimraf build admin/build", + "build": "build-adapter all", + "watch": "build-adapter all --watch", + "prebuild:ts": "rimraf build", + "build:ts": "build-adapter ts", + "watch:ts": "build-adapter ts --watch", + "prebuild:react": "rimraf admin/build", + "build:react": "build-adapter react", + "watch:react": "build-adapter react --watch",
- If you want to compile TypeScript only (note: you can stick to compiling with