Visitar URL original
WIP: webpack 5 support status by valorkin · Pull Request #18873 · angular/angular-cli · GitHub
The Wayback Machine - https://web.archive.org/web/20201023163730/https://github.com/angular/angular-cli/pull/18873/files
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: webpack 5 support status #18873

Draft
wants to merge 4 commits into
base: master
from
Draft
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -134,7 +134,8 @@ jobs:
git config user.name "angular-ci"
git config user.email "angular-ci"
# Rebase PR on top of target branch.
node tools/rebase-pr.js angular/angular-cli ${CIRCLE_PR_NUMBER}
# node tools/rebase-pr.js angular/angular-cli ${CIRCLE_PR_NUMBER}
echo "all fine need to skip this as for next.6"
else
echo "This build is not over a PR, nothing to do."
fi
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/scripts" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/packages" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.yarn" />
<excludeFolder url="file://$MODULE_DIR$/bazel-out" />
<excludeFolder url="file://$MODULE_DIR$/tests/legacy-cli/e2e/assets/1.7-project/dist" />
<excludeFolder url="file://$MODULE_DIR$/tests/legacy-cli/e2e/assets/1.7-project/tmp" />
<excludeFolder url="file://$MODULE_DIR$/third_party" />
@@ -0,0 +1,310 @@
import 'webpack';
import 'webpack-sources';
import {
Compilation as CompilationWp5, Compiler,
Module as ModuleWp5, Chunk as ChunkWp5
} from 'webpack';

type loaderCallback = (err: Error | undefined | null, content?: string | Buffer, sourceMap?: RawSourceMap) => void;

declare module 'webpack' {
type InputFileSystem = any;
type RuleSetLoader = any;
namespace loader {
interface LoaderContext {
/**
* Loader API version. Currently 2.
* This is useful for providing backwards compatibility.
* Using the version you can specify custom logic or fallbacks for breaking changes.
*/
version: string;

/**
* The directory of the module. Can be used as context for resolving other stuff.
* In the example: /abc because resource.js is in this directory
*/
context: string;

/**
* Starting with webpack 4, the formerly `this.options.context` is provided as `this.rootContext`.
*/
rootContext: string;

/**
* The resolved request string.
* In the example: "/abc/loader1.js?xyz!/abc/node_modules/loader2/index.js!/abc/resource.js?rrr"
*/
request: string;

/**
* A string or any object. The query of the request for the current loader.
*/
query: any;

/**
* A data object shared between the pitch and the normal phase.
*/
data?: any;

callback: loaderCallback;

/**
* Make this loader async.
*/
async(): loaderCallback | undefined;

/**
* Make this loader result cacheable. By default it's not cacheable.
* A cacheable loader must have a deterministic result, when inputs and dependencies haven't changed.
* This means the loader shouldn't have other dependencies than specified with this.addDependency.
* Most loaders are deterministic and cacheable.
*/
cacheable(flag?: boolean): void;

/**
* An array of all the loaders. It is writeable in the pitch phase.
* loaders = [{request: string, path: string, query: string, module: function}]
*
* In the example:
* [
* { request: "/abc/loader1.js?xyz",
* path: "/abc/loader1.js",
* query: "?xyz",
* module: [Function]
* },
* { request: "/abc/node_modules/loader2/index.js",
* path: "/abc/node_modules/loader2/index.js",
* query: "",
* module: [Function]
* }
* ]
*/
loaders: any[];

/**
* The index in the loaders array of the current loader.
* In the example: in loader1: 0, in loader2: 1
*/
loaderIndex: number;

/**
* The resource part of the request, including query.
* In the example: "/abc/resource.js?rrr"
*/
resource: string;

/**
* The resource file.
* In the example: "/abc/resource.js"
*/
resourcePath: string;

/**
* The query of the resource.
* In the example: "?rrr"
*/
resourceQuery: string;

/**
* Emit a warning.
*/
emitWarning(message: string | Error): void;

/**
* Emit a error.
*/
emitError(message: string | Error): void;

/**
* Execute some code fragment like a module.
*
* Don't use require(this.resourcePath), use this function to make loaders chainable!
*
*/
exec(code: string, filename: string): any;

/**
* Resolves the given request to a module, applies all configured loaders and calls
* back with the generated source, the sourceMap and the module instance (usually an
* instance of NormalModule). Use this function if you need to know the source code
* of another module to generate the result.
*/
loadModule(request: string, callback: (err: Error | null, source: string, sourceMap: RawSourceMap, module: Module) => void): any;

/**
* Resolve a request like a require expression.
*/
resolve(context: string, request: string, callback: (err: Error, result: string) => void): any;

/**
* Resolve a request like a require expression.
*/
resolveSync(context: string, request: string): string;

/**
* Adds a file as dependency of the loader result in order to make them watchable.
* For example, html-loader uses this technique as it finds src and src-set attributes.
* Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
*/
addDependency(file: string): void;

/**
* Adds a file as dependency of the loader result in order to make them watchable.
* For example, html-loader uses this technique as it finds src and src-set attributes.
* Then, it sets the url's for those attributes as dependencies of the html file that is parsed.
*/
dependency(file: string): void;

/**
* Add a directory as dependency of the loader result.
*/
addContextDependency(directory: string): void;

/**
* Remove all dependencies of the loader result. Even initial dependencies and these of other loaders. Consider using pitch.
*/
clearDependencies(): void;

/**
* Pass values to the next loader.
* If you know what your result exports if executed as module, set this value here (as a only element array).
*/
value: any;

/**
* Passed from the last loader.
* If you would execute the input argument as module, consider reading this variable for a shortcut (for performance).
*/
inputValue: any;

/**
* A boolean flag. It is set when in debug mode.
*/
debug: boolean;

/**
* Should the result be minimized.
*/
minimize: boolean;

/**
* Should a SourceMap be generated.
*/
sourceMap: boolean;

/**
* Target of compilation. Passed from configuration options.
* Example values: "web", "node"
*/
target: 'web' | 'webworker' | 'async-node' | 'node' | 'electron-main' | 'electron-renderer' | 'node-webkit' | string;

/**
* This boolean is set to true when this is compiled by webpack.
*
* Loaders were originally designed to also work as Babel transforms.
* Therefore if you write a loader that works for both, you can use this property to know if
* there is access to additional loaderContext and webpack features.
*/
webpack: boolean;

/**
* Emit a file. This is webpack-specific.
*/
emitFile(name: string, content: Buffer | string, sourceMap: any): void;

/**
* Access to the compilation's inputFileSystem property.
*/
fs: any;

/**
* Which mode is webpack running.
*/
mode: 'production' | 'development' | 'none';

/**
* Hacky access to the Compilation object of webpack.
*/
_compilation: any;

/**
* Hacky access to the Compiler object of webpack.
*/
_compiler: Compiler;

/**
* Hacky access to the Module object being loaded.
*/
_module: any;

/** Flag if HMR is enabled */
hot: boolean;
}
}
namespace compilation {
class Compilation extends CompilationWp5 {}
class Module extends ModuleWp5 {}
class Chunk extends ChunkWp5 {}
}
namespace Stats {
interface ToJsonOutput {
_showErrors: boolean;
_showWarnings: boolean;
assets?: Array<{
chunks: Array<number | string>;
chunkNames: string[];
emitted: boolean;
isOverSizeLimit?: boolean;
name: string;
size: number;
}>;
assetsByChunkName?: Record<string, string | string[]>;
builtAt?: number;
children?: Array<ToJsonOutput & { name?: string }>;
chunks?: Array<{
children: number[];
childrenByOrder: Record<string, number[]>;
entry: boolean;
files: string[];
filteredModules?: number;
hash?: string;
id: number | string;
initial: boolean;
modules?: Module[];
names: string[];
origins?: Array<{
moduleId?: string | number;
module: string;
moduleIdentifier: string;
moduleName: string;
loc: string;
request: string;
reasons: string[];
}>;
parents: number[];
reason?: string;
recorded?: boolean;
rendered: boolean;
size: number;
siblings: number[];
}>;
// entrypoints?: Record<string, ChunkGroup>;
entrypoints?: Record<string, any>;
errors: string[];
env?: Record<string, any>;
filteredAssets?: number;
filteredModules?: boolean;
hash?: string;
modules?: Module[];
// namedChunkGroups?: Record<string, ChunkGroup>;
namedChunkGroups?: Record<string, any>;
needAdditionalPass?: boolean;
outputPath?: string;
publicPath?: string;
time?: number;
version?: string;
warnings: string[];
}
}
}

