Skip to content

Commit bdebc9e

Browse files
alan-agius4alexeagle
authored andcommitted
feat(@angular-devkit/build-angular): add ignore option to assets object
You can now provide an array of globs to `ignore` from copying Closes #11850
1 parent 509c0fa commit bdebc9e

File tree

7 files changed

+79
-8
lines changed

7 files changed

+79
-8
lines changed

docs/documentation/stories/asset-configuration.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ The array below does the same as the default one:
2323
]
2424
```
2525

26-
`glob` is the a [node-glob](https://github.com/isaacs/node-glob) using `input` as base directory.
27-
`input` is relative to the workspace root, while `output` is relative to `outDir`
28-
(`dist/project-name` default).
26+
- `glob` is the a [node-glob](https://github.com/isaacs/node-glob) using `input` as base directory.
27+
- `input` is relative to the workspace root.
28+
- `ignore` is a list of globs to ignore from copying.
29+
- `output` is relative to `outDir` (`dist/project-name` default).
2930

3031
You can use this extended configuration to copy assets from outside your project.
3132
For instance, you can copy assets from a node package:
@@ -36,7 +37,14 @@ The array below does the same as the default one:
3637
]
3738
```
3839

39-
The contents of `node_modules/some-package/images/` will be available in `dist/some-package/`.
40+
You can ignore certain files from copying by using the `ignore` option:
41+
```json
42+
"assets": [
43+
{ "glob": "**/*", "input": "src/assets/", "ignore": ["**/*.svg"], "output": "/assets/" },
44+
]
45+
```
46+
47+
The contents of `node_modules/some-package/images/` will be available in `dist/some-package/`.
4048

4149
## Writing assets outside of `dist/`
4250

packages/angular/cli/lib/config/schema.json

+17-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"default": false,
109109
"alias": "t"
110110
},
111-
"module": {
111+
"module": {
112112
"type": "string",
113113
"description": "Allows specification of the declaring module.",
114114
"alias": "m"
@@ -160,7 +160,7 @@
160160
"description": "Flag to indicate if a dir is created.",
161161
"default": true
162162
},
163-
"module": {
163+
"module": {
164164
"type": "string",
165165
"description": "Allows specification of the declaring module.",
166166
"alias": "m"
@@ -219,7 +219,7 @@
219219
"default": true,
220220
"visible": false
221221
},
222-
"module": {
222+
"module": {
223223
"type": "string",
224224
"description": "Allows specification of the declaring module.",
225225
"alias": "m"
@@ -778,6 +778,13 @@
778778
"output": {
779779
"type": "string",
780780
"description": "Absolute path within the output."
781+
},
782+
"ignore": {
783+
"description": "An array of globs to ignore.",
784+
"type": "array",
785+
"items": {
786+
"type": "string"
787+
}
781788
}
782789
},
783790
"additionalProperties": false,
@@ -1241,6 +1248,13 @@
12411248
"output": {
12421249
"type": "string",
12431250
"description": "Absolute path within the output."
1251+
},
1252+
"ignore": {
1253+
"description": "An array of globs to ignore.",
1254+
"type": "array",
1255+
"items": {
1256+
"type": "string"
1257+
}
12441258
}
12451259
},
12461260
"additionalProperties": false,
@@ -1541,7 +1555,6 @@
15411555
}
15421556
]
15431557
}
1544-
15451558
}
15461559
},
15471560
"tslint": {

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
125125
context: asset.input,
126126
// Now we remove starting slash to make Webpack place it from the output root.
127127
to: asset.output.replace(/^\//, ''),
128+
ignore: asset.ignore,
128129
from: {
129130
glob: asset.glob,
130131
dot: true

packages/angular_devkit/build_angular/src/browser/schema.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ export interface AssetPatternObject {
237237
*/
238238
input: string;
239239

240+
/**
241+
* An array of globs to ignore.
242+
*/
243+
ignore?: string[];
244+
240245
/**
241246
* Absolute path within the output.
242247
*/

packages/angular_devkit/build_angular/src/browser/schema.json

+7
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@
259259
"type": "string",
260260
"description": "The input path dir in which to apply 'glob'. Defaults to the project root."
261261
},
262+
"ignore": {
263+
"description": "An array of globs to ignore.",
264+
"type": "array",
265+
"items": {
266+
"type": "string"
267+
}
268+
},
262269
"output": {
263270
"type": "string",
264271
"description": "Absolute path within the output."

packages/angular_devkit/build_angular/src/karma/schema.json

+7
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@
174174
"output": {
175175
"type": "string",
176176
"description": "Absolute path within the output."
177+
},
178+
"ignore": {
179+
"description": "An array of globs to ignore.",
180+
"type": "array",
181+
"items": {
182+
"type": "string"
183+
}
177184
}
178185
},
179186
"additionalProperties": false,

packages/angular_devkit/build_angular/test/browser/assets_spec_large.ts

+30
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,36 @@ describe('Browser Builder assets', () => {
5959
).toPromise().then(done, done.fail);
6060
});
6161

62+
it('works with ignored patterns', (done) => {
63+
const assets: { [path: string]: string } = {
64+
'./src/folder/.gitkeep': '',
65+
'./src/folder/asset-ignored.txt': '',
66+
'./src/folder/asset.txt': '',
67+
};
68+
69+
host.writeMultipleFiles(assets);
70+
71+
const overrides = {
72+
assets: [
73+
{
74+
glob: '**/*',
75+
ignore: ['asset-ignored.txt'],
76+
input: 'src/folder',
77+
output: '/folder',
78+
},
79+
],
80+
};
81+
82+
runTargetSpec(host, browserTargetSpec, overrides).pipe(
83+
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
84+
tap(() => {
85+
expect(host.scopedSync().exists(normalize('./dist/folder/asset.txt'))).toBe(true);
86+
expect(host.scopedSync().exists(normalize('./dist/folder/asset-ignored.txt'))).toBe(false);
87+
expect(host.scopedSync().exists(normalize('./dist/folder/.gitkeep'))).toBe(false);
88+
}),
89+
).toPromise().then(done, done.fail);
90+
});
91+
6292
it('fails with non-absolute output path', (done) => {
6393
const assets: { [path: string]: string } = {
6494
'./node_modules/some-package/node_modules-asset.txt': 'node_modules-asset.txt',

0 commit comments

Comments
 (0)