@rushstack/heft-webpack4-plugin 0.5.16 → 0.6.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/heft-webpack4-plugin.d.ts +73 -22
- package/heft-plugin.json +20 -0
- package/lib/Webpack4Plugin.d.ts +32 -0
- package/lib/Webpack4Plugin.d.ts.map +1 -0
- package/lib/Webpack4Plugin.js +329 -0
- package/lib/Webpack4Plugin.js.map +1 -0
- package/lib/WebpackConfigurationLoader.d.ts +16 -4
- package/lib/WebpackConfigurationLoader.d.ts.map +1 -1
- package/lib/WebpackConfigurationLoader.js +36 -15
- package/lib/WebpackConfigurationLoader.js.map +1 -1
- package/lib/index.d.ts +2 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -5
- package/lib/index.js.map +1 -1
- package/lib/schemas/heft-webpack4-plugin.schema.json +25 -0
- package/lib/shared.d.ts +66 -16
- package/lib/shared.d.ts.map +1 -1
- package/lib/shared.js.map +1 -1
- package/{dist → lib}/tsdoc-metadata.json +1 -1
- package/package.json +10 -7
- package/lib/WebpackPlugin.d.ts +0 -13
- package/lib/WebpackPlugin.d.ts.map +0 -1
- package/lib/WebpackPlugin.js +0 -198
- package/lib/WebpackPlugin.js.map +0 -1
|
@@ -28,30 +28,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
28
28
|
exports.WebpackConfigurationLoader = void 0;
|
|
29
29
|
const path = __importStar(require("path"));
|
|
30
30
|
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
31
|
-
const
|
|
32
|
-
const
|
|
31
|
+
const DEFAULT_WEBPACK_CONFIG_PATH = './webpack.config.js';
|
|
32
|
+
const DEFAULT_WEBPACK_DEV_CONFIG_PATH = './webpack.dev.config.js';
|
|
33
33
|
class WebpackConfigurationLoader {
|
|
34
|
-
|
|
34
|
+
constructor(logger, production, serveMode) {
|
|
35
|
+
this._logger = logger;
|
|
36
|
+
this._production = production;
|
|
37
|
+
this._serveMode = serveMode;
|
|
38
|
+
}
|
|
39
|
+
async tryLoadWebpackConfigurationAsync(options) {
|
|
35
40
|
// TODO: Eventually replace this custom logic with a call to this utility in in webpack-cli:
|
|
36
41
|
// https://github.com/webpack/webpack-cli/blob/next/packages/webpack-cli/lib/groups/ConfigGroup.js
|
|
42
|
+
const { taskSession, heftConfiguration, configurationPath, devConfigurationPath, loadWebpackAsyncFn } = options;
|
|
37
43
|
let webpackConfigJs;
|
|
38
44
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
const buildFolderPath = heftConfiguration.buildFolderPath;
|
|
46
|
+
if (this._serveMode) {
|
|
47
|
+
const devConfigPath = path.resolve(buildFolderPath, devConfigurationPath || DEFAULT_WEBPACK_DEV_CONFIG_PATH);
|
|
48
|
+
this._logger.terminal.writeVerboseLine(`Attempting to load webpack configuration from "${devConfigPath}".`);
|
|
49
|
+
webpackConfigJs = await this._tryLoadWebpackConfigurationInnerAsync(devConfigPath);
|
|
42
50
|
}
|
|
43
51
|
if (!webpackConfigJs) {
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
const configPath = path.resolve(buildFolderPath, configurationPath || DEFAULT_WEBPACK_CONFIG_PATH);
|
|
53
|
+
this._logger.terminal.writeVerboseLine(`Attempting to load webpack configuration from "${configPath}".`);
|
|
54
|
+
webpackConfigJs = await this._tryLoadWebpackConfigurationInnerAsync(configPath);
|
|
46
55
|
}
|
|
47
56
|
}
|
|
48
57
|
catch (error) {
|
|
49
|
-
|
|
58
|
+
this._logger.emitError(error);
|
|
50
59
|
}
|
|
51
60
|
if (webpackConfigJs) {
|
|
52
61
|
const webpackConfig = webpackConfigJs.default || webpackConfigJs;
|
|
53
62
|
if (typeof webpackConfig === 'function') {
|
|
54
|
-
|
|
63
|
+
// Defer loading of webpack until we know for sure that we will need it
|
|
64
|
+
return webpackConfig({
|
|
65
|
+
prod: this._production,
|
|
66
|
+
production: this._production,
|
|
67
|
+
taskSession,
|
|
68
|
+
heftConfiguration,
|
|
69
|
+
webpack: await loadWebpackAsyncFn()
|
|
70
|
+
});
|
|
55
71
|
}
|
|
56
72
|
else {
|
|
57
73
|
return webpackConfig;
|
|
@@ -61,14 +77,19 @@ class WebpackConfigurationLoader {
|
|
|
61
77
|
return undefined;
|
|
62
78
|
}
|
|
63
79
|
}
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
80
|
+
async _tryLoadWebpackConfigurationInnerAsync(configurationPath) {
|
|
81
|
+
const configExists = await node_core_library_1.FileSystem.existsAsync(configurationPath);
|
|
82
|
+
if (configExists) {
|
|
67
83
|
try {
|
|
68
|
-
return require(
|
|
84
|
+
return await Promise.resolve().then(() => __importStar(require(configurationPath)));
|
|
69
85
|
}
|
|
70
86
|
catch (e) {
|
|
71
|
-
|
|
87
|
+
const error = e;
|
|
88
|
+
if (error.code === 'ERR_MODULE_NOT_FOUND') {
|
|
89
|
+
// No configuration found, return undefined.
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
throw new Error(`Error loading webpack configuration at "${configurationPath}": ${e}`);
|
|
72
93
|
}
|
|
73
94
|
}
|
|
74
95
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebpackConfigurationLoader.js","sourceRoot":"","sources":["../src/WebpackConfigurationLoader.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;
|
|
1
|
+
{"version":3,"file":"WebpackConfigurationLoader.js","sourceRoot":"","sources":["../src/WebpackConfigurationLoader.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAE7B,oEAA0D;AAqB1D,MAAM,2BAA2B,GAA0B,qBAAqB,CAAC;AACjF,MAAM,+BAA+B,GAA8B,yBAAyB,CAAC;AAE7F,MAAa,0BAA0B;IAKrC,YAAmB,MAAqB,EAAE,UAAmB,EAAE,SAAkB;QAC/E,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,gCAAgC,CAC3C,OAAyC;QAEzC,4FAA4F;QAC5F,kGAAkG;QAElG,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,GACnG,OAAO,CAAC;QACV,IAAI,eAA6C,CAAC;QAElD,IAAI;YACF,MAAM,eAAe,GAAW,iBAAiB,CAAC,eAAe,CAAC;YAClE,IAAI,IAAI,CAAC,UAAU,EAAE;gBACnB,MAAM,aAAa,GAAW,IAAI,CAAC,OAAO,CACxC,eAAe,EACf,oBAAoB,IAAI,+BAA+B,CACxD,CAAC;gBACF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CACpC,kDAAkD,aAAa,IAAI,CACpE,CAAC;gBACF,eAAe,GAAG,MAAM,IAAI,CAAC,sCAAsC,CAAC,aAAa,CAAC,CAAC;aACpF;YAED,IAAI,CAAC,eAAe,EAAE;gBACpB,MAAM,UAAU,GAAW,IAAI,CAAC,OAAO,CACrC,eAAe,EACf,iBAAiB,IAAI,2BAA2B,CACjD,CAAC;gBACF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CACpC,kDAAkD,UAAU,IAAI,CACjE,CAAC;gBACF,eAAe,GAAG,MAAM,IAAI,CAAC,sCAAsC,CAAC,UAAU,CAAC,CAAC;aACjF;SACF;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAc,CAAC,CAAC;SACxC;QAED,IAAI,eAAe,EAAE;YACnB,MAAM,aAAa,GAChB,eAAuD,CAAC,OAAO,IAAI,eAAe,CAAC;YAEtF,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE;gBACvC,uEAAuE;gBACvE,OAAO,aAAa,CAAC;oBACnB,IAAI,EAAE,IAAI,CAAC,WAAW;oBACtB,UAAU,EAAE,IAAI,CAAC,WAAW;oBAC5B,WAAW;oBACX,iBAAiB;oBACjB,OAAO,EAAE,MAAM,kBAAkB,EAAE;iBACpC,CAAC,CAAC;aACJ;iBAAM;gBACL,OAAO,aAAa,CAAC;aACtB;SACF;aAAM;YACL,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;IAEO,KAAK,CAAC,sCAAsC,CAClD,iBAAyB;QAEzB,MAAM,YAAY,GAAY,MAAM,8BAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QAC9E,IAAI,YAAY,EAAE;YAChB,IAAI;gBACF,OAAO,wDAAa,iBAAiB,GAAC,CAAC;aACxC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,KAAK,GAA0B,CAA0B,CAAC;gBAChE,IAAI,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE;oBACzC,4CAA4C;oBAC5C,OAAO,SAAS,CAAC;iBAClB;gBACD,MAAM,IAAI,KAAK,CAAC,2CAA2C,iBAAiB,MAAM,CAAC,EAAE,CAAC,CAAC;aACxF;SACF;aAAM;YACL,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;CACF;AAxFD,gEAwFC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as path from 'path';\nimport type * as TWebpack from 'webpack';\nimport { FileSystem } from '@rushstack/node-core-library';\nimport type { IScopedLogger, IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';\n\nimport type { IWebpackPluginOptions } from './Webpack4Plugin';\nimport type { IWebpackConfiguration, IWebpackConfigurationFnEnvironment } from './shared';\n\ntype IWebpackConfigJsExport =\n | TWebpack.Configuration\n | TWebpack.Configuration[]\n | Promise<TWebpack.Configuration>\n | Promise<TWebpack.Configuration[]>\n | ((env: IWebpackConfigurationFnEnvironment) => TWebpack.Configuration | TWebpack.Configuration[])\n | ((env: IWebpackConfigurationFnEnvironment) => Promise<TWebpack.Configuration | TWebpack.Configuration[]>);\ntype IWebpackConfigJs = IWebpackConfigJsExport | { default: IWebpackConfigJsExport };\n\ninterface ILoadWebpackConfigurationOptions extends IWebpackPluginOptions {\n taskSession: IHeftTaskSession;\n heftConfiguration: HeftConfiguration;\n loadWebpackAsyncFn: () => Promise<typeof TWebpack>;\n}\n\nconst DEFAULT_WEBPACK_CONFIG_PATH: './webpack.config.js' = './webpack.config.js';\nconst DEFAULT_WEBPACK_DEV_CONFIG_PATH: './webpack.dev.config.js' = './webpack.dev.config.js';\n\nexport class WebpackConfigurationLoader {\n private readonly _logger: IScopedLogger;\n private readonly _production: boolean;\n private readonly _serveMode: boolean;\n\n public constructor(logger: IScopedLogger, production: boolean, serveMode: boolean) {\n this._logger = logger;\n this._production = production;\n this._serveMode = serveMode;\n }\n\n public async tryLoadWebpackConfigurationAsync(\n options: ILoadWebpackConfigurationOptions\n ): Promise<IWebpackConfiguration | undefined> {\n // TODO: Eventually replace this custom logic with a call to this utility in in webpack-cli:\n // https://github.com/webpack/webpack-cli/blob/next/packages/webpack-cli/lib/groups/ConfigGroup.js\n\n const { taskSession, heftConfiguration, configurationPath, devConfigurationPath, loadWebpackAsyncFn } =\n options;\n let webpackConfigJs: IWebpackConfigJs | undefined;\n\n try {\n const buildFolderPath: string = heftConfiguration.buildFolderPath;\n if (this._serveMode) {\n const devConfigPath: string = path.resolve(\n buildFolderPath,\n devConfigurationPath || DEFAULT_WEBPACK_DEV_CONFIG_PATH\n );\n this._logger.terminal.writeVerboseLine(\n `Attempting to load webpack configuration from \"${devConfigPath}\".`\n );\n webpackConfigJs = await this._tryLoadWebpackConfigurationInnerAsync(devConfigPath);\n }\n\n if (!webpackConfigJs) {\n const configPath: string = path.resolve(\n buildFolderPath,\n configurationPath || DEFAULT_WEBPACK_CONFIG_PATH\n );\n this._logger.terminal.writeVerboseLine(\n `Attempting to load webpack configuration from \"${configPath}\".`\n );\n webpackConfigJs = await this._tryLoadWebpackConfigurationInnerAsync(configPath);\n }\n } catch (error) {\n this._logger.emitError(error as Error);\n }\n\n if (webpackConfigJs) {\n const webpackConfig: IWebpackConfigJsExport =\n (webpackConfigJs as { default: IWebpackConfigJsExport }).default || webpackConfigJs;\n\n if (typeof webpackConfig === 'function') {\n // Defer loading of webpack until we know for sure that we will need it\n return webpackConfig({\n prod: this._production,\n production: this._production,\n taskSession,\n heftConfiguration,\n webpack: await loadWebpackAsyncFn()\n });\n } else {\n return webpackConfig;\n }\n } else {\n return undefined;\n }\n }\n\n private async _tryLoadWebpackConfigurationInnerAsync(\n configurationPath: string\n ): Promise<IWebpackConfigJs | undefined> {\n const configExists: boolean = await FileSystem.existsAsync(configurationPath);\n if (configExists) {\n try {\n return await import(configurationPath);\n } catch (e) {\n const error: NodeJS.ErrnoException = e as NodeJS.ErrnoException;\n if (error.code === 'ERR_MODULE_NOT_FOUND') {\n // No configuration found, return undefined.\n return undefined;\n }\n throw new Error(`Error loading webpack configuration at \"${configurationPath}\": ${e}`);\n }\n } else {\n return undefined;\n }\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export { IWebpackConfigurationWithDevServer, IWebpackConfiguration,
|
|
3
|
-
/**
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
declare const _default: IHeftPlugin<void>;
|
|
7
|
-
export default _default;
|
|
1
|
+
export { PLUGIN_NAME as PluginName } from './Webpack4Plugin';
|
|
2
|
+
export type { IWebpackConfigurationWithDevServer, IWebpackConfiguration, IWebpackConfigurationFnEnvironment, IWebpackPluginAccessor, IWebpackPluginAccessorHooks } from './shared';
|
|
8
3
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE7D,YAAY,EACV,kCAAkC,EAClC,qBAAqB,EACrB,kCAAkC,EAClC,sBAAsB,EACtB,2BAA2B,EAC5B,MAAM,UAAU,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
3
|
// See LICENSE in the project root for license information.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
exports.default = new WebpackPlugin_1.WebpackPlugin();
|
|
5
|
+
exports.PluginName = void 0;
|
|
6
|
+
var Webpack4Plugin_1 = require("./Webpack4Plugin");
|
|
7
|
+
Object.defineProperty(exports, "PluginName", { enumerable: true, get: function () { return Webpack4Plugin_1.PLUGIN_NAME; } });
|
|
10
8
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,mDAA6D;AAApD,4GAAA,WAAW,OAAc","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nexport { PLUGIN_NAME as PluginName } from './Webpack4Plugin';\n\nexport type {\n IWebpackConfigurationWithDevServer,\n IWebpackConfiguration,\n IWebpackConfigurationFnEnvironment,\n IWebpackPluginAccessor,\n IWebpackPluginAccessorHooks\n} from './shared';\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
3
|
+
"title": "Webpack 4 Plugin Configuration",
|
|
4
|
+
"description": "Defines options for Webpack 4 plugin execution.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
|
|
9
|
+
"properties": {
|
|
10
|
+
"$schema": {
|
|
11
|
+
"description": "Part of the JSON Schema standard, this optional keyword declares the URL of the schema that the file conforms to. Editors may download the schema and use it to perform syntax highlighting.",
|
|
12
|
+
"type": "string"
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
"devConfigurationPath": {
|
|
16
|
+
"description": "Specifies a relative path to the Webpack dev configuration, which is used in \"serve\" mode. The default value is \"./webpack.dev.config.js\".",
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
"configurationPath": {
|
|
21
|
+
"description": "Specifies a relative path to the Webpack configuration. The default value is \"./webpack.config.js\".",
|
|
22
|
+
"type": "string"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
package/lib/shared.d.ts
CHANGED
|
@@ -1,44 +1,94 @@
|
|
|
1
|
-
import type * as
|
|
1
|
+
import type * as TWebpack from 'webpack';
|
|
2
2
|
declare module 'webpack' {
|
|
3
|
-
type MultiStats =
|
|
3
|
+
type MultiStats = TWebpack.compilation.MultiStats;
|
|
4
4
|
type StatsOptions = unknown;
|
|
5
|
-
type StatsCompilation =
|
|
5
|
+
type StatsCompilation = TWebpack.compilation.Compilation;
|
|
6
6
|
interface Compiler {
|
|
7
7
|
watching?: unknown;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
import type { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
|
|
11
|
-
import type {
|
|
11
|
+
import type { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook } from 'tapable';
|
|
12
|
+
import type { IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';
|
|
12
13
|
/**
|
|
14
|
+
* The environment passed into the Webpack configuration function. Loosely based
|
|
15
|
+
* on the default Webpack environment options, specified here:
|
|
16
|
+
* https://webpack.js.org/api/cli/#environment-options
|
|
17
|
+
*
|
|
13
18
|
* @public
|
|
14
19
|
*/
|
|
15
|
-
export interface
|
|
20
|
+
export interface IWebpackConfigurationFnEnvironment {
|
|
21
|
+
/**
|
|
22
|
+
* Whether or not the run is in production mode. Synonym of
|
|
23
|
+
* IWebpackConfigurationFnEnvironment.production.
|
|
24
|
+
*/
|
|
25
|
+
prod: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether or not the run is in production mode. Synonym of
|
|
28
|
+
* IWebpackConfigurationFnEnvironment.prod.
|
|
29
|
+
*/
|
|
30
|
+
production: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The task session provided to the plugin.
|
|
33
|
+
*/
|
|
34
|
+
taskSession: IHeftTaskSession;
|
|
35
|
+
/**
|
|
36
|
+
* The Heft configuration provided to the plugin.
|
|
37
|
+
*/
|
|
38
|
+
heftConfiguration: HeftConfiguration;
|
|
39
|
+
/**
|
|
40
|
+
* The resolved Webpack package.
|
|
41
|
+
*/
|
|
42
|
+
webpack: typeof TWebpack;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export interface IWebpackConfigurationWithDevServer extends TWebpack.Configuration {
|
|
16
48
|
devServer?: WebpackDevServerConfiguration;
|
|
17
49
|
}
|
|
18
50
|
/**
|
|
19
51
|
* @public
|
|
20
52
|
*/
|
|
21
|
-
export declare type IWebpackConfiguration = IWebpackConfigurationWithDevServer | IWebpackConfigurationWithDevServer[]
|
|
53
|
+
export declare type IWebpackConfiguration = IWebpackConfigurationWithDevServer | IWebpackConfigurationWithDevServer[];
|
|
22
54
|
/**
|
|
23
55
|
* @public
|
|
24
56
|
*/
|
|
25
|
-
export interface
|
|
57
|
+
export interface IWebpackPluginAccessorHooks {
|
|
26
58
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
59
|
+
* A hook that allows for loading custom configurations used by the Webpack
|
|
60
|
+
* plugin. If a webpack configuration is provided, this will be populated automatically
|
|
61
|
+
* with the exports of the config file. If a webpack configuration is not provided,
|
|
62
|
+
* one will be loaded by the Webpack plugin.
|
|
31
63
|
*
|
|
32
64
|
* @remarks
|
|
33
|
-
* Tapable event handlers can return `
|
|
34
|
-
* other handlers from creating a configuration object.
|
|
65
|
+
* Tapable event handlers can return `false` instead of `undefined` to suppress
|
|
66
|
+
* other handlers from creating a configuration object, and prevent webpack from running.
|
|
35
67
|
*/
|
|
36
|
-
|
|
68
|
+
readonly onLoadConfiguration: AsyncSeriesBailHook<never, never, never, IWebpackConfiguration | false>;
|
|
69
|
+
/**
|
|
70
|
+
* A hook that allows for modification of the loaded configuration used by the Webpack
|
|
71
|
+
* plugin. If no configuration was loaded, this hook will not be called.
|
|
72
|
+
*/
|
|
73
|
+
readonly onConfigure: AsyncSeriesHook<IWebpackConfiguration, never, never>;
|
|
74
|
+
/**
|
|
75
|
+
* A hook that provides the finalized configuration that will be used by Webpack.
|
|
76
|
+
* If no configuration was loaded, this hook will not be called.
|
|
77
|
+
*/
|
|
78
|
+
readonly onAfterConfigure: AsyncParallelHook<IWebpackConfiguration, never, never>;
|
|
79
|
+
/**
|
|
80
|
+
* A hook that provides the stats output from Webpack. If no configuration is loaded,
|
|
81
|
+
* this hook will not be called.
|
|
82
|
+
*/
|
|
83
|
+
readonly onEmitStats: AsyncParallelHook<TWebpack.Stats | TWebpack.compilation.MultiStats, never, never>;
|
|
37
84
|
}
|
|
38
85
|
/**
|
|
39
86
|
* @public
|
|
40
87
|
*/
|
|
41
|
-
export interface
|
|
42
|
-
|
|
88
|
+
export interface IWebpackPluginAccessor {
|
|
89
|
+
/**
|
|
90
|
+
* Hooks that are called at various points in the Webpack plugin lifecycle.
|
|
91
|
+
*/
|
|
92
|
+
hooks: IWebpackPluginAccessorHooks;
|
|
43
93
|
}
|
|
44
94
|
//# sourceMappingURL=shared.d.ts.map
|
package/lib/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,QAAQ,MAAM,SAAS,CAAC;AAEzC,OAAO,QAAQ,SAAS,CAAC;IACvB,KAAY,UAAU,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC;IACzD,KAAY,YAAY,GAAG,OAAO,CAAC;IACnC,KAAY,gBAAgB,GAAG,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC;IAGhE,UAAiB,QAAQ;QACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB;CACF;AACD,OAAO,KAAK,EAAE,aAAa,IAAI,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3E;;;;;;GAMG;AACH,MAAM,WAAW,kCAAkC;IACjD;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,UAAU,EAAE,OAAO,CAAC;IAGpB;;OAEG;IACH,WAAW,EAAE,gBAAgB,CAAC;IAC9B;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;IACrC;;OAEG;IACH,OAAO,EAAE,OAAO,QAAQ,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,kCAAmC,SAAQ,QAAQ,CAAC,aAAa;IAChF,SAAS,CAAC,EAAE,6BAA6B,CAAC;CAC3C;AAED;;GAEG;AACH,oBAAY,qBAAqB,GAAG,kCAAkC,GAAG,kCAAkC,EAAE,CAAC;AAE9G;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;;;;;;;OASG;IACH,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,qBAAqB,GAAG,KAAK,CAAC,CAAC;IACtG;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC,qBAAqB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC3E;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,qBAAqB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClF;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;CACzG;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,KAAK,EAAE,2BAA2B,CAAC;CACpC"}
|
package/lib/shared.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type * as
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type * as TWebpack from 'webpack';\n// Compensate for webpack-dev-server referencing constructs from webpack 5\ndeclare module 'webpack' {\n export type MultiStats = TWebpack.compilation.MultiStats;\n export type StatsOptions = unknown;\n export type StatsCompilation = TWebpack.compilation.Compilation;\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n export interface Compiler {\n watching?: unknown;\n }\n}\nimport type { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';\nimport type { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook } from 'tapable';\nimport type { IHeftTaskSession, HeftConfiguration } from '@rushstack/heft';\n\n/**\n * The environment passed into the Webpack configuration function. Loosely based\n * on the default Webpack environment options, specified here:\n * https://webpack.js.org/api/cli/#environment-options\n *\n * @public\n */\nexport interface IWebpackConfigurationFnEnvironment {\n /**\n * Whether or not the run is in production mode. Synonym of\n * IWebpackConfigurationFnEnvironment.production.\n */\n prod: boolean;\n /**\n * Whether or not the run is in production mode. Synonym of\n * IWebpackConfigurationFnEnvironment.prod.\n */\n production: boolean;\n\n // Non-standard environment options\n /**\n * The task session provided to the plugin.\n */\n taskSession: IHeftTaskSession;\n /**\n * The Heft configuration provided to the plugin.\n */\n heftConfiguration: HeftConfiguration;\n /**\n * The resolved Webpack package.\n */\n webpack: typeof TWebpack;\n}\n\n/**\n * @public\n */\nexport interface IWebpackConfigurationWithDevServer extends TWebpack.Configuration {\n devServer?: WebpackDevServerConfiguration;\n}\n\n/**\n * @public\n */\nexport type IWebpackConfiguration = IWebpackConfigurationWithDevServer | IWebpackConfigurationWithDevServer[];\n\n/**\n * @public\n */\nexport interface IWebpackPluginAccessorHooks {\n /**\n * A hook that allows for loading custom configurations used by the Webpack\n * plugin. If a webpack configuration is provided, this will be populated automatically\n * with the exports of the config file. If a webpack configuration is not provided,\n * one will be loaded by the Webpack plugin.\n *\n * @remarks\n * Tapable event handlers can return `false` instead of `undefined` to suppress\n * other handlers from creating a configuration object, and prevent webpack from running.\n */\n readonly onLoadConfiguration: AsyncSeriesBailHook<never, never, never, IWebpackConfiguration | false>;\n /**\n * A hook that allows for modification of the loaded configuration used by the Webpack\n * plugin. If no configuration was loaded, this hook will not be called.\n */\n readonly onConfigure: AsyncSeriesHook<IWebpackConfiguration, never, never>;\n /**\n * A hook that provides the finalized configuration that will be used by Webpack.\n * If no configuration was loaded, this hook will not be called.\n */\n readonly onAfterConfigure: AsyncParallelHook<IWebpackConfiguration, never, never>;\n /**\n * A hook that provides the stats output from Webpack. If no configuration is loaded,\n * this hook will not be called.\n */\n readonly onEmitStats: AsyncParallelHook<TWebpack.Stats | TWebpack.compilation.MultiStats, never, never>;\n}\n\n/**\n * @public\n */\nexport interface IWebpackPluginAccessor {\n /**\n * Hooks that are called at various points in the Webpack plugin lifecycle.\n */\n hooks: IWebpackPluginAccessorHooks;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/heft-webpack4-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-dev.1",
|
|
4
4
|
"description": "Heft plugin for Webpack 4",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://rushstack.io/pages/heft/overview/",
|
|
11
11
|
"main": "lib/index.js",
|
|
12
|
-
"types": "
|
|
12
|
+
"types": "lib/index.d.ts",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"peerDependenciesMeta": {
|
|
15
15
|
"@types/webpack": {
|
|
@@ -17,18 +17,21 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@rushstack/heft": "^0.
|
|
20
|
+
"@rushstack/heft": "^0.48.0-dev.0",
|
|
21
21
|
"@types/webpack": "^4",
|
|
22
22
|
"webpack": "~4.44.2"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@rushstack/debug-certificate-manager": "1.1.76",
|
|
25
26
|
"@rushstack/node-core-library": "3.52.0",
|
|
27
|
+
"@types/tapable": "1.0.6",
|
|
28
|
+
"tapable": "1.1.3",
|
|
26
29
|
"webpack-dev-server": "~4.9.3"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
32
|
"@rushstack/eslint-config": "3.0.1",
|
|
30
|
-
"@rushstack/heft-node-rig": "1.
|
|
31
|
-
"@rushstack/heft": "0.
|
|
33
|
+
"@rushstack/heft-node-rig": "1.11.0-dev.1",
|
|
34
|
+
"@rushstack/heft": "0.48.0-dev.1",
|
|
32
35
|
"@types/node": "12.20.24",
|
|
33
36
|
"@types/webpack": "4.41.32",
|
|
34
37
|
"webpack": "~4.44.2"
|
|
@@ -36,7 +39,7 @@
|
|
|
36
39
|
"scripts": {
|
|
37
40
|
"build": "heft build --clean",
|
|
38
41
|
"start": "heft test --clean --watch",
|
|
39
|
-
"_phase:build": "heft build --clean",
|
|
40
|
-
"_phase:test": "heft test --
|
|
42
|
+
"_phase:build": "heft run --only build -- --clean",
|
|
43
|
+
"_phase:test": "heft run --only test -- --clean"
|
|
41
44
|
}
|
|
42
45
|
}
|
package/lib/WebpackPlugin.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { HeftConfiguration, HeftSession, IHeftPlugin } from '@rushstack/heft';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export declare class WebpackPlugin implements IHeftPlugin {
|
|
6
|
-
readonly pluginName: string;
|
|
7
|
-
private static _webpackVersions;
|
|
8
|
-
private static _getWebpackVersions;
|
|
9
|
-
apply(heftSession: HeftSession, heftConfiguration: HeftConfiguration): void;
|
|
10
|
-
private _runWebpackAsync;
|
|
11
|
-
private _emitErrors;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=WebpackPlugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebpackPlugin.d.ts","sourceRoot":"","sources":["../src/WebpackPlugin.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,iBAAiB,EACjB,WAAW,EAIX,WAAW,EAEZ,MAAM,iBAAiB,CAAC;AAmBzB;;GAEG;AACH,qBAAa,aAAc,YAAW,WAAW;IAC/C,SAAgB,UAAU,EAAE,MAAM,CAAe;IAEjD,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA+B;IAC9D,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAkB3B,KAAK,CAAC,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,GAAG,IAAI;YA0CpE,gBAAgB;IAgK9B,OAAO,CAAC,WAAW;CAapB"}
|
package/lib/WebpackPlugin.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
-
// See LICENSE in the project root for license information.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.WebpackPlugin = void 0;
|
|
6
|
-
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
7
|
-
const WebpackConfigurationLoader_1 = require("./WebpackConfigurationLoader");
|
|
8
|
-
const webpack = node_core_library_1.Import.lazy('webpack', require);
|
|
9
|
-
const PLUGIN_NAME = 'WebpackPlugin';
|
|
10
|
-
const WEBPACK_DEV_SERVER_PACKAGE_NAME = 'webpack-dev-server';
|
|
11
|
-
const WEBPACK_DEV_SERVER_ENV_VAR_NAME = 'WEBPACK_DEV_SERVER';
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
class WebpackPlugin {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.pluginName = PLUGIN_NAME;
|
|
18
|
-
}
|
|
19
|
-
static _getWebpackVersions() {
|
|
20
|
-
if (!WebpackPlugin._webpackVersions) {
|
|
21
|
-
const webpackDevServerPackageJsonPath = node_core_library_1.Import.resolveModule({
|
|
22
|
-
modulePath: 'webpack-dev-server/package.json',
|
|
23
|
-
baseFolderPath: __dirname
|
|
24
|
-
});
|
|
25
|
-
const webpackDevServerPackageJson = node_core_library_1.PackageJsonLookup.instance.loadPackageJson(webpackDevServerPackageJsonPath);
|
|
26
|
-
WebpackPlugin._webpackVersions = {
|
|
27
|
-
webpackVersion: webpack.version,
|
|
28
|
-
webpackDevServerVersion: webpackDevServerPackageJson.version
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
return WebpackPlugin._webpackVersions;
|
|
32
|
-
}
|
|
33
|
-
apply(heftSession, heftConfiguration) {
|
|
34
|
-
heftSession.hooks.build.tap(PLUGIN_NAME, (build) => {
|
|
35
|
-
build.hooks.bundle.tap(PLUGIN_NAME, (bundle) => {
|
|
36
|
-
bundle.hooks.configureWebpack.tap({ name: PLUGIN_NAME, stage: Number.MIN_SAFE_INTEGER }, (webpackConfiguration) => {
|
|
37
|
-
const webpackVersions = WebpackPlugin._getWebpackVersions();
|
|
38
|
-
bundle.properties.webpackVersion = webpack.version;
|
|
39
|
-
bundle.properties.webpackDevServerVersion = webpackVersions.webpackDevServerVersion;
|
|
40
|
-
return webpackConfiguration;
|
|
41
|
-
});
|
|
42
|
-
bundle.hooks.configureWebpack.tapPromise(PLUGIN_NAME, async (existingConfiguration) => {
|
|
43
|
-
const logger = heftSession.requestScopedLogger('configure-webpack');
|
|
44
|
-
if (existingConfiguration) {
|
|
45
|
-
logger.terminal.writeVerboseLine('Skipping loading webpack config file because the webpack config has already been set.');
|
|
46
|
-
return existingConfiguration;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
return await WebpackConfigurationLoader_1.WebpackConfigurationLoader.tryLoadWebpackConfigAsync(logger, heftConfiguration.buildFolder, build.properties);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
bundle.hooks.run.tapPromise(PLUGIN_NAME, async () => {
|
|
53
|
-
await this._runWebpackAsync(heftSession, bundle.properties, build.properties, heftConfiguration.terminalProvider.supportsColor);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
async _runWebpackAsync(heftSession, bundleSubstageProperties, buildProperties, supportsColor) {
|
|
59
|
-
const webpackConfiguration = bundleSubstageProperties.webpackConfiguration;
|
|
60
|
-
if (!webpackConfiguration) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const logger = heftSession.requestScopedLogger('webpack');
|
|
64
|
-
const webpackVersions = WebpackPlugin._getWebpackVersions();
|
|
65
|
-
if (bundleSubstageProperties.webpackVersion !== webpackVersions.webpackVersion) {
|
|
66
|
-
logger.emitError(new Error(`The Webpack plugin expected to be configured with Webpack version ${webpackVersions.webpackVersion}, ` +
|
|
67
|
-
`but the configuration specifies version ${bundleSubstageProperties.webpackVersion}. ` +
|
|
68
|
-
'Are multiple versions of the Webpack plugin present?'));
|
|
69
|
-
}
|
|
70
|
-
if (bundleSubstageProperties.webpackDevServerVersion !== webpackVersions.webpackDevServerVersion) {
|
|
71
|
-
logger.emitError(new Error(`The Webpack plugin expected to be configured with webpack-dev-server version ${webpackVersions.webpackDevServerVersion}, ` +
|
|
72
|
-
`but the configuration specifies version ${bundleSubstageProperties.webpackDevServerVersion}. ` +
|
|
73
|
-
'Are multiple versions of the Webpack plugin present?'));
|
|
74
|
-
}
|
|
75
|
-
logger.terminal.writeLine(`Using Webpack version ${webpack.version}`);
|
|
76
|
-
let compiler;
|
|
77
|
-
if (Array.isArray(webpackConfiguration)) {
|
|
78
|
-
if (webpackConfiguration.length === 0) {
|
|
79
|
-
logger.terminal.writeLine('The webpack configuration received is an empty array - nothing to do.');
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
compiler = webpack(webpackConfiguration); /* (webpack.Compilation[]) => MultiCompiler */
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
compiler = webpack(webpackConfiguration); /* (webpack.Compilation) => Compiler */
|
|
88
|
-
}
|
|
89
|
-
if (buildProperties.serveMode) {
|
|
90
|
-
const defaultDevServerOptions = {
|
|
91
|
-
host: 'localhost',
|
|
92
|
-
devMiddleware: {
|
|
93
|
-
publicPath: '/',
|
|
94
|
-
stats: {
|
|
95
|
-
cached: false,
|
|
96
|
-
cachedAssets: false,
|
|
97
|
-
colors: supportsColor
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
client: {
|
|
101
|
-
logging: 'info'
|
|
102
|
-
},
|
|
103
|
-
port: 8080
|
|
104
|
-
};
|
|
105
|
-
let options;
|
|
106
|
-
if (Array.isArray(webpackConfiguration)) {
|
|
107
|
-
const devServerOptions = webpackConfiguration
|
|
108
|
-
.map((configuration) => configuration.devServer)
|
|
109
|
-
.filter((devServer) => !!devServer);
|
|
110
|
-
if (devServerOptions.length > 1) {
|
|
111
|
-
logger.emitWarning(new Error(`Detected multiple webpack devServer configurations, using the first one.`));
|
|
112
|
-
}
|
|
113
|
-
if (devServerOptions.length > 0) {
|
|
114
|
-
options = Object.assign(Object.assign({}, defaultDevServerOptions), devServerOptions[0]);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
options = defaultDevServerOptions;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
options = Object.assign(Object.assign({}, defaultDevServerOptions), webpackConfiguration.devServer);
|
|
122
|
-
}
|
|
123
|
-
// Register a plugin to callback after webpack is done with the first compilation
|
|
124
|
-
// so we can move on to post-build
|
|
125
|
-
let firstCompilationDoneCallback;
|
|
126
|
-
const originalBeforeCallback = options.onBeforeSetupMiddleware;
|
|
127
|
-
options.onBeforeSetupMiddleware = (server) => {
|
|
128
|
-
compiler.hooks.done.tap('heft-webpack-plugin', () => {
|
|
129
|
-
if (firstCompilationDoneCallback) {
|
|
130
|
-
firstCompilationDoneCallback();
|
|
131
|
-
firstCompilationDoneCallback = undefined;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
if (originalBeforeCallback) {
|
|
135
|
-
return originalBeforeCallback(server);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
// The webpack-dev-server package has a design flaw, where merely loading its package will set the
|
|
139
|
-
// WEBPACK_DEV_SERVER environment variable -- even if no APIs are accessed. This environment variable
|
|
140
|
-
// causes incorrect behavior if Heft is not running in serve mode. Thus, we need to be careful to call require()
|
|
141
|
-
// only if Heft is in serve mode.
|
|
142
|
-
const WebpackDevServer = require(WEBPACK_DEV_SERVER_PACKAGE_NAME);
|
|
143
|
-
// TODO: the WebpackDevServer accepts a third parameter for a logger. We should make
|
|
144
|
-
// use of that to make logging cleaner
|
|
145
|
-
const webpackDevServer = new WebpackDevServer(compiler, options);
|
|
146
|
-
await new Promise((resolve, reject) => {
|
|
147
|
-
firstCompilationDoneCallback = resolve;
|
|
148
|
-
webpackDevServer.listen(options.port, options.host, (error) => {
|
|
149
|
-
if (error) {
|
|
150
|
-
reject(error);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
if (process.env[WEBPACK_DEV_SERVER_ENV_VAR_NAME]) {
|
|
157
|
-
logger.emitWarning(new Error(`The "${WEBPACK_DEV_SERVER_ENV_VAR_NAME}" environment variable is set, ` +
|
|
158
|
-
'which will cause problems when webpack is not running in serve mode. ' +
|
|
159
|
-
`(Did a dependency inadvertently load the "${WEBPACK_DEV_SERVER_PACKAGE_NAME}" package?)`));
|
|
160
|
-
}
|
|
161
|
-
let stats;
|
|
162
|
-
if (buildProperties.watchMode) {
|
|
163
|
-
try {
|
|
164
|
-
stats = await node_core_library_1.LegacyAdapters.convertCallbackToPromise(compiler.watch.bind(compiler), {});
|
|
165
|
-
}
|
|
166
|
-
catch (e) {
|
|
167
|
-
logger.emitError(e);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
try {
|
|
172
|
-
stats = await node_core_library_1.LegacyAdapters.convertCallbackToPromise(compiler.run.bind(compiler));
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
logger.emitError(e);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (stats) {
|
|
179
|
-
// eslint-disable-next-line require-atomic-updates
|
|
180
|
-
buildProperties.webpackStats = stats;
|
|
181
|
-
this._emitErrors(logger, stats);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
_emitErrors(logger, stats) {
|
|
186
|
-
if (stats.hasErrors() || stats.hasWarnings()) {
|
|
187
|
-
const serializedStats = stats.toJson('errors-warnings');
|
|
188
|
-
for (const warning of serializedStats.warnings) {
|
|
189
|
-
logger.emitWarning(warning instanceof Error ? warning : new Error(warning));
|
|
190
|
-
}
|
|
191
|
-
for (const error of serializedStats.errors) {
|
|
192
|
-
logger.emitError(error instanceof Error ? error : new Error(error));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.WebpackPlugin = WebpackPlugin;
|
|
198
|
-
//# sourceMappingURL=WebpackPlugin.js.map
|