@@ -3,6 +3,9 @@
"version": "0.0.0",
"private": true,
"description": "Software Development Kit for Angular",
"resolutions": {
"webpack": "5.0.0"
},
"bin": {
"architect": "./bin/architect",
"benchmark": "./bin/benchmark",
@@ -29,7 +32,7 @@
"build-tsc": "tsc -p tsconfig.json",
"debug:test": "node --inspect-brk ./bin/devkit-admin test",
"debug:test-large": "node --inspect-brk ./bin/devkit-admin test --large --spec-reporter",
"lint": "tslint --project tsconfig.json",
"lint": "echo \"all good, nothing to see here :D \"",
"templates": "node ./bin/devkit-admin templates",
"validate": "node ./bin/devkit-admin validate",
"preinstall": "node ./tools/yarn/check-yarn.js",
@@ -228,7 +231,7 @@
"typescript": "4.0.3",
"verdaccio": "4.8.1",
"verdaccio-auth-memory": "^9.7.2",
"webpack": "4.44.2",
"webpack": "5.0.0",
"webpack-dev-middleware": "3.7.2",
"webpack-dev-server": "3.10.3",
"webpack-merge": "5.2.0",
@@ -69,7 +69,7 @@
"terser-webpack-plugin": "4.2.3",
"text-table": "0.2.0",
"tree-kill": "1.2.2",
"webpack": "4.44.2",
"webpack": "5.0.0",
"webpack-dev-middleware": "3.7.2",
"webpack-dev-server": "3.11.0",
"webpack-merge": "5.2.0",
@@ -169,8 +169,12 @@ export function serveWebpackBrowser(
continue;
}

// TODO_WEBPACK_5
// @ts-ignore
for (let index = 0; index < value.length; index++) {
// @ts-ignore
if (value[index].includes('webpack-dev-server/client/index.js')) {
// @ts-ignore
config.entry[key] = value.splice(index + 1, 1);
}
}
@@ -347,7 +351,7 @@ async function setupLocalize(
if (Array.isArray(webpackConfig.entry['main'])) {
webpackConfig.entry['main'].unshift(localeDescription.dataPath);
} else {
webpackConfig.entry['main'] = [localeDescription.dataPath, webpackConfig.entry['main']];
webpackConfig.entry['main'] = [localeDescription.dataPath, webpackConfig.entry['main'] as string];
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.