48
loading...
This website collects cookies to deliver better user experience
$ npx -p @angular/cli ng new esbuild-ng-cli
$ npm install esbuild --save-dev
added 1 package (...)
npm run build
as it was created - on webpack, and add dedicated esbuild
script:"esbuild": "esbuild src/main.ts --bundle --outfile=dist/main.js --loader:.html=text --minify"
src/main.ts
- is the script entry point - from there esbuild start finding all dependecies--bundle
- tell esbuild to bundle all files into one bundle file--outfile=dist/main.js
- the target of our build--loader:.html=text
- makes HTML files interpreted as strings. It's similar to raw-loader
in webpack--minify
- minimize our code. It's not as effective as angular main configuration, but it's much better than leaving code unoptimized.src/app/app.component.ts
with:import { Component } from '@angular/core';
import template from './app.component.html';
@Component({
selector: 'app-root',
template,
// styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'esbuild-ng-cli';
}
templateUrl
is replace by explicit template load, and css import I dropped to simplify the proof-of-a-concept application.index.d.ts
with:declare module "*.html" {
const content: string;
export default content;
}
$ npm run esbuild
> [email protected] esbuild
> esbuild src/main.ts --bundle --outfile=dist/main.js --loader:.html=text --minify
dist/main.js 761.1kb
⚡ Done in 124ms
./index.html
:<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>EsbuildNgCli</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<body>
<app-root></app-root>
<script src="dist/main.js"></script>
</body></html>
Error: In this configuration Angular requires Zone.js
./src/main.ts
:import 'zone.js';
import { enableProdMode } from '@angular/core';
/** the rest of the file **/
798.2kb