-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): avoid attempting to optimize copi…
…ed JavaScript assets When in watch mode (`ng serve`/`ng build --watch`), Webpack's `copy-webpack-plugin` is currently used to implement the project `assets` option within `angular.json`. Files specified by the `assets` option are intended to be copied to the output unmodified and in their original form. However, if any JavaScript assets were present they previously would have been unintentionally subject to their respective optimization plugins which would result in modified asset outputs and the potential for breakage of the assets. `ng build` outside of watch mode uses a direct file copy with copy-on-write (where supported) to process assets and is therefore not affected by this situation. When the `copy-webpack-plugin` is used, it adds a `copied` flag to an asset's info metadata. This flag is now used to exclude all such copied JavaScript assets from optimization.
- Loading branch information
1 parent
8499cfe
commit f5d019f
Showing
2 changed files
with
68 additions
and
25 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
.../angular_devkit/build_angular/src/builders/dev-server/tests/behavior/build-assets_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { serveWebpackBrowser } from '../../index'; | ||
import { executeOnceAndFetch } from '../execute-fetch'; | ||
import { | ||
BASE_OPTIONS, | ||
DEV_SERVER_BUILDER_INFO, | ||
describeBuilder, | ||
setupBrowserTarget, | ||
} from '../setup'; | ||
|
||
describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => { | ||
describe('Behavior: "browser builder assets"', () => { | ||
it('serves a project JavaScript asset unmodified', async () => { | ||
const javascriptFileContent = '/* a comment */const foo = `bar`;\n\n\n'; | ||
await harness.writeFile('src/extra.js', javascriptFileContent); | ||
|
||
setupBrowserTarget(harness, { | ||
assets: ['src/extra.js'], | ||
optimization: { | ||
scripts: true, | ||
}, | ||
}); | ||
|
||
harness.useTarget('serve', { | ||
...BASE_OPTIONS, | ||
}); | ||
|
||
const { result, response } = await executeOnceAndFetch(harness, 'extra.js'); | ||
|
||
expect(result?.success).toBeTrue(); | ||
expect(await response?.text()).toBe(javascriptFileContent); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters