Comments (7)
Duplicate of #26478 and #26832
from angular-cli.
@alan-agius4 Please don't close this so suddenly.
It's not a direct duplicate, #26478 was about single-entry. We'd really want a single-file.
That issue refers to #23574 where you state:
This is currently not in scope of the webpack based builder.
This however is possible using the esbuild builder by putting all the polyfills and scripts into the main file.
Your statement on this contradicts my experience. In the webpack based builder, it was possible, though indeed not in scope of the builder. In the esbuild based builder, it seems impossible.
I can't find any documentation backing your statement, and I have not found a way to actually do that. If this truly is possible, could you point out how?
I've put the polyfills into the main.ts
. I don't have any scripts. But I still end up with 12 chunks (polyfills is gone):
chunk-CGT2X6C5.js
chunk-KOPSFDZE.js
chunk-PZJJYAMS.js
decoder-LCJLRLPY.js
deflate-ZSPXRSXJ.js
jpeg-OX3M3M6U.js
lerc-T3HVF324.js
lzw-UTG2IYYK.js
main.js
packbits-VLAADFFN.js
raw-S76QM7G4.js
webimage-B5RQHO6U.js
from angular-cli.
With the esbuild based builder, you can create a single bundle as explained in the above linked issue. For quick reference here's the comment #26478 (comment)
from angular-cli.
I have read that comment, but I guess I'm completely failing to understand it.
If you do not use dynamic importing then there will be a single main JavaScript file and the polyfills JavaScript file generated in the output.
- I've managed to eliminate the
polyfill
as per your recommendation to add it tomain.ts
. - I do not use dynamic imports.
Step 1 does work as you said. However step 2 doesn't result at all in: "there will be a single main JavaScript file". I'm still stuck with 12 files.
from angular-cli.
This should not be case, unless a dynamic import or some form of lazy-loading is used. It can also be that one of the libraries that you dependent on is using dynamic imports.
In which case, you can run esbuild or another bundler on your main.js to concat it.
from angular-cli.
Ah, thanks, I'll look into doing that.
from angular-cli.
Thank you so much!
Apparently I really can't control the code splitting, but bundling the split results with esbuild
in a post-build step works smoothly.
This is now run by my npm postbuild command:
#!/bin/env node
{
const esbuild = require('esbuild');
const { mkdirSync } = require('fs');
const srcDir = 'dist/fooComponent/browser';
const destDir = 'dist/components';
const destFileName = 'fooComponent.js';
mkdirSync(destDir, { recursive: true });
console.log(`Bundling ${destFileName}…`);
esbuild
.build({
entryPoints: [`${srcDir}/main.js`],
bundle: true,
minify: true,
sourcemap: false,
outfile: `${destDir}/${destFileName}`,
format: 'esm',
})
.then(
() => console.info(`${destFileName} created successfully!`),
(error) => console.error(error),
);
}
from angular-cli.
Related Issues (20)
- Top-level await is not available in the configured target environment HOT 4
- Bug: [ngtools] Replace resource transformer issue with conditional `templateUrl` HOT 3
- npm start with .NET Core SPA HOT 2
- Components sourcemap not resolved when using sub-paths HOT 1
- Sqlite3 causing "Could not locate the bindings file" when added to SSR server HOT 2
- `build-angular:application` + `ng serve` doesn't update components, that were removed and then readded
- ESBuild application builder breaks when using SCSS variables in asset URLs HOT 1
- yarn: command not found HOT 1
- application builder - strict-dynamic - issues with content security policy HOT 2
- How specify a folder for javascript and css with "ng build" (but with index.html on the root folder) HOT 3
- --skip-install is ignored when creating a new app with --ssr HOT 1
- Out of memory after upgrade to latest version HOT 5
- "NG04014: Invalid configuration of route" when using router with exported variables HOT 2
- Angular CLI 16+ generates config that fails to inline stylesheet from typekit/Adobe HOT 8
- Angular11: fileReplacements stopped working after angular update HOT 3
- [Deprecation Warning] Node's DEP0060 when using proxy config and entering a URL target. HOT 1
- Esbuild file loader significant slowdown HOT 4
- SchematicTestRunner.runExternalSchematic fails with "The encoded data was not valid for encoding utf-8" HOT 2
- ng serve confusing raw size? HOT 4
- Bug: ng build cause warnings with pseudo-selectors in aws-amplify HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-cli.