Skip to content

Commit c1e66b5

Browse files
authored
fix(cordovaserve): update copy-webpack to new format (#272)
Update outdated types and usage of copy-webpack-plugin Closes #265
1 parent 4b6a66b commit c1e66b5

File tree

6 files changed

+800
-1297
lines changed

6 files changed

+800
-1297
lines changed

builders/cordova-serve/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,10 @@ const cordovaServeTransform: (
9292
}
9393
);
9494

95-
const copyWebpackPluginOptions = {
96-
ignore: ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'],
97-
};
98-
const copyWebpackPluginInstance = new CopyWebpackPlugin(
99-
formattedAssets.copyWebpackPluginPatterns,
100-
copyWebpackPluginOptions
101-
);
95+
const copyWebpackPluginInstance = new CopyWebpackPlugin({
96+
patterns: formattedAssets.copyWebpackPluginPatterns,
97+
});
98+
10299
// tslint:disable-next-line: no-non-null-assertion
103100
browserWebpackConfig.plugins!.push(
104101
...scriptExtras,

builders/utils/index.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { normalizeExtraEntryPoints } from '@angular-devkit/build-angular/src/ang
22
import { AssetPatternClass } from '@angular-devkit/build-angular/src/browser/schema';
33
import { getSystemPath, join, normalize } from '@angular-devkit/core';
44
import { writeFileSync } from 'fs';
5-
import { resolve } from 'path';
5+
import { posix, resolve } from 'path';
66

77
import { CordovaBuildBuilderSchema } from '../cordova-build/schema';
88
import { CordovaServeBuilderSchema } from '../cordova-serve/schema';
@@ -66,9 +66,7 @@ export function prepareBrowserConfig(
6666
);
6767
writeFileSync(
6868
configPath,
69-
`window.Ionic = window.Ionic || {}; Ionic.ConsoleLogServerConfig = { wsPort: ${
70-
options.consolelogsPort
71-
} }`
69+
`window.Ionic = window.Ionic || {}; Ionic.ConsoleLogServerConfig = { wsPort: ${options.consolelogsPort} }`
7270
);
7371
optionsStarter.scripts.push({
7472
input: configPath,
@@ -155,9 +153,7 @@ export function prepareServerConfig(
155153
);
156154
writeFileSync(
157155
configPath,
158-
`window.Ionic = window.Ionic || {}; Ionic.ConsoleLogServerConfig = { wsPort: ${
159-
options.consolelogsPort
160-
} }`
156+
`window.Ionic = window.Ionic || {}; Ionic.ConsoleLogServerConfig = { wsPort: ${options.consolelogsPort} }`
161157
);
162158
scripts.push({ input: configPath, bundleName: 'consolelogs', lazy: false });
163159
scripts.push({
@@ -220,20 +216,29 @@ export function prepareServerConfig(
220216

221217
const copyWebpackPluginPatterns = assets.map((asset: AssetPatternClass) => {
222218
// Resolve input paths relative to workspace root and add slash at the end.
223-
asset.input = resolve(root, asset.input).replace(/\\/g, '/');
224-
asset.input = asset.input.endsWith('/') ? asset.input : asset.input + '/';
225-
asset.output = asset.output.endsWith('/')
226-
? asset.output
227-
: asset.output + '/';
219+
// tslint:disable-next-line: prefer-const
220+
let { input, output, ignore = [], glob } = asset;
221+
input = resolve(root, input).replace(/\\/g, '/');
222+
input = input.endsWith('/') ? input : input + '/';
223+
output = output.endsWith('/') ? output : output + '/';
228224

229225
return {
230-
context: asset.input,
226+
context: input,
231227
// Now we remove starting slash to make Webpack place it from the output root.
232-
to: asset.output.replace(/^\//, ''),
233-
ignore: asset.ignore,
234-
from: {
235-
glob: asset.glob,
228+
to: output.replace(/^\//, ''),
229+
from: glob,
230+
noErrorOnMissing: true,
231+
globOptions: {
236232
dot: true,
233+
ignore: [
234+
'.gitkeep',
235+
'**/.DS_Store',
236+
'**/Thumbs.db',
237+
// Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
238+
// causes negate patterns not to match.
239+
// See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
240+
...ignore,
241+
].map(i => posix.join(input, i)),
237242
},
238243
};
239244
});

0 commit comments

Comments
 (0)