本文整理匯總了TypeScript中@angular-devkit/build-webpack.WebpackBuilder類的典型用法代碼示例。如果您正苦於以下問題:TypeScript WebpackBuilder類的具體用法?TypeScript WebpackBuilder怎麽用?TypeScript WebpackBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了WebpackBuilder類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: run
run(builderConfig: BuilderConfiguration<BrowserBuilderSchema>): Observable<BuildEvent> {
const options = builderConfig.options;
const root = this.context.workspace.root;
const projectRoot = resolve(root, builderConfig.root);
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host<fs.Stats>);
const webpackBuilder = new WebpackBuilder({ ...this.context, host });
return of(null).pipe(
concatMap(() => options.deleteOutputPath
? this._deleteOutputDir(root, normalize(options.outputPath), this.context.host)
: of(null)),
concatMap(() => normalizeFileReplacements(options.fileReplacements, host, root)),
tap(fileReplacements => options.fileReplacements = fileReplacements),
concatMap(() => normalizeAssetPatterns(
options.assets, host, root, projectRoot, builderConfig.sourceRoot)),
// Replace the assets in options with the normalized version.
tap((assetPatternObjects => options.assets = assetPatternObjects)),
concatMap(() => {
// Ensure Build Optimizer is only used with AOT.
if (options.buildOptimizer && !options.aot) {
throw new Error('The `--build-optimizer` option cannot be used without `--aot`.');
}
let webpackConfig;
try {
webpackConfig = this.buildWebpackConfig(root, projectRoot, host,
options as NormalizedBrowserBuilderSchema);
} catch (e) {
return throwError(e);
}
return webpackBuilder.runWebpack(webpackConfig, getBrowserLoggingCb(options.verbose));
}),
concatMap(buildEvent => {
if (buildEvent.success && !options.watch && options.serviceWorker) {
return new Observable(obs => {
augmentAppWithServiceWorker(
this.context.host,
root,
projectRoot,
resolve(root, normalize(options.outputPath)),
options.baseHref || '/',
options.ngswConfigPath,
).then(
() => {
obs.next({ success: true });
obs.complete();
},
(err: Error) => {
obs.error(err);
},
);
});
} else {
return of(buildEvent);
}
}),
);
}
示例2: run
run(builderConfig: BuilderConfiguration<ExtractI18nBuilderOptions>): Observable<BuildEvent> {
const architect = this.context.architect;
const options = builderConfig.options;
const root = this.context.workspace.root;
const projectRoot = resolve(root, builderConfig.root);
const [project, targetName, configuration] = options.browserTarget.split(':');
// Override browser build watch setting.
const overrides = { watch: false };
const browserTargetSpec = { project, target: targetName, configuration, overrides };
const browserBuilderConfig = architect.getBuilderConfiguration<BrowserBuilderSchema>(
browserTargetSpec);
const webpackBuilder = new WebpackBuilder(this.context);
const loggingCb: LoggingCallback = (stats, config, logger) => {
const json = stats.toJson();
if (stats.hasWarnings()) {
this.context.logger.warn(statsWarningsToString(json, config.stats));
}
if (stats.hasErrors()) {
this.context.logger.error(statsErrorsToString(json, config.stats));
}
};
return architect.getBuilderDescription(browserBuilderConfig).pipe(
concatMap(browserDescription =>
architect.validateBuilderOptions(browserBuilderConfig, browserDescription)),
map(browserBuilderConfig => browserBuilderConfig.options),
concatMap((validatedBrowserOptions) => {
const browserOptions = validatedBrowserOptions;
// We need to determine the outFile name so that AngularCompiler can retrieve it.
let outFile = options.outFile || getI18nOutfile(options.i18nFormat);
if (options.outputPath) {
// AngularCompilerPlugin doesn't support genDir so we have to adjust outFile instead.
outFile = path.join(options.outputPath, outFile);
}
// Extracting i18n uses the browser target webpack config with some specific options.
const webpackConfig = this.buildWebpackConfig(root, projectRoot, {
// todo: remove this casting when 'CurrentFileReplacement' is changed to 'FileReplacement'
...(browserOptions as NormalizedBrowserBuilderSchema),
optimization: false,
i18nLocale: options.i18nLocale,
i18nFormat: options.i18nFormat,
i18nFile: outFile,
aot: true,
progress: options.progress,
assets: [],
scripts: [],
styles: [],
});
return webpackBuilder.runWebpack(webpackConfig, loggingCb);
}),
);
}
示例3: run
run(builderConfig: BuilderConfiguration<BuildWebpackServerSchema>): Observable<BuildEvent> {
const options = builderConfig.options;
const root = this.context.workspace.root;
const projectRoot = resolve(root, builderConfig.root);
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host<Stats>);
const webpackBuilder = new WebpackBuilder({ ...this.context, host });
// TODO: verify using of(null) to kickstart things is a pattern.
return of(null).pipe(
concatMap(() => options.deleteOutputPath
? this._deleteOutputDir(root, normalize(options.outputPath), this.context.host)
: of(null)),
concatMap(() => addFileReplacements(root, host, options.fileReplacements)),
concatMap(() => {
const webpackConfig = this.buildWebpackConfig(root, projectRoot, host, options);
return webpackBuilder.runWebpack(webpackConfig, getBrowserLoggingCb(options.verbose));
}),
);
}
示例4: concatMap
concatMap((validatedBrowserOptions) => {
const browserOptions = validatedBrowserOptions;
// We need to determine the outFile name so that AngularCompiler can retrieve it.
let outFile = options.outFile || getI18nOutfile(options.i18nFormat);
if (options.outputPath) {
// AngularCompilerPlugin doesn't support genDir so we have to adjust outFile instead.
outFile = path.join(options.outputPath, outFile);
}
// Extracting i18n uses the browser target webpack config with some specific options.
const webpackConfig = this.buildWebpackConfig(root, projectRoot, {
// todo: remove this casting when 'CurrentFileReplacement' is changed to 'FileReplacement'
...(browserOptions as NormalizedBrowserBuilderSchema),
optimization: {
scripts: false,
styles: false,
},
i18nLocale: options.i18nLocale,
i18nFormat: options.i18nFormat,
i18nFile: outFile,
aot: true,
progress: options.progress,
assets: [],
scripts: [],
styles: [],
});
return webpackBuilder.runWebpack(webpackConfig, loggingCb);
}),
示例5: throwError
concatMap(() => {
let webpackConfig;
try {
webpackConfig = this.buildWebpackConfig(root, projectRoot, host,
options as NormalizedBrowserBuilderSchema);
} catch (e) {
return throwError(e);
}
return webpackBuilder.runWebpack(webpackConfig, getBrowserLoggingCb(options.verbose));
}),
示例6: Error
concatMap(() => {
// Ensure Build Optimizer is only used with AOT.
if (options.buildOptimizer && !options.aot) {
throw new Error('The `--build-optimizer` option cannot be used without `--aot`.');
}
let webpackConfig;
try {
webpackConfig = this.buildWebpackConfig(root, projectRoot, host,
options as NormalizedBrowserBuilderSchema);
} catch (e) {
return throwError(e);
}
return webpackBuilder.runWebpack(webpackConfig, getBrowserLoggingCb(options.verbose));
}),