Built with: Node.js v24.0.2
Supported Node.js versions: Node.js v20.x, v22.x, v24.x and v25.x - Monitored by central Blocks CI from @build-in-blocks/dev.setup
Overview: Production and development bundler build setup for your typescript web-related projects.
Description: Build production-ready typescript web apps (or web-based libraries) without your regular javascript/typescript web frameworks, with ease and speed. The @build-in-blocks/dev.build package contains preconfigured webpack setup for both development and production environment. After installation in your web project (and with very minimal intervention on your end), you just need to run npm run dev to generate a development mode bundle or npm run build to generate a well optimized production mode bundle.
User guide: See docs.users README.md
Contributor guide: See docs.contributors README.md
Run into any issues? Report them via our product issue reports repo
Note
Also see user guide 👆🏽 for more detailed guide on what's included in this package (out of the box) and customization.
-
Install our dev build package as a
devDependencyin your project:npm install -D @build-in-blocks/dev.build --save-exact -
Also make sure to install the resources package, as this will be useful later (also so that your web app code can compile successfully without errors):
npm install -D @build-in-blocks/dev.resources --save-exact
-
You DON'T need to install
typescriptinto your web project (this library already does that internally, relative to your web project). Seetypescripttable in the general guide for more information: Typescript compatibility and usage. -
Just create a
tsconfig.jsonfile at the root of your web project, and add these:{ "extends": "@build-in-blocks/dev.build/tsconfig.base.json", "compilerOptions": { "declarationDir": "./build", "rootDir": "./src", "checkJs": false, "skipLibCheck": true, }, "include": ["src"], }
-
Add dev and build scripts: In your web project's
package.jsonfile, add thedevandbuildscripts.-
For
macOSandlinux, use:"scripts": { "dev": "blocks.pkg.dev.build dev:build", "build": "blocks.pkg.dev.build prod:build" // your other npm scripts in your project goes here as usual }, -
For
windows OS, use:"scripts": { "dev": "blocks.pkg.dev.build.cmd dev:build", "build": "blocks.pkg.dev.build.cmd prod:build" // your other npm scripts in your project goes here as usual },
-
-
You need this too: Add these in the your web project's
package.jsonfile too:{ "type": "module", "sideEffects": false, // your other package.json property values go here as usual }[!NOTE]
You need"type": "module"since this library package is ESM-first.sideEffectshelps with treeshaking.
-
Option 1 - Default webpack entry file path: If you create or use a
src/index.tsfile in your web project, the library will assume that you don't wish to change yourwebpackentry file path and want to stick to the default. -
option 2 - Override the default with your preferred entry file path: If you prefer e.g.
app/main.tsto be your project'swebpackentry file path, create ablocks.config.tsfile at the root of your web project and add this code in there:import { BlocksConfig } from '@build-in-blocks/dev.resources'; const blocksConfig: BlocksConfig = { devBuild: { srcCodeFolder: 'app', entryFileName: 'main', }, }; export default blocksConfig;[!NOTE]
You'll also need to update your web project'stsconfig.jsonfile'sincludearray androotDiri.e. change"src"to"app".
If you plan to run your web project in the browser, add a main index.html file at the root of your source code folder i.e. it's file path should be src/index.html if you are using default, or e.g. app/index.html if you've used blocks config to override the default.
Note
This will automatically include the main index.html file in the generated dist and build folders. Your entry point file is also injected in the generated index.html's body tag.
-
Local development build:
Webpackwill now watch your source code folder as you make changes to its content, and will also generate/update thedistoutput folder, when you run thedevscript command:npm run dev -
Production build: Run the
buildscript command, anytime you need to generate/update your production build i.e. thebuildoutput folder:npm run build
Thanks to these amazing contributors to the @build-in-blocks/dev.build project. This project follows the all-contributors specification. See emoji key. Contributions of any kind welcome!
Mary @Ifycode 💻 📖 |
allcontributors[bot] 🔧 📖 |