Skip to content

Commit b2871c3

Browse files
committed
schematics: use scripts instead of copying files to assets
1 parent 24f4fd1 commit b2871c3

File tree

105 files changed

+7014
-3584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+7014
-3584
lines changed

lib/README.md

Lines changed: 30 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Extend the Angular CLI's default build behavior without ejecting:
66
- 📄 Alternative: Extend the default behavior by providing a custom function
77
- 📦 Optional: Build a single bundle (e. g. for Angular Elements)
88
- ☑️ Inherits from the default builder, hence you have the same options
9+
- ☑️ Provides schematics for some advanced use cases like webpack externals
910
- 🍰 Simple to use
1011
- ⏏️ No eject needed
1112

@@ -24,13 +25,27 @@ Big thanks to [Rob Wormald](https://twitter.com/robwormald) and [David Herges](h
2425
ng update ngx-build-plus --force
2526
```
2627

27-
## Breaking Change in Version 7
28+
## Breaking Changes
29+
30+
## Version 7
2831

2932
- The switch ``single-bundle`` now defaults to ``false`` to align with the CLI's default behavior.
3033

31-
## Example
34+
## Version 9
35+
36+
- `keepPolyfills` and `keepStyles` default to true to avoid misunderstandings.
37+
38+
## Schematics and Options
39+
40+
### Options
3241

33-
https://github.com/manfredsteyer/ngx-build-plus
42+
- ``ng build --single-bundle``: Puts everything reachable from the main entry point into one bundle. Polyfills, scripts, and styles stay in their own bundles as the consuming application might have its own versions of these.
43+
44+
### Schamtics
45+
46+
- ``ng add ngx-build-plus``
47+
- ``ng g ngx-build-plus:wc-polyfill``: Adds webcomponent polyfills to your app
48+
- ``ng g ngx-build-plus:externals``: Updates your app to use webpack externals (see example at the end)
3449

3550
## Getting started
3651

@@ -219,26 +234,13 @@ The result of this description can be found in the [repository's](https://github
219234
ng add ngx-build-plus --project myProject
220235
```
221236

222-
4. **Alternative**: *If, and only if,* this does not work for you, e. g. because you use an earlier Angular version, you can install the library manually:
223-
224-
```
225-
npm install ngx-build-plus --save-dev
226-
```
227-
228-
After this, update your angular.json:
229-
230-
```json
231-
[...]
232-
"architect": {
233-
"build": {
234-
"builder": "ngx-build-plus:build",
235-
[...]
236-
}
237-
}
238-
[...]
239-
```
237+
4. Execute the externals schematc:
238+
239+
```
240+
ng g ngx-build-plus:externals --project myProject
241+
```
240242

241-
5. Create a file ``webpack.extra.js`` with a partial webpack config that tells webpack to exclude packages like ``@angular/core``:
243+
5. This creates a partial webpack config in your project's root:
242244
243245
```JavaScript
244246
module.exports = {
@@ -252,76 +254,19 @@ The result of this description can be found in the [repository's](https://github
252254
}
253255
```
254256
255-
6. Build your application:
257+
6. Build your application. You can use the npm script created by the above mentioned schematic:
256258
257259
```
258-
ng build --prod --extraWebpackConfig webpack.extra.js --output-hashing none --single-bundle true
260+
npm run build:externals:myProject
259261
```
260262
261-
7. You will see that just one bundle (besides the ``script.js`` that could also be shared) is built. The size of the ``main.js`` tells you, that the mentioned packages have been excluded.
263+
7. Angular will now be compiled into a scripts.js and can be reused amongs several seperately compiled bundles. Your code is in the main bundle which is quite tiny b/c it does not contain Angular.
262264
263-
![Result](result.png)
264265
265-
8. Copy the bundle into a project that references the UMD versions of all external libraries and your ``main.ts``. You can find such a project with all the necessary script files in the ``deploy`` folder of the sample.
266-
267-
```html
268-
<!doctype html>
269-
<html lang="en">
270-
<head>
271-
<meta charset="utf-8">
272-
<title>ElementsLoading</title>
273-
<base href="/">
274-
275-
<meta name="viewport" content="width=device-width, initial-scale=1">
276-
<link rel="icon" type="image/x-icon" href="favicon.ico">
277-
</head>
278-
<body>
279-
280-
<!-- Consider putting the following UMD (!) bundles -->
281-
<!-- into a big one -->
282-
283-
<!-- core-js for legacy browsers -->
284-
<script src="./assets/core-js/core.js"></script>
285-
286-
<!-- Zone.js -->
287-
<!--
288-
Consider excluding zone.js when creating
289-
custom Elements by using the noop zone.
290-
-->
291-
<script src="./assets/zone.js/zone.js"></script>
292-
293-
294-
<!-- Polyfills for Browsers supporting
295-
Custom Elements. Needed b/c we downlevel
296-
to ES5. See: @webcomponents/custom-elements
297-
-->
298-
<script src="./assets/custom-elements/src/native-shim.js"></script>
299-
300-
<!-- Polyfills for Browsers not supporting
301-
Custom Elements. See: @webcomponents/custom-elements
302-
-->
303-
<script src="./assets/custom-elements/custom-elements.min.js"></script>
304-
305-
306-
<!-- Rx -->
307-
<script src="./assets/rxjs/rxjs.umd.js"></script>
308-
309-
<!-- Angular Packages -->
310-
<script src="./assets/core/bundles/core.umd.js"></script>
311-
<script src="./assets/common/bundles/common.umd.js"></script>
312-
<script src="./assets/platform-browser/bundles/platform-browser.umd.js"></script>
313-
<script src="./assets/elements/bundles/elements.umd.js"></script>
314-
315-
<!-- Calling Custom Element -->
316-
<custom-element></custom-element>
317-
318-
</body>
319-
</html>
320-
```
266+
Further information about this can be found in my blog [here](https://www.softwarearchitekt.at/post/2019/01/27/building-angular-elements-with-the-cli.aspx).
321267
322-
9. Test your solution.
268+
## Angular Trainings, Consultings, Schulungen
323269
324-
**Hint:** For production, consider using the minified versions of those bundles. They can be found in the ``node_modules`` folder after npm installing them.
270+
see http://www.softwarearchitekt.at
325271
326-
**Hint:** The sample project contains a node script ``copy-bundles.js`` that copies the needed UMD bundles from the ``node_modules`` folder into the assets folder.
327272

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-build-plus",
3-
"version": "8.1.5",
3+
"version": "9.0.1",
44
"description": "Extends the Angular CLI's build process!",
55
"license": "MIT",
66
"repository": {

0 commit comments

Comments
 (0)