Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
@angular-builders/custom-esbuild
Advanced tools
Custom esbuild builders for Angular build facade. Allow to modify Angular build configuration without ejecting it
Allow customizing ESBuild configuration
npm i -D @angular-builders/custom-esbuild
angular.json
:
"projects": {
...
"[project]": {
...
"architect": {
...
"[architect-target]": {
"builder": "@angular-builders/custom-esbuild:[application|dev-server]",
"options": {
...
}
Where:
[architect-target]
is not one of the predefined targets (like build, serve, test etc.) then run it like this:ng run [project]:[architect-target]
ng [architect-target]
"projects": {
...
"example-app": {
...
"architect": {
...
"build": {
"builder": "@angular-builders/custom-esbuild:browser",
"options": {
...
}
ng build
application
The @angular-builders/custom-esbuild:application
builder is an extension of the @angular-devkit/build-angular:application
builder, allowing the specification of additional properties on top of the existing ones. The custom builder runs the original builder at the end, incorporating extra parameters specified in the extended configuration. It will also perform index.html
transformations if specified.
Builder options:
@angular-devkit/build-angular:application
optionsplugins
indexHtmlTransformer
: see belowangular.json
:
"architect": {
...
"build": {
"builder": "@angular-builders/custom-esbuild:application",
"options": {
"plugins": ["./esbuild/plugins.ts", { "path": "./esbuild/define-env.ts", "options": { "stage": "development" } }],
"indexHtmlTransformer": "./esbuild/index-html-transformer.js",
"outputPath": "dist/my-cool-client",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "src/tsconfig.app.json"
},
"configurations": {
"production": {
"plugins": ["./esbuild/plugins.ts", { "path": "./esbuild/define-env.ts", "options": { "stage": "production" } }]
}
}
}
In the above example, we specify the list of plugins
that should implement the ESBuild plugin schema. These plugins are custom user plugins and are added to the original ESBuild Angular configuration. Additionally, the indexHtmlTransformer
property is used to specify the path to the file that exports the function used to modify the index.html
.
The plugin file can export either a single plugin or a list of plugins. If a plugin accepts configuration then the config should be provided in angular.json
:
// esbuild/plugins.ts
import type { Plugin, PluginBuild } from 'esbuild';
const defineTextPlugin: Plugin = {
name: 'define-text',
setup(build: PluginBuild) {
const options = build.initialOptions;
options.define.buildText = JSON.stringify('This text is provided during the compilation');
},
};
export default defineTextPlugin;
OR:
// esbuild/plugins.ts
import type { Plugin, PluginBuild } from 'esbuild';
function defineEnv(pluginOptions: { stage: string }): Plugin {
return {
name: 'define-env',
setup(build: PluginBuild) {
const buildOptions = build.initialOptions;
buildOptions.define.stage = JSON.stringify(pluginOptions.stage);
},
};
};
export default defineEnv;
Or:
// esbuild/plugins.ts
import type { Plugin, PluginBuild } from 'esbuild';
const defineTextPlugin: Plugin = {
name: 'define-text',
setup(build: PluginBuild) {
const options = build.initialOptions;
options.define.buildText = JSON.stringify('This text is provided during the compilation');
},
};
const updateExternalPlugin: Plugin = {
name: 'update-external',
setup(build: PluginBuild) {
const options = build.initialOptions;
options.external ??= [];
options.external.push('elysia');
},
};
export default [defineTextPlugin, updateExternalPlugin];
dev-server
The @angular-builders/custom-esbuild:dev-server
is an enhanced version of the @angular-devkit/build-angular:dev-server
builder that allows the specification of middlewares
(Vite's Connect
functions). It also obtains plugins
and indexHtmlTransformer
from the :application
configuration to run the Vite server with all the necessary configuration applied.
angular.json
:
"architect": {
...
"build": {
"builder": "@angular-builders/custom-esbuild:application",
"options": {
"plugins": ["./esbuild/plugin-1.js"]
...
}
},
"serve": {
"builder": "@angular-builders/custom-esbuild:dev-server",
"options": {
"middlewares": ["./esbuild/my-middleware.js"],
"buildTarget": "my-project:build"
}
}
Since Angular 8, index.html
is not generated as part of the build. If you want to modify your index.html
, you should use the indexHtmlTransformer
option. indexHtmlTransformer
is a path (relative to the workspace root) to a .js
or .ts
file that exports a transformation function for index.html
. If indexHtmlTransformer
is written in TypeScript, the application's tsConfig
file will be used by tsnode
for its execution:
(indexHtmlContent: string) => string | Promise<string>;
or, in other words, the function receives target options and original index.html
content (generated by Angular CLI) and returns a new content as string
or Promise<string>
.
The indexHtmlTransformer
function signature is defined here.
It is useful when you want to transform your index.html
according to the build options.
angular.json
:
"architect": {
...
"build": {
"builder": "@angular-builders/custom-esbuild:application",
"options": {
"indexHtmlTransformer": "./esbuild/index-html-transformer.js"
...
}
index-html-transformer.js
:
module.exports = (indexHtml) => {
const i = indexHtml.indexOf('</body>');
const content = `<p>Dynamically inserted content</p>`;
return `${indexHtml.slice(0, i)}
${content}
${indexHtml.slice(i)}`;
};
Alternatively, using TypeScript:
export default (indexHtml: string) => {
const i = indexHtml.indexOf('</body>');
const content = `<p>Dynamically inserted content</p>`;
return `${indexHtml.slice(0, i)}
${content}
${indexHtml.slice(i)}`;
};
In the example we add a paragraph with an example content to your index.html
. It is a very simple example without any asynchronous code but you can also return a Promise
from this function.
Custom ESBuild builder fully supports ESM.
"type": "module"
both plugin.js
and index-html-transformer.js
will be treated as ES modules, unless you change their file extension to .cjs
. In that case they'll be treated as CommonJS Modules. Example."type": "commonjs"
(or unspecified type) both plugin.js
and index-html-transformer.js
will be treated as CommonJS modules unless you change their file extension to .mjs
. In that case they'll be treated as ES Modules. Example.ts-node/esm
when running ng build
. Also, in that case tsconfig.json
for ts-node
no longer defaults to tsConfig
from the application
target - you have to specify it manually via environment variable. Example.FAQs
Custom esbuild builders for Angular build facade. Allow to modify Angular build configuration without ejecting it
The npm package @angular-builders/custom-esbuild receives a total of 7,138 weekly downloads. As such, @angular-builders/custom-esbuild popularity was classified as popular.
We found that @angular-builders/custom-esbuild demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.