A vanilla JS, CSS and HTML project with Web Workers and Custom HTML Elements as first class citizens.
Install dependencies:
npm installTo run the project in development mode:
npm startThis will start a development server. By default, it runs on port 3000. You can view the project in your browser.
To build the project for production:
npm buildThis will create a dist folder with the bundled and optimized files.
You can customize the build output by creating a .env file in the root of the project.
To change the name of the output file, set the OUTPUT_FILE_NAME variable in your .env file.
.env
OUTPUT_FILE_NAME=my-custom-filename.js
If this variable is not set, the output file will default to dist/main.min.js.
You can also change the development server port by setting the PORT variable in your .env file.
.env
PORT=8080
If this variable is not set, the port will default to 3000.
You can control whether CSS is bundled into the JavaScript file or output as a separate file by setting the SEPARATE_CSS variable in your .env file.
.env
SEPARATE_CSS=true
true: CSS is extracted to a separate file (e.g.,main.css).false(default): CSS is injected into the DOM via JavaScript (usingstyle-loader).
src/- Your JavaScript source filesstyles/- CSS filesscripts/- Build scripts (including Web Worker transformation)index.html- Main HTML fileindex.js- Main JavaScript entry pointindex.css- Main CSS filerspack.config.js- Rspack configuration
The project uses Rspack with the following features configured:
-
CSS Processing Pipeline
style-loader- Injects CSS into the DOMcss-loader- Resolves CSS imports and URLspostcss-loaderwith cssnano - Minifies and optimizes CSS- Source maps enabled in development mode
- Automatic comment removal in production builds
-
JavaScript Processing
builtin:swc-loader- Fast JavaScript transpilation- Custom
transform-workers.jsloader - Transforms web worker imports - Dynamic imports forced to eager mode for web worker compatibility
- Source maps enabled in development mode
The build system includes special handling for web workers:
- Custom loader (
scripts/transform-workers.js) transforms worker imports - Dynamic imports are eagerly evaluated for worker compatibility
- Workers are properly bundled and can be imported in your code
The assets/ folder receives special treatment:
- Development Server: Assets are served from the root path (
/) if the directory exists and contains files - Production Build: Assets are copied to the dist root (not in a subdirectory) via
CopyRspackPlugin - Conditional Loading: Assets are only processed if the directory exists and has files
Place any static files (images, fonts, etc.) in the assets/ directory and they will be accessible from the root path in both dev and production.
splitChunks: false- Bundles everything into a single fileruntimeChunk: false- No separate runtime chunkclean: true- Automatically cleans the dist directory before each build
- Serves static files from project root
- Conditionally serves assets directory
- Gzip compression enabled
- Cache-Control headers set to
no-storefor development - Configurable port via environment variable
.envfile support via dotenvOUTPUT_FILE_NAME- Customize output filename (default:main.min.js)PORT- Configure dev server port (default:3000)SEPARATE_CSS- Control CSS extraction (default:false)NODE_ENV- Set toproductionfor production builds
- Rspack - Fast bundler for development and production
- dataroom-js - Custom HTML elements framework
- Web Workers - For parallel processing
- PostCSS - CSS processing with cssnano optimization
- SWC - Fast JavaScript/TypeScript compiler
This project is configured for publishing to npm. Follow these steps to publish:
-
Update package metadata in
package.json:- Set the package
name(must be unique on npm) - Update
authorwith your name and email - Update
repository,bugs, andhomepageURLs with your actual repository - Set the initial
version(recommend starting with0.1.0)
- Set the package
-
Verify the package contents:
npm pack --dry-run
This shows what files will be included in the package.
-
Test the build:
npm run build
Ensure the
dist/directory is created successfully.
-
Login to npm (first time only):
npm login
-
Publish the package:
npm publish
The
prepublishOnlyscript will automatically run the build before publishing.
-
Update the version using npm's version command:
npm version patch # For bug fixes (1.0.0 -> 1.0.1) npm version minor # For new features (1.0.0 -> 1.1.0) npm version major # For breaking changes (1.0.0 -> 2.0.0)
-
Publish the update:
npm publish
The package includes:
dist/- Built production filessrc/- Source JavaScript filesstyles/- CSS filesindex.js,index.css,index.html- Entry filespackage.jsonand related metadata
Development files (rspack config, build scripts, tests, etc.) are excluded via .npmignore.