The @perfective/build
package provides base configurations
and presets for tools like Gulp, TypeScript, Babel, etc.
to reduce code duplication between projects setup.
-
Check that dev dependencies include correct versions of
gulp
andtypescript
:{ "devDependencies": { "gulp": "^5.0.0", "typescript": "~5.7.2" } }
-
Setup
tsconfig.json
using the basetsconfig.strict.json
configuration.{ "extends": "@perfective/build/tsconfig.strict.json", "compilerOptions": { "rootDir": "./src" }, "exclude": [ "dist" ] }
-
Add the
RequireExtension
andImportExtension
plugins to yourbabel.config.js
.RequireExtension
replaces.js
extensions with the.cjs
extensions inrequire()
statements.ImportExtension
adds the required.mjs
(or.js
) extension to theimport
andexport
statements for ES modules.import { babelPluginImportExtension, babelPluginRequireExtension } from '@perfective/build/babel'; export default { presets: [], plugins: [ babelPluginRequireExtension, babelPluginImportExtension('js'), // (1) ] };
-
Override the default extension (
mjs
).
-
-
Add
prettier
as a dev dependency:{ "devDependencies": { "prettier": "^3.4.2" } }
-
Setup
.prettierrc.js
:import { config } from '@perfective/build/prettier'; export default config;
-
Setup
.prettierignore
:# Build dist # ESLint *.js *.jsx *.ts *.tsx
-
Update
package.json
scripts.{ "scripts": { "lint": "npm run lint:prettier", "lint:prettier": "prettier --write .", "lint:prettier:build": "prettier --check ." } }
Use
lint:prettier
during development (to fix code automatically) andlint:prettier:build
to verify the build (to fail if code is not formatted).
-
Add
jest
and related peer dependencies as dev dependencies:{ "devDependencies": { "@types/jest": "^29.5.14", "jest": "^29.7.0", "ts-jest": "^29.2.5", } }
-
Setup
jest.config.js
:import { config } from '@perfective/build/jest'; export default config;
-
Update
package.json
scripts:{ "scripts": { "test": "jest", "test:build": "jest --clearCache && jest --collectCoverage" } }
Use
test
for development testing andtest:build
to test during the build (and fail if test coverage is not sufficient).