Skip to content

Commit c858d98

Browse files
committed
chore(docs): add global lib docs
1 parent 3dcd49b commit c858d98

File tree

4 files changed

+67
-24
lines changed

4 files changed

+67
-24
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The generated project has dependencies that require **Node 4 or greater**.
4747
* [Global styles](#global-styles)
4848
* [CSS preprocessor integration](#css-preprocessor-integration)
4949
* [3rd Party Library Installation](#3rd-party-library-installation)
50+
* [Global Library Installation](#global-library-installation)
5051
* [Updating angular-cli](#updating-angular-cli)
5152
* [Known Issues](#known-issues)
5253
* [Development Hints for hacking on angular-cli](#development-hints-for-hacking-on-angular-cli)
@@ -250,6 +251,8 @@ The `styles.css` file allows users to add global styles and supports
250251
If the project is created with the `--style=sass` option, this will be a `.sass`
251252
file instead, and the same applies to `scss/less/styl`.
252253

254+
You can add more global styles via the `apps[0].styles` property in `angular-cli.json`.
255+
253256
### CSS Preprocessor integration
254257

255258
Angular-CLI supports all major CSS preprocessors:
@@ -296,6 +299,42 @@ npm install moment --save
296299
npm install @types/moment --save-dev
297300
```
298301

302+
### Global Library Installation
303+
304+
Some javascript libraries need to be added to the global scope, and loaded as if
305+
they were in a script tag. We can do this using the `apps[0].scripts` and
306+
`apps[0].styles` properties of `angular-cli.json`.
307+
308+
As an example, to use [Boostrap 4](http://v4-alpha.getbootstrap.com/) this is
309+
what you need to do:
310+
311+
First install Bootstrap from `npm`:
312+
313+
```bash
314+
npm install bootstrap@next
315+
```
316+
317+
Then add the needed script files to to `apps[0].scripts`.
318+
319+
```
320+
"scripts": [
321+
"../node_modules/jquery/dist/jquery.js",
322+
"../node_modules/tether/dist/js/tether.js",
323+
"../node_modules/bootstrap/dist/js/bootstrap.js"
324+
],
325+
```
326+
327+
Finally add the Bootstrap CSS to the `apps[0].styles` array:
328+
```
329+
"styles": [
330+
"styles.css",
331+
"../node_modules/bootstrap/dist/css/bootstrap.css"
332+
],
333+
```
334+
335+
Restart `ng serve` if you're running it, and Bootstrap 4 should be working on
336+
your app.
337+
299338
### Updating angular-cli
300339

301340
To update `angular-cli` to a new version, you must update both the global package and your project's local package.

addon/ng2/blueprints/ng2/files/angular-cli.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"tsconfig": "tsconfig.json",
1515
"prefix": "<%= prefix %>",
1616
"mobile": <%= isMobile %>,
17-
"styles": "styles.<%= styleExt %>",
17+
"styles": [
18+
"styles.<%= styleExt %>"
19+
],
20+
"scripts": [],
1821
"environments": {
1922
"source": "environments/environment.ts",
2023
"prod": "environments/environment.prod.ts",

addon/ng2/models/webpack-build-common.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@ export function getWebpackCommonConfig(projectRoot: string, environment: string,
1010

1111
const appRoot = path.resolve(projectRoot, appConfig.root);
1212
const appMain = path.resolve(appRoot, appConfig.main);
13-
const styles = path.resolve(appRoot, appConfig.styles);
13+
const styles = appConfig.styles.map(style => path.resolve(appRoot, style));
14+
const scripts = appConfig.scripts.map(script => path.resolve(appRoot, script));
1415
const lazyModules = findLazyModules(appRoot);
1516

17+
let entry = {
18+
main: [appMain]
19+
};
20+
21+
if (appConfig.styles.length > 0) entry.styles = styles;
22+
if (appConfig.scripts.length > 0) entry.scripts = scripts;
23+
1624
return {
1725
devtool: 'source-map',
1826
resolve: {
1927
extensions: ['', '.ts', '.js'],
2028
root: appRoot
2129
},
2230
context: path.resolve(__dirname, './'),
23-
entry: {
24-
main: [appMain, styles]
25-
},
31+
entry: entry,
2632
output: {
2733
path: path.resolve(projectRoot, appConfig.outDir),
2834
filename: '[name].bundle.js'
@@ -66,6 +72,9 @@ export function getWebpackCommonConfig(projectRoot: string, environment: string,
6672
       { include: styles, test: /\.less$/, loaders: ['style-loader', 'css-loader', 'postcss-loader', 'less-loader'] },
6773
       { include: styles, test: /\.scss$|\.sass$/, loaders: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'] },
6874

75+
// load global scripts using script-loader
76+
{ include: scripts, test: /\.js$/, loader: 'script-loader' },
77+
6978
       { test: /\.json$/, loader: 'json-loader' },
7079
       { test: /\.(jpg|png)$/, loader: 'url-loader?limit=10000' },
7180
       { test: /\.html$/, loader: 'raw-loader' },

lib/config/schema.json

+11-19
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,19 @@
4949
"mobile": {
5050
"type": "boolean"
5151
},
52-
"additionalEntries": {
53-
"description": "Additional files to be included in the build.",
52+
"styles": {
53+
"description": "Global styles to be included in the build.",
5454
"type": "array",
5555
"items": {
56-
"anyOf": [
57-
{
58-
"type": "string"
59-
},
60-
{
61-
"type": "object",
62-
"properties": {
63-
"input": {
64-
"type": "string"
65-
},
66-
"output": {
67-
"type": "string"
68-
}
69-
},
70-
"additionalProperties": false
71-
}
72-
]
56+
"type": "string"
57+
},
58+
"additionalProperties": false
59+
},
60+
"scripts": {
61+
"description": "Global scripts to be included in the build.",
62+
"type": "array",
63+
"items": {
64+
"type": "string"
7365
},
7466
"additionalProperties": false
7567
},

0 commit comments

Comments
 (0)