@@ -26,7 +26,7 @@ import {
2626import { IndexHtmlWebpackPlugin } from '@angular-devkit/build-angular/src/angular-cli-files/plugins/index-html-webpack-plugin' ;
2727import { getSystemPath , logging , normalize , tags } from '@angular-devkit/core' ;
2828import { NodeJsSyncHost } from '@angular-devkit/core/node' ;
29- import { AngularWebpack , WebpackSetup } from '@teambit/angular' ;
29+ import { AngularWebpack , optionValue , WebpackSetup } from '@teambit/angular' ;
3030import { BundlerContext , DevServerContext } from '@teambit/bundler' ;
3131import { CompositionsMain } from '@teambit/compositions' ;
3232import { Logger } from '@teambit/logger' ;
@@ -67,66 +67,11 @@ export class AngularV10Webpack extends AngularWebpack {
6767 * Migrate options from webpack-dev-server 3 to 4
6868 */
6969 private migrateConfiguration ( webpackConfig : Configuration ) : Configuration {
70- // /**
71- // * Removed logLevel in favor of built-in logger
72- // * see https://webpack.js.org/configuration/other-options/#infrastructurelogginglevel
73- // */
74- // // @ts -ignore
75- // delete webpackConfig.devServer.logLevel;
76- //
7770 /**
7871 * Removed contentBase in favor of the static option
7972 */
8073 // @ts -ignore
8174 delete webpackConfig . devServer . contentBase ;
82- //
83- // /**
84- // * Removed publicPath in favor of the dev option
85- // */
86- // // @ts -ignore
87- // delete webpackConfig.devServer.publicPath;
88- //
89- // /**
90- // * Moved overlay to client option
91- // */
92- // // @ts -ignore
93- // webpackConfig.devServer.client = webpackConfig.devServer.client || {};
94- // // @ts -ignore
95- // webpackConfig.devServer.client.overlay = webpackConfig.devServer.overlay;
96- // // @ts -ignore
97- // delete webpackConfig.devServer.overlay;
98- //
99- // /**
100- // * Removed in favor of the static option
101- // */
102- // // @ts -ignore
103- // delete webpackConfig.devServer.watchOptions;
104- //
105- // /**
106- // * Moved sockPath to client option path
107- // */
108- // // @ts -ignore
109- // webpackConfig.devServer.client.path = webpackConfig.devServer.sockPath;
110- // // @ts -ignore
111- // delete webpackConfig.devServer.sockPath;
112- //
113- // /**
114- // * Removed stats in favor of the stats options from webpack
115- // */
116- // // @ts -ignore
117- // delete webpackConfig.devServer.stats;
118- //
119- // /**
120- // * Cleaning up undefined values
121- // */
122- // // @ts -ignore
123- // Object.keys(webpackConfig.devServer).forEach(option => {
124- // // @ts -ignore
125- // if (typeof webpackConfig.devServer[option] === 'undefined') {
126- // // @ts -ignore
127- // delete webpackConfig.devServer[option];
128- // }
129- // })
13075
13176 return webpackConfig ;
13277 }
@@ -138,34 +83,32 @@ export class AngularV10Webpack extends AngularWebpack {
13883 workspaceRoot : string ,
13984 logger : Logger ,
14085 setup : WebpackSetup ,
141- extraOptions : Partial < WebpackConfigWithDevServer > = { }
86+ webpackOptions : Partial < WebpackConfigWithDevServer > = { } ,
87+ angularOptions : Partial < BrowserBuilderSchema > = { }
14288 ) : Promise < WebpackConfigWithDevServer | Configuration > {
14389 // Options from angular.json
14490 const browserOptions : BrowserBuilderSchema = {
91+ ...angularOptions ,
14592 baseHref : path . posix . join ( '/' , context . rootPath ! , context . publicPath ! ) ,
14693 preserveSymlinks : true ,
14794 outputPath : 'public' , // doesn't matter because it will be deleted from the config
14895 index : 'src/index.html' ,
14996 main : 'src/main.ts' ,
15097 polyfills : 'src/polyfills.ts' ,
15198 tsConfig : tsconfigPath ,
152- assets : [ 'src/favicon.ico' , 'src/assets' ] ,
153- styles : [ 'src/styles.scss' ] ,
154- scripts : [ ] ,
155- vendorChunk : true ,
156- namedChunks : true ,
157- optimization : setup === WebpackSetup . Build ,
158- buildOptimizer : setup === WebpackSetup . Build ,
159- aot : true ,
160- deleteOutputPath : true ,
161- sourceMap : setup === WebpackSetup . Serve ,
162- outputHashing : setup === WebpackSetup . Build ? OutputHashing . All : OutputHashing . None ,
163- // inlineStyleLanguage: InlineStyleLanguage.Scss,
99+ assets : [ 'src/favicon.ico' , 'src/assets' , ...( angularOptions . assets || [ ] ) ] ,
100+ styles : [ 'src/styles.scss' , ...( angularOptions . styles || [ ] ) ] ,
101+ scripts : angularOptions . scripts ,
102+ vendorChunk : optionValue ( angularOptions . vendorChunk , true ) ,
103+ namedChunks : optionValue ( angularOptions . namedChunks , true ) ,
104+ optimization : optionValue ( angularOptions . optimization , setup === WebpackSetup . Build ) ,
105+ buildOptimizer : optionValue ( angularOptions . buildOptimizer , setup === WebpackSetup . Build ) ,
106+ aot : optionValue ( angularOptions . aot , true ) ,
107+ deleteOutputPath : optionValue ( angularOptions . deleteOutputPath , true ) ,
108+ sourceMap : optionValue ( angularOptions . sourceMap , setup === WebpackSetup . Serve ) ,
109+ outputHashing : optionValue ( angularOptions . outputHashing , setup === WebpackSetup . Build ? OutputHashing . All : OutputHashing . None ) ,
164110 watch : setup === WebpackSetup . Serve ,
165- allowedCommonJsDependencies : [ '@teambit/harmony' , 'graphql' ] ,
166- // deployUrl: undefined,
167- // subresourceIntegrity: undefined,
168- // crossOrigin: undefined,
111+ allowedCommonJsDependencies : [ '@teambit/harmony' , 'graphql' , ...( angularOptions . allowedCommonJsDependencies || [ ] ) ] ,
169112 } ;
170113
171114 const normalizedWorkspaceRoot = normalize ( workspaceRoot ) ;
@@ -175,7 +118,7 @@ export class AngularV10Webpack extends AngularWebpack {
175118 const host = new NodeJsSyncHost ( ) ;
176119 const normalizedOptions = normalizeBrowserSchema ( host , normalizedWorkspaceRoot , projectRoot , sourceRoot , {
177120 ...browserOptions ,
178- ...( extraOptions as Partial < BrowserBuilderSchema & DevServerBuilderOptions > ) ,
121+ ...( webpackOptions as Partial < BrowserBuilderSchema & DevServerBuilderOptions > ) ,
179122 } ) ;
180123
181124 const loggerApi = {
@@ -205,7 +148,7 @@ export class AngularV10Webpack extends AngularWebpack {
205148 if ( setup === WebpackSetup . Serve ) {
206149 webpackConfig . devServer = buildServerConfig (
207150 normalizedWorkspaceRoot ,
208- extraOptions as DevServerBuilderOptions ,
151+ webpackOptions as DevServerBuilderOptions ,
209152 browserOptions ,
210153 loggerApi
211154 ) ;
@@ -215,7 +158,7 @@ export class AngularV10Webpack extends AngularWebpack {
215158 webpackConfig . entry . main . unshift ( ...entryFiles ) ;
216159
217160 // @ts -ignore
218- if ( extraOptions . liveReload && ! extraOptions . hmr ) {
161+ if ( webpackOptions . liveReload && ! webpackOptions . hmr ) {
219162 // This is needed because we cannot use the inline option directly in the config
220163 // because of the SuppressExtractedTextChunksWebpackPlugin
221164 // Consider not using SuppressExtractedTextChunksWebpackPlugin when liveReload is enable.
@@ -250,7 +193,7 @@ export class AngularV10Webpack extends AngularWebpack {
250193 }
251194
252195 // @ts -ignore
253- if ( extraOptions . hmr ) {
196+ if ( webpackOptions . hmr ) {
254197 logger . warn ( tags . stripIndents `NOTICE: Hot Module Replacement (HMR) is enabled for the dev server.
255198 See https://webpack.js.org/guides/hot-module-replacement for information on working with HMR for Webpack.` ) ;
256199 }
0 commit comments