Project Status
Use case
One development tool for web and Node.js projects instead of a hand-written webpack, Babel, TypeScript, Jest, ESLint and PostCSS setup. weboptimizer brings working defaults for all of them: it builds libraries and web applications from TypeScript, JavaScript, CSS and EJS templates, runs a development server, tests, type checks, linting and documentation. Everything you want to change is configured in your "package.json".
Content
Quick start
A TypeScript library with tests:
npm install --save-dev weboptimizer core-js jest @types/webpack-env
{
"name": "greeter",
"type": "module",
"main": "dist/index.js",
"files": ["dist"],
"scripts": {
"build": "weboptimizer build",
"check:types": "weboptimizer check:types",
"clear": "weboptimizer clear",
"test": "weboptimizer test",
"watch": "weboptimizer build --watch"
},
"webOptimizer": {
"path": {
"source": {"base": "src/"},
"target": {"base": "dist/"}
}
}
}
// src/index.ts
export const greet = (name: string): string => `Hello ${name}!`
export default greet
// src/test.ts
import {expect, test} from '@jest/globals'
import greet from './index'
test('greet', (): void => {
expect(greet('World')).toStrictEqual('Hello World!')
})
"npm run build" writes "dist/index.js", "npm test" builds the tests and runs them with Jest.
Libraries and applications
weboptimizer distinguishes two kinds of projects. Many defaults depend on it:
- Library (default): Every source file is compiled on its own, imported packages stay external. Without a "path" configuration the output is placed next to the sources, therefore the quick start sets "src/" and "dist/".
- Application ("library": false): Everything including dependencies is bundled from "src/" into "dist/" together with an "index.html". Stylesheets belong into "src/cascadingStyleSheet/", images into "src/image/" and fonts into "src/font/". An own "src/index.html.ejs" replaces the default page.
{
"scripts": {
"build": "weboptimizer build",
"serve": "weboptimizer serve"
},
"webOptimizer": {
"library": false
}
}
Commands
- "build": Builds the project. Further arguments go to webpack, e.g. "weboptimizer build --watch" rebuilds on every change.
- "serve": Starts a development server on port 8080 which reloads the page on changes.
- "test": Builds all files named "test" and runs them with Jest in Node.js. For a simulated browser set "commandLine.test.environments" to ["jsdom"]. "test:coverage" adds a coverage report.
- "test:browser": Serves the tests to run them in a real browser.
- "check:types" and "build:types": Checks the TypeScript types or writes declaration files.
- "lint": Checks scripts with ESLint and stylesheets with Stylelint.
- "document": Generates API documentation with JSDoc.
- "clear": Removes all build output.
Optional features
Features beyond building scripts need additional packages:
- Stylesheets: "css-loader", "style-loader", "mini-css-extract-plugin", "postcss-loader", "postcss-import", "postcss-preset-env", "postcss-url", "postcss-fontpath" and "cssnano".
- Development server: "webpack-dev-server".
- Linting: "eslint", "@eslint/js", "eslint-config-google", "eslint-plugin-jsdoc", "typescript-eslint", "@stylistic/eslint-plugin" and "globals", for stylesheets "stylelint" and "stylelint-config-standard".
- Favicons from "src/image/favicon.png": "favicons-webpack-plugin".
- Image compression: "imagemin" plus "imagemin-gifsicle", "imagemin-jpegtran", "imagemin-optipng" and "imagemin-svgo" (disabled by default, enable it by setting "module.optimizer.image.content.exclude" to "null").
- Offline support via service worker: "workbox-webpack-plugin".
- API documentation: "jsdoc".
Configuration
All settings live under the key "webOptimizer" in your "package.json" and are merged into the defaults, which you find under "configuration" in weboptimizer's own "package.json". Keys like "#" or "#1" are comments:
{
"webOptimizer": {
"#": "Serve on another port.",
"development": {
"server": {"port": 9000}
},
"generic": {
"supportedBrowsers": ["last 2 versions", "> 1%"]
}
}
}
The sections "debug", "document", "test" and "test:browser" are merged in only for the corresponding command or for debug mode. Debug mode leaves stylesheets and HTML unminified and is enabled via "debug": true (also on the command line) or the environment variable "NODE_ENV=development".
Computed values
Values can be JavaScript expressions with "evaluate" or function bodies with "execute". "self" is the whole configuration, further available are e.g. "currentPath", "path", "fs", "webOptimizerPath" and the helpers of clientnode like "string" or "array". Computed locations in "path" are made absolute like plain ones:
{
"webOptimizer": {
"libraryName": {"__evaluate__": "`${self.name}-library`"},
"path": {
"target": {
"base": {"__evaluate__": "self.debug ? 'build/' : 'dist/'"}
}
}
}
}
Command line
The last argument of a command can be a JavaScript object which overrides the configuration. "reference" merges in named sections of your configuration (or JSON files), which is handy for build variants:
{
"scripts": {
"build:bundle": "weboptimizer build '{__reference__: \"target:bundle\"}'"
},
"webOptimizer": {
"target:bundle": {
"inPlace": {"externalLibrary": {"normal": true}},
"path": {"target": {"base": "dist/bundle/"}}
}
}
}
npx weboptimizer serve '{development: {server: {port: 9000}}}'
If your toolchain can not pass such characters, encode the object as base64:
npx weboptimizer build \
"$(printf '%s' "{path: {target: {base: 'out/'}}}" | base64)"
Editor integration
Point your editor's ESLint integration to the project's "eslint" package and to the configuration "node_modules/weboptimizer/dist/eslint.config.js". TypeScript configurations can extend "weboptimizer/tsconfig.json".
Development
yarn install
yarn build
yarn test
About this website
Provider ofhttps://tsickert.com/weboptimizer:
Torben Sickert
Waldstraße 29
79194 Gundelfingen i.Br.
Phone: +49 (0) 176 / 10 248 185
Email: [email protected]
Website: https://tsickert.com
Disclaimer
Liability for content
The content of our pages has been prepared with the utmost care. However, we cannot guarantee the accuracy, completeness or timeliness of the content. As a service provider, we are responsible for our own content on these pages under general law. However, we are not obliged to monitor transmitted or stored third-party information or investigate circumstances that indicate illegal activity. Obligations to remove or block the use of information under general law remain unaffected. Liability in this respect is only possible from the time we become aware of a specific infringement. Upon becoming aware of any such legal violations, we will remove this content immediately.
Liability for links
Our website contains links to external third-party websites whose content is beyond our control. We therefore cannot accept any responsibility for such third-party content. The respective provider or operator of each linked site is always responsible for its content. The linked sites were checked for possible legal violations when the links were created. No illegal content was apparent at that time. However, continuous monitoring of linked sites is not reasonable without specific evidence of a legal violation. If we become aware of any legal violations, we will remove the relevant links immediately.
Copyright
Content and works on these pages created by the site operators are subject to German copyright law. Reproduction, adaptation, distribution and any use beyond the scope of copyright law require the written consent of the respective author or creator. Downloads and copies of this site are permitted for private, non-commercial use only. Where content on this site was not created by the operator, third-party copyrights are respected. In particular, third-party content is identified as such. If you become aware of a copyright infringement, please notify us. Upon becoming aware of any legal violations, we will remove the relevant content immediately.
Privacy Policy
You can generally use our website without providing personal data. Where personal data (such as names, addresses or email addresses) is collected on our pages, this is, wherever possible, always done on a voluntary basis. This data will not be passed on to third parties without your express consent. Please note that data transmission over the internet (for example, when communicating by email) may have security vulnerabilities. It is not possible to completely protect data against access by third parties. We expressly object to the use by third parties of contact details published to meet legal notice requirements for sending unsolicited advertising or information. The site operators expressly reserve the right to take legal action if unsolicited advertising, such as spam emails, is sent.
Content Delivery Network (Cloudflare)
We use Cloudflare (Cloudflare, Inc., 101 Townsend St., San Francisco, CA 94107, USA) to protect and speed up our website. This constitutes a legitimate interest within the meaning of Art. 6(1)(f) GDPR. Cloudflare processes log data (including IP addresses) and sets technically necessary cookies to defend against malicious bot traffic. We have concluded a Data Processing Addendum (DPA) with Cloudflare based on the EU Standard Contractual Clauses. Cloudflare is certified under the EU-U.S. Data Privacy Framework.
Privacy Statement for a possible use of Google Analytics
This website may use Google Analytics 4, a web analytics service provided by Google Ireland Limited ("Google", Gordon House, Barrow Street, Dublin 4, Ireland). If it is used, data is processed solely on the basis of your express consent (Art. 6(1)(a) GDPR). Google Analytics uses cookies that enable analysis of how you use the website. Information generated by these cookies about your use of this website is transmitted to and stored on a Google server; transfer of data to third countries (such as the United States) cannot be ruled out. IP anonymization is enabled by default on this website, so Google truncates your IP address within a member state of the European Union or another state party to the Agreement on the European Economic Area before transmission. You may withdraw your consent at any time with effect for the future through the cookie settings (our consent tool), or prevent data collection by using the official Google browser add-on.
Copyright Statement
Unless noted otherwise, all artwork on this website is protected property of the website author. Any use for commercial purpose, reproduction and publication requires the author's written permission. Commercial work created in cooperation or bound by contract with third parties are specifically marked. Respective copyrights apply.