-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Expand file tree
/
Copy pathrebuild-replacements.ts
More file actions
41 lines (34 loc) · 1.37 KB
/
rebuild-replacements.ts
File metadata and controls
41 lines (34 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { getGlobalVariable } from '../../utils/env';
import { appendToFile, createDir, writeMultipleFiles } from '../../utils/fs';
import { waitForAnyProcessOutputToMatch } from '../../utils/process';
import { ngServe, updateJsonFile } from '../../utils/project';
const webpackGoodRegEx = getGlobalVariable('argv')['esbuild']
? /Application bundle generation complete\./
: / Compiled successfully./;
export default async function () {
if (process.platform.startsWith('win')) {
return;
}
await createDir('src/environments');
await writeMultipleFiles({
'src/environments/environment.ts': `export const env = 'dev';`,
'src/environments/environment.prod.ts': `export const env = 'prod';`,
'src/main.ts': `
import { env } from './environments/environment';
console.log(env);
`,
});
await updateJsonFile('angular.json', (workspaceJson) => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect.build.configurations.production.fileReplacements = [
{
replace: 'src/environments/environment.ts',
with: 'src/environments/environment.prod.ts',
},
];
});
await ngServe('--configuration=production');
// Should trigger a rebuild.
await appendToFile('src/environments/environment.prod.ts', `console.log('PROD');`);
await waitForAnyProcessOutputToMatch(webpackGoodRegEx);
}