Skip to content

Commit

Permalink
fix(cordovaserve): update copy-webpack to new format (#272)
Browse files Browse the repository at this point in the history
Update outdated types and usage of copy-webpack-plugin

Closes #265
  • Loading branch information
mhartington authored Aug 21, 2020
1 parent 4b6a66b commit c1e66b5
Show file tree
Hide file tree
Showing 6 changed files with 800 additions and 1,297 deletions.
11 changes: 4 additions & 7 deletions builders/cordova-serve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,10 @@ const cordovaServeTransform: (
}
);

const copyWebpackPluginOptions = {
ignore: ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'],
};
const copyWebpackPluginInstance = new CopyWebpackPlugin(
formattedAssets.copyWebpackPluginPatterns,
copyWebpackPluginOptions
);
const copyWebpackPluginInstance = new CopyWebpackPlugin({
patterns: formattedAssets.copyWebpackPluginPatterns,
});

// tslint:disable-next-line: no-non-null-assertion
browserWebpackConfig.plugins!.push(
...scriptExtras,
Expand Down
39 changes: 22 additions & 17 deletions builders/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { normalizeExtraEntryPoints } from '@angular-devkit/build-angular/src/ang
import { AssetPatternClass } from '@angular-devkit/build-angular/src/browser/schema';
import { getSystemPath, join, normalize } from '@angular-devkit/core';
import { writeFileSync } from 'fs';
import { resolve } from 'path';
import { posix, resolve } from 'path';

import { CordovaBuildBuilderSchema } from '../cordova-build/schema';
import { CordovaServeBuilderSchema } from '../cordova-serve/schema';
Expand Down Expand Up @@ -66,9 +66,7 @@ export function prepareBrowserConfig(
);
writeFileSync(
configPath,
`window.Ionic = window.Ionic || {}; Ionic.ConsoleLogServerConfig = { wsPort: ${
options.consolelogsPort
} }`
`window.Ionic = window.Ionic || {}; Ionic.ConsoleLogServerConfig = { wsPort: ${options.consolelogsPort} }`
);
optionsStarter.scripts.push({
input: configPath,
Expand Down Expand Up @@ -155,9 +153,7 @@ export function prepareServerConfig(
);
writeFileSync(
configPath,
`window.Ionic = window.Ionic || {}; Ionic.ConsoleLogServerConfig = { wsPort: ${
options.consolelogsPort
} }`
`window.Ionic = window.Ionic || {}; Ionic.ConsoleLogServerConfig = { wsPort: ${options.consolelogsPort} }`
);
scripts.push({ input: configPath, bundleName: 'consolelogs', lazy: false });
scripts.push({
Expand Down Expand Up @@ -220,20 +216,29 @@ export function prepareServerConfig(

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

return {
context: asset.input,
context: input,
// Now we remove starting slash to make Webpack place it from the output root.
to: asset.output.replace(/^\//, ''),
ignore: asset.ignore,
from: {
glob: asset.glob,
to: output.replace(/^\//, ''),
from: glob,
noErrorOnMissing: true,
globOptions: {
dot: true,
ignore: [
'.gitkeep',
'**/.DS_Store',
'**/Thumbs.db',
// Negate patterns needs to be absolute because copy-webpack-plugin uses absolute globs which
// causes negate patterns not to match.
// See: https://github.com/webpack-contrib/copy-webpack-plugin/issues/498#issuecomment-639327909
...ignore,
].map(i => posix.join(input, i)),
},
};
});
Expand Down
Loading

0 comments on commit c1e66b5

Please sign in to comment.