Skip to content

Commit 41c8649

Browse files
committed
docs: add lazy scripts/styles docs
This was added back in #3401 but never documented. Also cleans up duplicate docs in overview. Close #4693
1 parent 9e91d86 commit 41c8649

File tree

3 files changed

+42
-65
lines changed

3 files changed

+42
-65
lines changed

docs/documentation/overview.md

-65
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,6 @@ ng serve
2020
```
2121
Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
2222

23-
### Build Targets and Environment Files
24-
25-
`ng build` can specify both a build target (`--target=production` or `--target=development`) and an
26-
environment file to be used with that build (`--environment=dev` or `--environment=prod`).
27-
By default, the development build target and environment are used.
28-
29-
The mapping used to determine which environment file is used can be found in `angular-cli.json`:
30-
31-
```json
32-
"environments": {
33-
"source": "environments/environment.ts",
34-
"dev": "environments/environment.ts",
35-
"prod": "environments/environment.prod.ts"
36-
}
37-
```
38-
39-
These options also apply to the serve command. If you do not pass a value for `environment`,
40-
it will default to `dev` for `development` and `prod` for `production`.
41-
4223
### Bundling
4324

4425
All builds make use of bundling, and using the `--prod` flag in `ng build --prod`
@@ -61,52 +42,6 @@ ng e2e
6142
Before running the tests make sure you are serving the app via `ng serve`.
6243
End-to-end tests are run via [Protractor](https://angular.github.io/protractor/).
6344

64-
### Global styles
65-
66-
The `styles.css` file allows users to add global styles and supports
67-
[CSS imports](https://developer.mozilla.org/en/docs/Web/CSS/@import).
68-
69-
If the project is created with the `--style=sass` option, this will be a `.sass`
70-
file instead, and the same applies to `scss/less/styl`.
71-
72-
You can add more global styles via the `apps[0].styles` property in `angular-cli.json`.
73-
74-
### Global Library Installation
75-
76-
Some javascript libraries need to be added to the global scope, and loaded as if
77-
they were in a script tag. We can do this using the `apps[0].scripts` and
78-
`apps[0].styles` properties of `angular-cli.json`.
79-
80-
As an example, to use [Bootstrap 4](http://v4-alpha.getbootstrap.com/) this is
81-
what you need to do:
82-
83-
First install Bootstrap from `npm`:
84-
85-
```bash
86-
npm install bootstrap@next
87-
```
88-
89-
Then add the needed script files to `apps[0].scripts`:
90-
91-
```json
92-
"scripts": [
93-
"../node_modules/jquery/dist/jquery.js",
94-
"../node_modules/tether/dist/js/tether.js",
95-
"../node_modules/bootstrap/dist/js/bootstrap.js"
96-
],
97-
```
98-
99-
Finally add the Bootstrap CSS to the `apps[0].styles` array:
100-
```json
101-
"styles": [
102-
"../node_modules/bootstrap/dist/css/bootstrap.css",
103-
"styles.css"
104-
],
105-
```
106-
107-
Restart `ng serve` if you're running it, and Bootstrap 4 should be working on
108-
your app.
109-
11045
### Additional Commands
11146
* [ng new](new)
11247
* [ng update](update)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Global styles
2+
3+
You can add Javascript files to the global scope via the `apps[0].scripts`
4+
property in `angular-cli.json`.
5+
These will be loaded exactly as if you had added them in a `<script>` tag inside `index.html`.
6+
7+
This is especially useful for legacy libraries or analytic snippets.
8+
9+
```json
10+
"scripts": [
11+
"global-script.js",
12+
],
13+
```
14+
15+
You can also rename the output and lazy load it by using the object format:
16+
17+
```json
18+
"scripts": [
19+
"global-script.js",
20+
{ "input": "lazy-script.js", "lazy": true },
21+
{ "input": "pre-rename-script.js", "output": "renamed-script" },
22+
],
23+
```

docs/documentation/stories/global-styles.md

+19
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,22 @@ If the project is created with the `--style=sass` option, this will be a `.sass`
77
file instead, and the same applies to `scss/less/styl`.
88

99
You can add more global styles via the `apps[0].styles` property in `angular-cli.json`.
10+
These will be loaded exactly as if you had added them in a `<link>` tag inside `index.html`.
11+
12+
```json
13+
"styles": [
14+
"styles.css",
15+
"more-styles.css",
16+
],
17+
```
18+
19+
You can also rename the output and lazy load it by using the object format:
20+
21+
```json
22+
"styles": [
23+
"styles.css",
24+
"more-styles.css",
25+
{ "input": "lazy-style.scss", "lazy": true },
26+
{ "input": "pre-rename-style.scss", "output": "renamed-style" },
27+
],
28+
```

0 commit comments

Comments
 (0)