@teambit/webpack 1.0.107 → 1.0.108

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.
@@ -71,7 +71,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
71
71
  /* eslint-disable complexity */
72
72
 
73
73
  function configFactory(target, context) {
74
- var _target$chunking;
75
74
  let truthyEntries = Array.isArray(target.entries) && target.entries.length ? target.entries.filter(Boolean) : target.entries || {};
76
75
  if (Array.isArray(truthyEntries) && !truthyEntries.length) {
77
76
  truthyEntries = {};
@@ -80,7 +79,7 @@ function configFactory(target, context) {
80
79
  const htmlConfig = target.html ?? context.html;
81
80
  const compress = target.compress ?? context.compress;
82
81
  const htmlPlugins = htmlConfig ? generateHtmlPlugins(htmlConfig) : undefined;
83
- const splitChunks = (_target$chunking = target.chunking) === null || _target$chunking === void 0 ? void 0 : _target$chunking.splitChunks;
82
+ const splitChunks = target.chunking?.splitChunks;
84
83
  const config = {
85
84
  mode: dev ? 'development' : 'production',
86
85
  // Stop compilation early in production
@@ -1 +1 @@
1
- {"version":3,"names":["_webpack","data","_interopRequireDefault","require","_lodash","_compressionWebpackPlugin","_path","_htmlWebpackPlugin","_webpackAssetsManifest","_webpackFallbacks","_webpackFallbacksProvidePluginConfig","_webpackFallbacksAliases","obj","__esModule","default","configFactory","target","context","_target$chunking","truthyEntries","Array","isArray","entries","length","filter","Boolean","dev","development","htmlConfig","html","compress","htmlPlugins","generateHtmlPlugins","undefined","splitChunks","chunking","config","mode","bail","entry","infrastructureLogging","level","output","path","outputPath","sep","stats","errorDetails","resolve","alias","fallbacksAliases","fallback","fallbacks","plugins","webpack","ProvidePlugin","fallbacksProvidePluginConfig","getAssetManifestPlugin","filename","chunkFilename","runtimeChunkName","optimization","runtimeChunk","name","chunks","concat","CompressionPlugin","WebpackAssetsManifest","entrypoints","configs","map","generateHtmlPlugin","baseConfig","chunksSortMode","chunkOrder","title","templateContent","minify","cache","favicon","filteredConfig","omitBy","isUndefined","HtmlWebpackPlugin"],"sources":["webpack.config.ts"],"sourcesContent":["/* eslint-disable complexity */\nimport webpack, { Configuration } from 'webpack';\nimport { isUndefined, omitBy } from 'lodash';\nimport CompressionPlugin from 'compression-webpack-plugin';\nimport { sep } from 'path';\nimport type { BundlerContext, BundlerHtmlConfig, Target } from '@teambit/bundler';\nimport HtmlWebpackPlugin from 'html-webpack-plugin';\nimport WebpackAssetsManifest from 'webpack-assets-manifest';\nimport { fallbacks } from './webpack-fallbacks';\nimport { fallbacksProvidePluginConfig } from './webpack-fallbacks-provide-plugin-config';\nimport { fallbacksAliases } from './webpack-fallbacks-aliases';\n\nexport function configFactory(target: Target, context: BundlerContext): Configuration {\n let truthyEntries =\n Array.isArray(target.entries) && target.entries.length ? target.entries.filter(Boolean) : target.entries || {};\n if (Array.isArray(truthyEntries) && !truthyEntries.length) {\n truthyEntries = {};\n }\n\n const dev = Boolean(context.development);\n const htmlConfig = target.html ?? context.html;\n const compress = target.compress ?? context.compress;\n const htmlPlugins = htmlConfig ? generateHtmlPlugins(htmlConfig) : undefined;\n const splitChunks = target.chunking?.splitChunks;\n\n const config: Configuration = {\n mode: dev ? 'development' : 'production',\n // Stop compilation early in production\n bail: true,\n // These are the \"entry points\" to our application.\n // This means they will be the \"root\" imports that are included in JS bundle.\n // @ts-ignore\n entry: truthyEntries,\n\n infrastructureLogging: {\n level: 'error',\n },\n\n output: {\n // The build folder.\n path: `${target.outputPath}${sep}public`,\n },\n stats: {\n errorDetails: true,\n },\n\n resolve: {\n // TODO - check - we should not need both fallbacks and alias and provider plugin\n alias: fallbacksAliases,\n\n fallback: fallbacks,\n },\n\n plugins: [new webpack.ProvidePlugin(fallbacksProvidePluginConfig), getAssetManifestPlugin()],\n };\n\n if (target.filename) {\n config.output = config.output || {};\n config.output.filename = target.filename;\n }\n\n if (target.chunkFilename) {\n config.output = config.output || {};\n config.output.chunkFilename = target.chunkFilename;\n }\n\n if (target.runtimeChunkName) {\n config.optimization = config.optimization || {};\n config.optimization.runtimeChunk = {\n name: target.runtimeChunkName,\n };\n }\n\n if (splitChunks) {\n config.optimization = config.optimization || {};\n config.optimization.splitChunks = {\n chunks: 'all',\n name: false,\n };\n }\n\n if (htmlPlugins && htmlPlugins.length) {\n if (!config.plugins) {\n config.plugins = [];\n }\n config.plugins = config.plugins.concat(htmlPlugins);\n }\n if (compress) {\n if (!config.plugins) {\n config.plugins = [];\n }\n config.plugins = config.plugins.concat(new CompressionPlugin());\n }\n return config;\n}\n\nfunction getAssetManifestPlugin() {\n return new WebpackAssetsManifest({ entrypoints: true });\n}\n\nfunction generateHtmlPlugins(configs: BundlerHtmlConfig[]) {\n return configs.map((config) => generateHtmlPlugin(config));\n}\n\nfunction generateHtmlPlugin(config: BundlerHtmlConfig) {\n const baseConfig: HtmlWebpackPlugin.Options = {\n filename: config.filename,\n chunks: config.chunks,\n chunksSortMode: config.chunkOrder,\n title: config.title,\n templateContent: config.templateContent,\n minify: config.minify,\n cache: false,\n favicon: config.favicon,\n };\n\n const filteredConfig = omitBy(baseConfig, isUndefined);\n return new HtmlWebpackPlugin(filteredConfig);\n}\n"],"mappings":";;;;;;AACA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,0BAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,yBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,MAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,KAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA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C,CAAC;AAC5D;AAEA,SAASmC,kBAAkBA,CAACnC,MAAyB,EAAE;EACrD,MAAMoC,UAAqC,GAAG;IAC5Cd,QAAQ,EAAEtB,MAAM,CAACsB,QAAQ;IACzBM,MAAM,EAAE5B,MAAM,CAAC4B,MAAM;IACrBS,cAAc,EAAErC,MAAM,CAACsC,UAAU;IACjCC,KAAK,EAAEvC,MAAM,CAACuC,KAAK;IACnBC,eAAe,EAAExC,MAAM,CAACwC,eAAe;IACvCC,MAAM,EAAEzC,MAAM,CAACyC,MAAM;IACrBC,KAAK,EAAE,KAAK;IACZC,OAAO,EAAE3C,MAAM,CAAC2C;EAClB,CAAC;EAED,MAAMC,cAAc,GAAG,IAAAC,gBAAM,EAACT,UAAU,EAAEU,qBAAW,CAAC;EACtD,OAAO,KAAIC,4BAAiB,EAACH,cAAc,CAAC;AAC9C"}
1
+ {"version":3,"names":["_webpack","data","_interopRequireDefault","require","_lodash","_compressionWebpackPlugin","_path","_htmlWebpackPlugin","_webpackAssetsManifest","_webpackFallbacks","_webpackFallbacksProvidePluginConfig","_webpackFallbacksAliases","obj","__esModule","default","configFactory","target","context","truthyEntries","Array","isArray","entries","length","filter","Boolean","dev","development","htmlConfig","html","compress","htmlPlugins","generateHtmlPlugins","undefined","splitChunks","chunking","config","mode","bail","entry","infrastructureLogging","level","output","path","outputPath","sep","stats","errorDetails","resolve","alias","fallbacksAliases","fallback","fallbacks","plugins","webpack","ProvidePlugin","fallbacksProvidePluginConfig","getAssetManifestPlugin","filename","chunkFilename","runtimeChunkName","optimization","runtimeChunk","name","chunks","concat","CompressionPlugin","WebpackAssetsManifest","entrypoints","configs","map","generateHtmlPlugin","baseConfig","chunksSortMode","chunkOrder","title","templateContent","minify","cache","favicon","filteredConfig","omitBy","isUndefined","HtmlWebpackPlugin"],"sources":["webpack.config.ts"],"sourcesContent":["/* eslint-disable complexity */\nimport webpack, { Configuration } from 'webpack';\nimport { isUndefined, omitBy } from 'lodash';\nimport CompressionPlugin from 'compression-webpack-plugin';\nimport { sep } from 'path';\nimport type { BundlerContext, BundlerHtmlConfig, Target } from '@teambit/bundler';\nimport HtmlWebpackPlugin from 'html-webpack-plugin';\nimport WebpackAssetsManifest from 'webpack-assets-manifest';\nimport { fallbacks } from './webpack-fallbacks';\nimport { fallbacksProvidePluginConfig } from './webpack-fallbacks-provide-plugin-config';\nimport { fallbacksAliases } from './webpack-fallbacks-aliases';\n\nexport function configFactory(target: Target, context: BundlerContext): Configuration {\n let truthyEntries =\n Array.isArray(target.entries) && target.entries.length ? target.entries.filter(Boolean) : target.entries || {};\n if (Array.isArray(truthyEntries) && !truthyEntries.length) {\n truthyEntries = {};\n }\n\n const dev = Boolean(context.development);\n const htmlConfig = target.html ?? context.html;\n const compress = target.compress ?? context.compress;\n const htmlPlugins = htmlConfig ? generateHtmlPlugins(htmlConfig) : undefined;\n const splitChunks = target.chunking?.splitChunks;\n\n const config: Configuration = {\n mode: dev ? 'development' : 'production',\n // Stop compilation early in production\n bail: true,\n // These are the \"entry points\" to our application.\n // This means they will be the \"root\" imports that are included in JS bundle.\n // @ts-ignore\n entry: truthyEntries,\n\n infrastructureLogging: {\n level: 'error',\n },\n\n output: {\n // The build folder.\n path: `${target.outputPath}${sep}public`,\n },\n stats: {\n errorDetails: true,\n },\n\n resolve: {\n // TODO - check - we should not need both fallbacks and alias and provider plugin\n alias: fallbacksAliases,\n\n fallback: fallbacks,\n },\n\n plugins: [new webpack.ProvidePlugin(fallbacksProvidePluginConfig), getAssetManifestPlugin()],\n };\n\n if (target.filename) {\n config.output = config.output || {};\n config.output.filename = target.filename;\n }\n\n if (target.chunkFilename) {\n config.output = config.output || {};\n config.output.chunkFilename = target.chunkFilename;\n }\n\n if (target.runtimeChunkName) {\n config.optimization = config.optimization || {};\n config.optimization.runtimeChunk = {\n name: target.runtimeChunkName,\n };\n }\n\n if (splitChunks) {\n config.optimization = config.optimization || {};\n config.optimization.splitChunks = {\n chunks: 'all',\n name: false,\n };\n }\n\n if (htmlPlugins && htmlPlugins.length) {\n if (!config.plugins) {\n config.plugins = [];\n }\n config.plugins = config.plugins.concat(htmlPlugins);\n }\n if (compress) {\n if (!config.plugins) {\n config.plugins = [];\n }\n config.plugins = config.plugins.concat(new CompressionPlugin());\n }\n return config;\n}\n\nfunction getAssetManifestPlugin() {\n return new WebpackAssetsManifest({ entrypoints: true });\n}\n\nfunction generateHtmlPlugins(configs: BundlerHtmlConfig[]) {\n return configs.map((config) => generateHtmlPlugin(config));\n}\n\nfunction generateHtmlPlugin(config: BundlerHtmlConfig) {\n const baseConfig: HtmlWebpackPlugin.Options = {\n filename: config.filename,\n chunks: config.chunks,\n chunksSortMode: config.chunkOrder,\n title: config.title,\n templateContent: config.templateContent,\n minify: config.minify,\n cache: false,\n favicon: config.favicon,\n };\n\n const filteredConfig = omitBy(baseConfig, isUndefined);\n return new HtmlWebpackPlugin(filteredConfig);\n}\n"],"mappings":";;;;;;AACA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,0BAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,yBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,MAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,KAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAM,mBAAA;EAAA,MAAAN,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAI,kBAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA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AK,EAAEvC,MAAM,CAACuC,KAAK;IACnBC,eAAe,EAAExC,MAAM,CAACwC,eAAe;IACvCC,MAAM,EAAEzC,MAAM,CAACyC,MAAM;IACrBC,KAAK,EAAE,KAAK;IACZC,OAAO,EAAE3C,MAAM,CAAC2C;EAClB,CAAC;EAED,MAAMC,cAAc,GAAG,IAAAC,gBAAM,EAACT,UAAU,EAAEU,qBAAW,CAAC;EACtD,OAAO,KAAIC,4BAAiB,EAACH,cAAc,CAAC;AAC9C"}
@@ -1,5 +1,5 @@
1
1
  import { BitBaseEvent } from '@teambit/pubsub';
2
- declare type Params = {
2
+ type Params = {
3
3
  devServerID: string;
4
4
  };
5
5
  export declare class WebpackCompilationStartedEvent extends BitBaseEvent<Params> {
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.webpack_webpack@1.0.107/dist/webpack.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.webpack_webpack@1.0.107/dist/webpack.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.webpack_webpack@1.0.108/dist/webpack.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.webpack_webpack@1.0.108/dist/webpack.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -1,5 +1,5 @@
1
1
  import type { WebpackConfigTransformer } from '@teambit/webpack';
2
- export declare type BodyInjectionOptions = {
2
+ export type BodyInjectionOptions = {
3
3
  content: string;
4
4
  position?: 'start' | 'end';
5
5
  };
@@ -1,5 +1,5 @@
1
1
  import type { WebpackConfigTransformer } from '@teambit/webpack';
2
- export declare type HeadInjectionOptions = {
2
+ export type HeadInjectionOptions = {
3
3
  content: string;
4
4
  position?: 'start' | 'end';
5
5
  };
@@ -29,8 +29,7 @@ function _getExternals() {
29
29
  }
30
30
  function generateAddAliasesFromPeersTransformer(peers, logger) {
31
31
  return (config, context) => {
32
- var _context$target;
33
- const hostRootDir = ((_context$target = context.target) === null || _context$target === void 0 ? void 0 : _context$target.hostRootDir) || context.hostRootDir;
32
+ const hostRootDir = context.target?.hostRootDir || context.hostRootDir;
34
33
  const peerAliases = peers.reduce((acc, peerName) => {
35
34
  // gets the correct module folder of the package.
36
35
  // this allows us to resolve internal files, for example:
@@ -63,8 +62,7 @@ function generateAddAliasesFromPeersTransformer(peers, logger) {
63
62
  */
64
63
  function generateExposePeersTransformer(peers, logger) {
65
64
  return (config, context) => {
66
- var _context$target2;
67
- const hostRootDir = ((_context$target2 = context.target) === null || _context$target2 === void 0 ? void 0 : _context$target2.hostRootDir) || context.hostRootDir;
65
+ const hostRootDir = context.target?.hostRootDir || context.hostRootDir;
68
66
  const exposedRules = (0, _getExposedRules().getExposedRules)(peers, logger, hostRootDir);
69
67
  config.addModuleRules(exposedRules);
70
68
  return config;
@@ -1 +1 @@
1
- {"version":3,"names":["_getExposedRules","data","require","_resolvePeer","_getExternals","generateAddAliasesFromPeersTransformer","peers","logger","config","context","_context$target","hostRootDir","target","peerAliases","reduce","acc","peerName","resolved","resolvePeerToDirOrFile","addAliases","generateExposePeersTransformer","_context$target2","exposedRules","getExposedRules","addModuleRules","generateExternalsTransformer","depes","externals","getExternals","addExternals"],"sources":["transformers.ts"],"sourcesContent":["import { WebpackConfigTransformContext } from '@teambit/webpack';\nimport { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';\nimport { Logger } from '@teambit/logger';\nimport { getExposedRules } from './get-exposed-rules';\nimport { resolvePeerToDirOrFile } from './resolve-peer';\nimport { getExternals } from './get-externals';\n\nexport function generateAddAliasesFromPeersTransformer(peers: string[], logger: Logger) {\n return (config: WebpackConfigMutator, context: WebpackConfigTransformContext): WebpackConfigMutator => {\n const hostRootDir = context.target?.hostRootDir || context.hostRootDir;\n const peerAliases = peers.reduce((acc, peerName) => {\n // gets the correct module folder of the package.\n // this allows us to resolve internal files, for example:\n // node_modules/react-dom/test-utils\n //\n // we can't use require.resolve() because it resolves to a specific file.\n // for example, if we used \"react-dom\": require.resolve(\"react-dom\"),\n // it would try to resolve \"react-dom/test-utils\" as:\n // node_modules/react-dom/index.js/test-utils\n const resolved = resolvePeerToDirOrFile(peerName, logger, hostRootDir);\n // Sometime there are packages that only hold icons for example, so there is no main property in their package.json\n // so they can't be resolved.\n // in such cases do not add them to the aliases.\n // We already log that cases in the resolvePeerToDirOrFile function.\n if (resolved) {\n acc[peerName] = resolved;\n }\n return acc;\n }, {});\n\n config.addAliases(peerAliases);\n return config;\n };\n}\n\n// [dead code] - no longer used\n/**\n * Generate a transformer that expose all the peers as global via the expose loader\n * @param peers\n * @returns\n */\nexport function generateExposePeersTransformer(peers: string[], logger: Logger) {\n return (config: WebpackConfigMutator, context: WebpackConfigTransformContext): WebpackConfigMutator => {\n const hostRootDir = context.target?.hostRootDir || context.hostRootDir;\n const exposedRules = getExposedRules(peers, logger, hostRootDir);\n config.addModuleRules(exposedRules);\n return config;\n };\n}\n\n/**\n * Generate a transformer that expose all the peers as global via the expose loader\n * @param peers\n * @returns\n */\nexport function generateExternalsTransformer(depes: string[]) {\n return (config: WebpackConfigMutator): WebpackConfigMutator => {\n const externals = getExternals(depes);\n config.addExternals(externals);\n return config;\n };\n}\n"],"mappings":";;;;;;;;AAGA,SAAAA,iBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,gBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,aAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,cAAA;EA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;EACf,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASiB,4BAA4BA,CAACC,KAAe,EAAE;EAC5D,OAAQlB,MAA4B,IAA2B;IAC7D,MAAMmB,SAAS,GAAG,IAAAC,4BAAY,EAACF,KAAK,CAAC;IACrClB,MAAM,CAACqB,YAAY,CAACF,SAAS,CAAC;IAC9B,OAAOnB,MAAM;EACf,CAAC;AACH"}
1
+ {"version":3,"names":["_getExposedRules","data","require","_resolvePeer","_getExternals","generateAddAliasesFromPeersTransformer","peers","logger","config","context","hostRootDir","target","peerAliases","reduce","acc","peerName","resolved","resolvePeerToDirOrFile","addAliases","generateExposePeersTransformer","exposedRules","getExposedRules","addModuleRules","generateExternalsTransformer","depes","externals","getExternals","addExternals"],"sources":["transformers.ts"],"sourcesContent":["import { WebpackConfigTransformContext } from '@teambit/webpack';\nimport { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';\nimport { Logger } from '@teambit/logger';\nimport { getExposedRules } from './get-exposed-rules';\nimport { resolvePeerToDirOrFile } from './resolve-peer';\nimport { getExternals } from './get-externals';\n\nexport function generateAddAliasesFromPeersTransformer(peers: string[], logger: Logger) {\n return (config: WebpackConfigMutator, context: WebpackConfigTransformContext): WebpackConfigMutator => {\n const hostRootDir = context.target?.hostRootDir || context.hostRootDir;\n const peerAliases = peers.reduce((acc, peerName) => {\n // gets the correct module folder of the package.\n // this allows us to resolve internal files, for example:\n // node_modules/react-dom/test-utils\n //\n // we can't use require.resolve() because it resolves to a specific file.\n // for example, if we used \"react-dom\": require.resolve(\"react-dom\"),\n // it would try to resolve \"react-dom/test-utils\" as:\n // node_modules/react-dom/index.js/test-utils\n const resolved = resolvePeerToDirOrFile(peerName, logger, hostRootDir);\n // Sometime there are packages that only hold icons for example, so there is no main property in their package.json\n // so they can't be resolved.\n // in such cases do not add them to the aliases.\n // We already log that cases in the resolvePeerToDirOrFile function.\n if (resolved) {\n acc[peerName] = resolved;\n }\n return acc;\n }, {});\n\n config.addAliases(peerAliases);\n return config;\n };\n}\n\n// [dead code] - no longer used\n/**\n * Generate a transformer that expose all the peers as global via the expose loader\n * @param peers\n * @returns\n */\nexport function generateExposePeersTransformer(peers: string[], logger: Logger) {\n return (config: WebpackConfigMutator, context: WebpackConfigTransformContext): WebpackConfigMutator => {\n const hostRootDir = context.target?.hostRootDir || context.hostRootDir;\n const exposedRules = getExposedRules(peers, logger, hostRootDir);\n config.addModuleRules(exposedRules);\n return config;\n };\n}\n\n/**\n * Generate a transformer that expose all the peers as global via the expose loader\n * @param peers\n * @returns\n */\nexport function generateExternalsTransformer(depes: string[]) {\n return (config: WebpackConfigMutator): WebpackConfigMutator => {\n const externals = getExternals(depes);\n config.addExternals(externals);\n return config;\n };\n}\n"],"mappings":";;;;;;;;AAGA,SAAAA,iBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,gBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,aAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,YAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,cAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,aAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,SAASI,sCAAsCA,CAACC,KAAe,EAAEC,MAAc,EAAE;EACtF,OAAO,CAACC,MAA4B,EAAEC,OAAsC,KAA2B;IACrG,MAAMC,WAAW,GAAGD,OAAO,CAACE,MAAM,EAAED,WAAW,IAAID,OAAO,CAACC,WAAW;IACtE,MAAME,WAAW,GAAGN,KAAK,CAACO,MAAM,CAAC,CAACC,GAAG,EAAEC,QAAQ,KAAK;MAClD;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,MAAMC,QAAQ,GAAG,IAAAC,qCAAsB,EAACF,QAAQ,EAAER,MAAM,EAAEG,WAAW,CAAC;MACtE;MACA;MACA;MACA;MACA,IAAIM,QAAQ,EAAE;QACZF,GAAG,CAACC,QAAQ,CAAC,GAAGC,QAAQ;MAC1B;MACA,OAAOF,GAAG;IACZ,CAAC,EAAE,CAAC,CAAC,CAAC;IAENN,MAAM,CAACU,UAAU,CAACN,WAAW,CAAC;IAC9B,OAAOJ,MAAM;EACf,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASW,8BAA8BA,CAACb,KAAe,EAAEC,MAAc,EAAE;EAC9E,OAAO,CAACC,MAA4B,EAAEC,OAAsC,KAA2B;IACrG,MAAMC,WAAW,GAAGD,OAAO,CAACE,MAAM,EAAED,WAAW,IAAID,OAAO,CAACC,WAAW;IACtE,MAAMU,YAAY,GAAG,IAAAC,kCAAe,EAACf,KAAK,EAAEC,MAAM,EAAEG,WAAW,CAAC;IAChEF,MAAM,CAACc,cAAc,CAACF,YAAY,CAAC;IACnC,OAAOZ,MAAM;EACf,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASe,4BAA4BA,CAACC,KAAe,EAAE;EAC5D,OAAQhB,MAA4B,IAA2B;IAC7D,MAAMiB,SAAS,GAAG,IAAAC,4BAAY,EAACF,KAAK,CAAC;IACrChB,MAAM,CAACmB,YAAY,CAACF,SAAS,CAAC;IAC9B,OAAOjB,MAAM;EACf,CAAC;AACH"}
@@ -50,11 +50,10 @@ class WebpackBundler {
50
50
  this.metaData = metaData;
51
51
  }
52
52
  async run() {
53
- var _this$metaData, _this$metaData2;
54
53
  const startTime = Date.now();
55
54
  const compilers = this.configs.map(config => this.webpack(config));
56
- const initiator = (_this$metaData = this.metaData) === null || _this$metaData === void 0 ? void 0 : _this$metaData.initiator;
57
- const envId = (_this$metaData2 = this.metaData) === null || _this$metaData2 === void 0 ? void 0 : _this$metaData2.envId;
55
+ const initiator = this.metaData?.initiator;
56
+ const envId = this.metaData?.envId;
58
57
  const initiatorMessage = initiator ? `process initiated by: ${initiator}.` : '';
59
58
  const envIdMessage = envId ? `config created by env: ${envId}.` : '';
60
59
  const longProcessLogger = this.logger.createLongProcessLogger('running Webpack bundler', compilers.length);
@@ -137,21 +136,18 @@ class WebpackBundler {
137
136
  const entriesMap = stats.entrypoints;
138
137
  if (!entriesMap || !Object.keys(assetsMap).length) return {};
139
138
  Object.entries(entriesMap).forEach(([, entryVal]) => {
140
- var _entryVal$assets, _entryVal$auxiliaryAs;
141
139
  let compressedAssetsSize = 0;
142
140
  let compressedAuxiliaryAssetsSize = 0;
143
- (_entryVal$assets = entryVal.assets) === null || _entryVal$assets === void 0 || _entryVal$assets.forEach(asset => {
144
- var _assetsMap$asset$name;
145
- const compressedSize = (_assetsMap$asset$name = assetsMap[asset.name]) === null || _assetsMap$asset$name === void 0 ? void 0 : _assetsMap$asset$name.compressedSize;
141
+ entryVal.assets?.forEach(asset => {
142
+ const compressedSize = assetsMap[asset.name]?.compressedSize;
146
143
  if (compressedSize) {
147
144
  // @ts-ignore
148
145
  asset.compressedSize = compressedSize;
149
146
  compressedAssetsSize += compressedSize;
150
147
  }
151
148
  });
152
- (_entryVal$auxiliaryAs = entryVal.auxiliaryAssets) === null || _entryVal$auxiliaryAs === void 0 || _entryVal$auxiliaryAs.forEach(asset => {
153
- var _assetsMap$asset$name2;
154
- const compressedSize = (_assetsMap$asset$name2 = assetsMap[asset.name]) === null || _assetsMap$asset$name2 === void 0 ? void 0 : _assetsMap$asset$name2.compressedSize;
149
+ entryVal.auxiliaryAssets?.forEach(asset => {
150
+ const compressedSize = assetsMap[asset.name]?.compressedSize;
155
151
  if (compressedSize) {
156
152
  // @ts-ignore
157
153
  asset.compressedSize = compressedSize;
@@ -1 +1 @@
1
- {"version":3,"names":["_bitError","data","require","_lodash","_pMapSeries","_interopRequireDefault","_path","obj","__esModule","default","WebpackBundler","constructor","targets","configs","logger","webpack","metaData","run","_this$metaData","_this$metaData2","startTime","Date","now","compilers","map","config","initiator","envId","initiatorMessage","envIdMessage","longProcessLogger","createLongProcessLogger","length","componentOutput","mapSeries","compiler","components","getComponents","outputPath","componentsLengthMessage","fullMessage","ids","component","id","toString","join","logProgress","debug","Promise","resolve","err","stats","error","errors","stack","BitError","info","toJson","all","entrypoints","warnings","assets","chunkGroupAuxiliary","relatedAssets","cachedAssets","assetsMap","getAssets","entriesAssetsMap","getEntriesAssetsMap","Object","values","assetsByChunkName","getErrors","compilation","outputOptions","path","endTime","end","fieldsToShow","webpackError","lines","fieldName","undefined","errorMessage","compact","reduce","acc","asset","name","size","compressedSize","getCompressedSize","entriesMap","keys","entries","forEach","entryVal","_entryVal$assets","_entryVal$auxiliaryAs","compressedAssetsSize","compressedAuxiliaryAssetsSize","_assetsMap$asset$name","auxiliaryAssets","_assetsMap$asset$name2","related","isEmpty","gzipped","find","relatedAsset","type","substring","lastIndexOf","sep","target","targetCandidate","Error","exports"],"sources":["webpack.bundler.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport type { Bundler, BundlerResult, Asset, Target, EntriesAssetsMap, BundlerContextMetaData } from '@teambit/bundler';\nimport type { Logger } from '@teambit/logger';\nimport { compact, isEmpty } from 'lodash';\nimport mapSeries from 'p-map-series';\nimport type { Compiler, Configuration, StatsCompilation, StatsAsset } from 'webpack';\nimport { sep } from 'path';\n\ntype AssetsMap = { [assetId: string]: Asset };\nexport class WebpackBundler implements Bundler {\n constructor(\n /**\n * targets to bundle.\n */\n private targets: Target[],\n\n /**\n * webpack configuration.\n */\n private configs: Configuration[],\n\n private logger: Logger,\n\n private webpack,\n\n private metaData?: BundlerContextMetaData | undefined\n ) {}\n\n async run(): Promise<BundlerResult[]> {\n const startTime = Date.now();\n const compilers = this.configs.map((config: any) => this.webpack(config));\n const initiator = this.metaData?.initiator;\n const envId = this.metaData?.envId;\n const initiatorMessage = initiator ? `process initiated by: ${initiator}.` : '';\n const envIdMessage = envId ? `config created by env: ${envId}.` : '';\n\n const longProcessLogger = this.logger.createLongProcessLogger('running Webpack bundler', compilers.length);\n const componentOutput = await mapSeries(compilers, (compiler: Compiler) => {\n const components = this.getComponents(compiler.outputPath);\n const componentsLengthMessage = `running on ${components.length} components`;\n const fullMessage = `${initiatorMessage} ${envIdMessage} ${componentsLengthMessage}`;\n const ids = components.map((component) => component.id.toString()).join(', ');\n longProcessLogger.logProgress(`${fullMessage}`);\n this.logger.debug(`${fullMessage}\\ncomponents ids: ${ids}`);\n return new Promise((resolve) => {\n // TODO: split to multiple processes to reduce time and configure concurrent builds.\n // @see https://github.com/trivago/parallel-webpack\n return compiler.run((err, stats) => {\n if (err) {\n this.logger.error('get error from webpack compiler, full error:', err);\n\n return resolve({\n errors: [`${err.toString()}\\n${err.stack}`],\n components,\n });\n }\n if (!stats) throw new BitError('unknown build error');\n // const info = stats.toJson();\n\n const info = stats.toJson({\n all: false,\n entrypoints: true,\n warnings: true,\n errors: true,\n assets: true,\n chunkGroupAuxiliary: true,\n relatedAssets: true,\n cachedAssets: true,\n });\n const assetsMap = this.getAssets(info);\n const entriesAssetsMap = this.getEntriesAssetsMap(info, assetsMap);\n\n return resolve({\n assets: Object.values(assetsMap),\n assetsByChunkName: info.assetsByChunkName,\n entriesAssetsMap,\n errors: this.getErrors(info),\n outputPath: stats.compilation.outputOptions.path,\n components,\n warnings: info.warnings,\n startTime,\n endTime: Date.now(),\n });\n });\n });\n });\n longProcessLogger.end();\n return componentOutput as BundlerResult[];\n }\n\n private getErrors(stats: StatsCompilation): Error[] {\n if (!stats.errors) return [];\n const fieldsToShow = ['message', 'moduleId', 'moduleName', 'moduleIdentifier', 'loc'];\n return stats.errors.map((webpackError) => {\n const lines = fieldsToShow.map((fieldName) => {\n if (webpackError[fieldName]) {\n return `${fieldName}: ${webpackError[fieldName]}`;\n }\n return undefined;\n });\n const errorMessage = compact(lines).join('\\n');\n return new BitError(errorMessage);\n });\n }\n\n private getAssets(stats: StatsCompilation): AssetsMap {\n if (!stats.assets) return {};\n return stats.assets.reduce((acc, asset) => {\n acc[asset.name] = {\n name: asset.name,\n size: asset.size,\n compressedSize: this.getCompressedSize(asset),\n };\n return acc;\n }, {});\n }\n\n private getEntriesAssetsMap(stats: StatsCompilation, assetsMap: AssetsMap): EntriesAssetsMap {\n const entriesMap = stats.entrypoints;\n if (!entriesMap || !Object.keys(assetsMap).length) return {};\n Object.entries(entriesMap).forEach(([, entryVal]) => {\n let compressedAssetsSize = 0;\n let compressedAuxiliaryAssetsSize = 0;\n entryVal.assets?.forEach((asset) => {\n const compressedSize = assetsMap[asset.name]?.compressedSize;\n if (compressedSize) {\n // @ts-ignore\n asset.compressedSize = compressedSize;\n compressedAssetsSize += compressedSize;\n }\n });\n entryVal.auxiliaryAssets?.forEach((asset) => {\n const compressedSize = assetsMap[asset.name]?.compressedSize;\n if (compressedSize) {\n // @ts-ignore\n asset.compressedSize = compressedSize;\n compressedAuxiliaryAssetsSize += compressedSize;\n }\n });\n entryVal.compressedAssetsSize = compressedAssetsSize;\n entryVal.compressedAuxiliaryAssetsSize = compressedAuxiliaryAssetsSize;\n });\n return entriesMap as any as EntriesAssetsMap;\n }\n\n private getCompressedSize(asset: StatsAsset): number | undefined {\n if (!asset.related || isEmpty(asset.related)) return undefined;\n const gzipped = asset.related.find((relatedAsset) => {\n return relatedAsset.type === 'gzipped';\n });\n if (!gzipped) return undefined;\n return gzipped.size;\n }\n\n private getComponents(outputPath: string) {\n const path = outputPath.substring(0, outputPath.lastIndexOf(sep));\n const target = this.targets.find((targetCandidate) => path === targetCandidate.outputPath);\n\n if (!target) throw new Error(`Could not find component id for path \"${path}\"`);\n return target.components;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,UAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,SAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAA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,EAAE;IACxC,MAAMqC,IAAI,GAAGrC,UAAU,CAACwE,SAAS,CAAC,CAAC,EAAExE,UAAU,CAACyE,WAAW,CAACC,WAAG,CAAC,CAAC;IACjE,MAAMC,MAAM,GAAG,IAAI,CAACrG,OAAO,CAAC+F,IAAI,CAAEO,eAAe,IAAKvC,IAAI,KAAKuC,eAAe,CAAC5E,UAAU,CAAC;IAE1F,IAAI,CAAC2E,MAAM,EAAE,MAAM,IAAIE,KAAK,CAAE,yCAAwCxC,IAAK,GAAE,CAAC;IAC9E,OAAOsC,MAAM,CAAC7E,UAAU;EAC1B;AACF;AAACgF,OAAA,CAAA1G,cAAA,GAAAA,cAAA"}
1
+ {"version":3,"names":["_bitError","data","require","_lodash","_pMapSeries","_interopRequireDefault","_path","obj","__esModule","default","WebpackBundler","constructor","targets","configs","logger","webpack","metaData","run","startTime","Date","now","compilers","map","config","initiator","envId","initiatorMessage","envIdMessage","longProcessLogger","createLongProcessLogger","length","componentOutput","mapSeries","compiler","components","getComponents","outputPath","componentsLengthMessage","fullMessage","ids","component","id","toString","join","logProgress","debug","Promise","resolve","err","stats","error","errors","stack","BitError","info","toJson","all","entrypoints","warnings","assets","chunkGroupAuxiliary","relatedAssets","cachedAssets","assetsMap","getAssets","entriesAssetsMap","getEntriesAssetsMap","Object","values","assetsByChunkName","getErrors","compilation","outputOptions","path","endTime","end","fieldsToShow","webpackError","lines","fieldName","undefined","errorMessage","compact","reduce","acc","asset","name","size","compressedSize","getCompressedSize","entriesMap","keys","entries","forEach","entryVal","compressedAssetsSize","compressedAuxiliaryAssetsSize","auxiliaryAssets","related","isEmpty","gzipped","find","relatedAsset","type","substring","lastIndexOf","sep","target","targetCandidate","Error","exports"],"sources":["webpack.bundler.ts"],"sourcesContent":["import { BitError } from '@teambit/bit-error';\nimport type { Bundler, BundlerResult, Asset, Target, EntriesAssetsMap, BundlerContextMetaData } from '@teambit/bundler';\nimport type { Logger } from '@teambit/logger';\nimport { compact, isEmpty } from 'lodash';\nimport mapSeries from 'p-map-series';\nimport type { Compiler, Configuration, StatsCompilation, StatsAsset } from 'webpack';\nimport { sep } from 'path';\n\ntype AssetsMap = { [assetId: string]: Asset };\nexport class WebpackBundler implements Bundler {\n constructor(\n /**\n * targets to bundle.\n */\n private targets: Target[],\n\n /**\n * webpack configuration.\n */\n private configs: Configuration[],\n\n private logger: Logger,\n\n private webpack,\n\n private metaData?: BundlerContextMetaData | undefined\n ) {}\n\n async run(): Promise<BundlerResult[]> {\n const startTime = Date.now();\n const compilers = this.configs.map((config: any) => this.webpack(config));\n const initiator = this.metaData?.initiator;\n const envId = this.metaData?.envId;\n const initiatorMessage = initiator ? `process initiated by: ${initiator}.` : '';\n const envIdMessage = envId ? `config created by env: ${envId}.` : '';\n\n const longProcessLogger = this.logger.createLongProcessLogger('running Webpack bundler', compilers.length);\n const componentOutput = await mapSeries(compilers, (compiler: Compiler) => {\n const components = this.getComponents(compiler.outputPath);\n const componentsLengthMessage = `running on ${components.length} components`;\n const fullMessage = `${initiatorMessage} ${envIdMessage} ${componentsLengthMessage}`;\n const ids = components.map((component) => component.id.toString()).join(', ');\n longProcessLogger.logProgress(`${fullMessage}`);\n this.logger.debug(`${fullMessage}\\ncomponents ids: ${ids}`);\n return new Promise((resolve) => {\n // TODO: split to multiple processes to reduce time and configure concurrent builds.\n // @see https://github.com/trivago/parallel-webpack\n return compiler.run((err, stats) => {\n if (err) {\n this.logger.error('get error from webpack compiler, full error:', err);\n\n return resolve({\n errors: [`${err.toString()}\\n${err.stack}`],\n components,\n });\n }\n if (!stats) throw new BitError('unknown build error');\n // const info = stats.toJson();\n\n const info = stats.toJson({\n all: false,\n entrypoints: true,\n warnings: true,\n errors: true,\n assets: true,\n chunkGroupAuxiliary: true,\n relatedAssets: true,\n cachedAssets: true,\n });\n const assetsMap = this.getAssets(info);\n const entriesAssetsMap = this.getEntriesAssetsMap(info, assetsMap);\n\n return resolve({\n assets: Object.values(assetsMap),\n assetsByChunkName: info.assetsByChunkName,\n entriesAssetsMap,\n errors: this.getErrors(info),\n outputPath: stats.compilation.outputOptions.path,\n components,\n warnings: info.warnings,\n startTime,\n endTime: Date.now(),\n });\n });\n });\n });\n longProcessLogger.end();\n return componentOutput as BundlerResult[];\n }\n\n private getErrors(stats: StatsCompilation): Error[] {\n if (!stats.errors) return [];\n const fieldsToShow = ['message', 'moduleId', 'moduleName', 'moduleIdentifier', 'loc'];\n return stats.errors.map((webpackError) => {\n const lines = fieldsToShow.map((fieldName) => {\n if (webpackError[fieldName]) {\n return `${fieldName}: ${webpackError[fieldName]}`;\n }\n return undefined;\n });\n const errorMessage = compact(lines).join('\\n');\n return new BitError(errorMessage);\n });\n }\n\n private getAssets(stats: StatsCompilation): AssetsMap {\n if (!stats.assets) return {};\n return stats.assets.reduce((acc, asset) => {\n acc[asset.name] = {\n name: asset.name,\n size: asset.size,\n compressedSize: this.getCompressedSize(asset),\n };\n return acc;\n }, {});\n }\n\n private getEntriesAssetsMap(stats: StatsCompilation, assetsMap: AssetsMap): EntriesAssetsMap {\n const entriesMap = stats.entrypoints;\n if (!entriesMap || !Object.keys(assetsMap).length) return {};\n Object.entries(entriesMap).forEach(([, entryVal]) => {\n let compressedAssetsSize = 0;\n let compressedAuxiliaryAssetsSize = 0;\n entryVal.assets?.forEach((asset) => {\n const compressedSize = assetsMap[asset.name]?.compressedSize;\n if (compressedSize) {\n // @ts-ignore\n asset.compressedSize = compressedSize;\n compressedAssetsSize += compressedSize;\n }\n });\n entryVal.auxiliaryAssets?.forEach((asset) => {\n const compressedSize = assetsMap[asset.name]?.compressedSize;\n if (compressedSize) {\n // @ts-ignore\n asset.compressedSize = compressedSize;\n compressedAuxiliaryAssetsSize += compressedSize;\n }\n });\n entryVal.compressedAssetsSize = compressedAssetsSize;\n entryVal.compressedAuxiliaryAssetsSize = compressedAuxiliaryAssetsSize;\n });\n return entriesMap as any as EntriesAssetsMap;\n }\n\n private getCompressedSize(asset: StatsAsset): number | undefined {\n if (!asset.related || isEmpty(asset.related)) return undefined;\n const gzipped = asset.related.find((relatedAsset) => {\n return relatedAsset.type === 'gzipped';\n });\n if (!gzipped) return undefined;\n return gzipped.size;\n }\n\n private getComponents(outputPath: string) {\n const path = outputPath.substring(0, outputPath.lastIndexOf(sep));\n const target = this.targets.find((targetCandidate) => path === targetCandidate.outputPath);\n\n if (!target) throw new Error(`Could not find component id for path \"${path}\"`);\n return target.components;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,UAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,SAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAI,sBAAA,CAAAH,OAAA;EAAAE,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAK,MAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,KAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA2B,SAAAI,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAGpB,MAAMG,cAAc,CAAoB;EAC7CC,WAAWA;EACT;AACJ;AACA;EACYC,OAAiB;EAEzB;AACJ;AACA;EACYC,OAAwB,EAExBC,MAAc,EAEdC,OAAO,EAEPC,QAA6C,EACrD;IAAA,KAZQJ,OAAiB,GAAjBA,OAAiB;IAAA,KAKjBC,OAAwB,GAAxBA,OAAwB;IAAA,KAExBC,MAAc,GAAdA,MAAc;IAAA,KAEdC,OAAO,GAAPA,OAAO;IAAA,KAEPC,QAA6C,GAA7CA,QAA6C;EAC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xC,CAAC,CAAC;IACF,IAAI,CAACH,OAAO,EAAE,OAAOpB,SAAS;IAC9B,OAAOoB,OAAO,CAACb,IAAI;EACrB;EAEQpD,aAAaA,CAACC,UAAkB,EAAE;IACxC,MAAMqC,IAAI,GAAGrC,UAAU,CAACoE,SAAS,CAAC,CAAC,EAAEpE,UAAU,CAACqE,WAAW,CAACC,WAAG,CAAC,CAAC;IACjE,MAAMC,MAAM,GAAG,IAAI,CAAC/F,OAAO,CAACyF,IAAI,CAAEO,eAAe,IAAKnC,IAAI,KAAKmC,eAAe,CAACxE,UAAU,CAAC;IAE1F,IAAI,CAACuE,MAAM,EAAE,MAAM,IAAIE,KAAK,CAAE,yCAAwCpC,IAAK,GAAE,CAAC;IAC9E,OAAOkC,MAAM,CAACzE,UAAU;EAC1B;AACF;AAAC4E,OAAA,CAAApG,cAAA,GAAAA,cAAA"}
@@ -1,2 +1,2 @@
1
- import React from 'react';
2
- export declare const Logo: () => React.JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const Logo: () => JSX.Element;
@@ -5,11 +5,11 @@ import { Logger, LoggerMain } from '@teambit/logger';
5
5
  import { Workspace } from '@teambit/workspace';
6
6
  import { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';
7
7
  import { WebpackBundler } from './webpack.bundler';
8
- export declare type WebpackConfigTransformContext = GlobalWebpackConfigTransformContext & {
8
+ export type WebpackConfigTransformContext = GlobalWebpackConfigTransformContext & {
9
9
  target: Target;
10
10
  };
11
- export declare type WebpackConfigDevServerTransformContext = GlobalWebpackConfigTransformContext & DevServerContext;
12
- export declare type GlobalWebpackConfigTransformContext = {
11
+ export type WebpackConfigDevServerTransformContext = GlobalWebpackConfigTransformContext & DevServerContext;
12
+ export type GlobalWebpackConfigTransformContext = {
13
13
  mode: BundlerMode;
14
14
  /**
15
15
  * Whether the config is for an env template bundling
@@ -23,8 +23,8 @@ export declare type GlobalWebpackConfigTransformContext = {
23
23
  */
24
24
  hostRootDir?: string;
25
25
  };
26
- export declare type WebpackConfigTransformer = (config: WebpackConfigMutator, context: WebpackConfigTransformContext) => WebpackConfigMutator;
27
- export declare type WebpackConfigDevServerTransformer = (config: WebpackConfigMutator, context: WebpackConfigDevServerTransformContext) => WebpackConfigMutator;
26
+ export type WebpackConfigTransformer = (config: WebpackConfigMutator, context: WebpackConfigTransformContext) => WebpackConfigMutator;
27
+ export type WebpackConfigDevServerTransformer = (config: WebpackConfigMutator, context: WebpackConfigDevServerTransformContext) => WebpackConfigMutator;
28
28
  export declare class WebpackMain {
29
29
  /**
30
30
  * Pubsub extension.
@@ -69,9 +69,9 @@ export declare class WebpackMain {
69
69
  private generateTransformers;
70
70
  private getWebpackInstance;
71
71
  private createDevServerConfig;
72
- static slots: never[];
72
+ static slots: any[];
73
73
  static runtime: import("@teambit/harmony").RuntimeDefinition;
74
74
  static dependencies: import("@teambit/harmony").Aspect[];
75
75
  static provider([pubsub, workspace, bundler, logger]: [PubsubMain, Workspace, BundlerMain, LoggerMain]): Promise<WebpackMain>;
76
76
  }
77
- export declare function runTransformersWithContext(config: WebpackConfigMutator, transformers: (WebpackConfigTransformer | WebpackConfigDevServerTransformer)[] | undefined, context: any): WebpackConfigMutator;
77
+ export declare function runTransformersWithContext(config: WebpackConfigMutator, transformers: Array<WebpackConfigTransformer | WebpackConfigDevServerTransformer>, context: any): WebpackConfigMutator;
@@ -151,10 +151,9 @@ class WebpackMain {
151
151
  return (0, _webpackMerge().merge)(target, source);
152
152
  }
153
153
  createBundler(context, transformers = [], initialConfigs, webpackModuleOrPath) {
154
- var _context$metaData;
155
154
  const transformerContext = {
156
155
  mode: 'prod',
157
- isEnvTemplate: (_context$metaData = context.metaData) === null || _context$metaData === void 0 ? void 0 : _context$metaData.isEnvTemplate
156
+ isEnvTemplate: context.metaData?.isEnvTemplate
158
157
  };
159
158
  // eslint-disable-next-line max-len
160
159
  const configs = initialConfigs || this.createConfigs(context.targets, _webpack2().configFactory, transformers, transformerContext, context);
@@ -175,13 +174,13 @@ class WebpackMain {
175
174
  generateTransformers(_bundlerContext, devServerContext, target) {
176
175
  const transformers = [];
177
176
  // TODO: handle dev server
178
- const hostDeps = (target === null || target === void 0 ? void 0 : target.hostDependencies) || (devServerContext === null || devServerContext === void 0 ? void 0 : devServerContext.hostDependencies);
177
+ const hostDeps = target?.hostDependencies || devServerContext?.hostDependencies;
179
178
  if (hostDeps) {
180
- if (target !== null && target !== void 0 && target.aliasHostDependencies || devServerContext !== null && devServerContext !== void 0 && devServerContext.aliasHostDependencies) {
179
+ if (target?.aliasHostDependencies || devServerContext?.aliasHostDependencies) {
181
180
  const peerAliasesTransformer = (0, _transformers().generateAddAliasesFromPeersTransformer)(hostDeps, this.logger);
182
181
  transformers.push(peerAliasesTransformer);
183
182
  }
184
- if (target !== null && target !== void 0 && target.externalizeHostDependencies || devServerContext !== null && devServerContext !== void 0 && devServerContext.externalizeHostDependencies) {
183
+ if (target?.externalizeHostDependencies || devServerContext?.externalizeHostDependencies) {
185
184
  const externalsTransformer = (0, _transformers().generateExternalsTransformer)(hostDeps);
186
185
  transformers.push(externalsTransformer);
187
186
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_webpack","data","_interopRequireDefault","require","_pubsub","_bundler","_cli","_logger","_workspace","_webpackMerge","_webpackModules","_transformers","_webpackDev","_webpack2","_webpack3","_webpack4","_webpack5","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","WebpackMain","constructor","pubsub","workspace","bundler","logger","createDevServer","context","transformers","webpackModulePath","webpackDevServerModulePath","config","createDevServerConfig","entry","path","id","rootPath","publicPath","getComponentPathsRegExps","title","wdsPath","resolve","configMutator","WebpackConfigMutator","transformerContext","assign","mode","internalTransformers","generateTransformers","undefined","afterMutation","runTransformersWithContext","clone","WebpackDevServer","raw","getWebpackInstance","webpack","mergeConfig","target","source","merge","createBundler","initialConfigs","webpackModuleOrPath","_context$metaData","isEnvTemplate","metaData","configs","createConfigs","targets","baseConfigFactory","WebpackBundler","factory","bundlerContext","map","baseConfig","_bundlerContext","devServerContext","hostDeps","hostDependencies","aliasHostDependencies","peerAliasesTransformer","generateAddAliasesFromPeersTransformer","push","externalizeHostDependencies","externalsTransformer","generateExternalsTransformer","webpackOrPath","fallback","devServerID","publicRoot","componentPathsRegExps","devServerConfigFactory","provider","logPublisher","createLogger","WebpackAspect","exports","MainRuntime","PubsubAspect","WorkspaceAspect","BundlerAspect","LoggerAspect","addRuntime","Array","isArray","newConfig","reduce","acc","transformer"],"sources":["webpack.main.runtime.ts"],"sourcesContent":["import webpack, { Configuration } from 'webpack';\nimport PubsubAspect, { PubsubMain } from '@teambit/pubsub';\nimport {\n BundlerAspect,\n BundlerContext,\n BundlerMain,\n DevServer,\n DevServerContext,\n BundlerMode,\n Target,\n} from '@teambit/bundler';\nimport { MainRuntime } from '@teambit/cli';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { merge } from 'webpack-merge';\n// We want to import it to make sure bit recognizes it as a dependency\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport WsDevServer from 'webpack-dev-server';\nimport { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';\n\nimport { generateAddAliasesFromPeersTransformer, generateExternalsTransformer } from './transformers';\nimport { configFactory as devServerConfigFactory } from './config/webpack.dev.config';\nimport { configFactory as baseConfigFactory } from './config/webpack.config';\n\nimport { WebpackAspect } from './webpack.aspect';\nimport { WebpackBundler } from './webpack.bundler';\nimport { WebpackDevServer } from './webpack.dev-server';\n\nexport type WebpackConfigTransformContext = GlobalWebpackConfigTransformContext & {\n target: Target;\n};\n\nexport type WebpackConfigDevServerTransformContext = GlobalWebpackConfigTransformContext & DevServerContext;\n\nexport type GlobalWebpackConfigTransformContext = {\n mode: BundlerMode;\n /**\n * Whether the config is for an env template bundling\n */\n isEnvTemplate?: boolean;\n /**\n * A path for the host root dir\n * Host root dir is usually the env root dir\n * This can be used in different bundle options which run require.resolve\n * for example when configuring webpack aliases or webpack expose loader on the peers deps\n */\n hostRootDir?: string;\n};\n\nexport type WebpackConfigTransformer = (\n config: WebpackConfigMutator,\n context: WebpackConfigTransformContext\n) => WebpackConfigMutator;\n\nexport type WebpackConfigDevServerTransformer = (\n config: WebpackConfigMutator,\n context: WebpackConfigDevServerTransformContext\n) => WebpackConfigMutator;\n\nexport class WebpackMain {\n constructor(\n /**\n * Pubsub extension.\n */\n public pubsub: PubsubMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * bundler extension.\n */\n private bundler: BundlerMain,\n\n /**\n * Logger extension\n */\n public logger: Logger\n ) {}\n\n /**\n * create an instance of bit-compliant webpack dev server for a set of components\n */\n createDevServer(\n context: DevServerContext,\n transformers: WebpackConfigTransformer[] = [],\n webpackModulePath?: string,\n webpackDevServerModulePath?: string\n ): DevServer {\n const config = this.createDevServerConfig(\n context.entry,\n this.workspace.path,\n context.id,\n context.rootPath,\n context.publicPath,\n this.workspace.getComponentPathsRegExps(),\n context.title\n ) as any;\n const wdsPath = webpackDevServerModulePath || require.resolve('webpack-dev-server');\n const configMutator = new WebpackConfigMutator(config);\n const transformerContext: WebpackConfigDevServerTransformContext = Object.assign(context, { mode: 'dev' as const });\n const internalTransformers = this.generateTransformers(undefined, transformerContext);\n\n const afterMutation = runTransformersWithContext(\n configMutator.clone(),\n [...internalTransformers, ...transformers],\n transformerContext\n );\n // @ts-ignore - fix this\n return new WebpackDevServer(afterMutation.raw, this.getWebpackInstance(webpackModulePath, webpack), wdsPath);\n }\n\n mergeConfig(target: any, source: any): any {\n return merge(target, source);\n }\n\n createBundler(\n context: BundlerContext,\n transformers: WebpackConfigTransformer[] = [],\n initialConfigs?: webpack.Configuration[],\n webpackModuleOrPath?: string | any\n ) {\n const transformerContext: GlobalWebpackConfigTransformContext = {\n mode: 'prod',\n isEnvTemplate: context.metaData?.isEnvTemplate,\n };\n // eslint-disable-next-line max-len\n const configs =\n initialConfigs ||\n this.createConfigs(context.targets, baseConfigFactory, transformers, transformerContext, context);\n return new WebpackBundler(\n context.targets,\n configs,\n this.logger,\n this.getWebpackInstance(webpackModuleOrPath, webpack),\n context.metaData\n );\n }\n\n private createConfigs(\n targets: Target[],\n factory: (target: Target, context: BundlerContext) => Configuration,\n transformers: WebpackConfigTransformer[] = [],\n transformerContext: GlobalWebpackConfigTransformContext,\n bundlerContext: BundlerContext\n ) {\n return targets.map((target) => {\n const baseConfig = factory(target, bundlerContext);\n const configMutator = new WebpackConfigMutator(baseConfig);\n const context = Object.assign({}, transformerContext, { target });\n const internalTransformers = this.generateTransformers(context, undefined, target);\n const afterMutation = runTransformersWithContext(\n configMutator.clone(),\n [...internalTransformers, ...transformers],\n context\n );\n return afterMutation.raw;\n });\n }\n\n private generateTransformers(\n _bundlerContext?: WebpackConfigTransformContext,\n devServerContext?: WebpackConfigDevServerTransformContext,\n target?: Target\n ): Array<WebpackConfigTransformer> {\n const transformers: WebpackConfigTransformer[] = [];\n // TODO: handle dev server\n const hostDeps = target?.hostDependencies || devServerContext?.hostDependencies;\n if (hostDeps) {\n if (target?.aliasHostDependencies || devServerContext?.aliasHostDependencies) {\n const peerAliasesTransformer = generateAddAliasesFromPeersTransformer(hostDeps, this.logger);\n transformers.push(peerAliasesTransformer);\n }\n if (target?.externalizeHostDependencies || devServerContext?.externalizeHostDependencies) {\n const externalsTransformer = generateExternalsTransformer(hostDeps);\n transformers.push(externalsTransformer);\n }\n }\n return transformers;\n }\n\n private getWebpackInstance(webpackOrPath?: any | string, fallback?: any) {\n if (!webpackOrPath) {\n return fallback;\n }\n if (typeof webpackOrPath === 'string') {\n // eslint-disable-next-line import/no-dynamic-require, global-require\n return require(webpackOrPath);\n }\n return webpackOrPath;\n }\n\n private createDevServerConfig(\n entry: string[],\n rootPath: string,\n devServerID: string,\n publicRoot: string,\n publicPath: string,\n componentPathsRegExps: RegExp[],\n title?: string\n ) {\n return devServerConfigFactory(\n devServerID,\n rootPath,\n entry,\n publicRoot,\n publicPath,\n componentPathsRegExps,\n this.pubsub,\n title\n );\n }\n\n static slots = [];\n\n static runtime = MainRuntime;\n static dependencies = [PubsubAspect, WorkspaceAspect, BundlerAspect, LoggerAspect];\n\n static async provider([pubsub, workspace, bundler, logger]: [PubsubMain, Workspace, BundlerMain, LoggerMain]) {\n const logPublisher = logger.createLogger(WebpackAspect.id);\n return new WebpackMain(pubsub, workspace, bundler, logPublisher);\n }\n}\n\nWebpackAspect.addRuntime(WebpackMain);\n\nexport function runTransformersWithContext(\n config: WebpackConfigMutator,\n transformers: Array<WebpackConfigTransformer | WebpackConfigDevServerTransformer> = [],\n // context: WebpackConfigTransformContext | WebpackConfigDevServerTransformContext\n context: any\n): WebpackConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n // @ts-ignore\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AASA,SAAAK,KAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,IAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,QAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,OAAA,YAAAA,CAA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AAC;EACH;EAOA,aAAasD,QAAQA,CAAC,CAACvE,MAAM,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,CAAmD,EAAE;IAC5G,MAAMqE,YAAY,GAAGrE,MAAM,CAACsE,YAAY,CAACC,yBAAa,CAAC7D,EAAE,CAAC;IAC1D,OAAO,IAAIf,WAAW,CAACE,MAAM,EAAEC,SAAS,EAAEC,OAAO,EAAEsE,YAAY,CAAC;EAClE;AACF;AAACG,OAAA,CAAA7E,WAAA,GAAAA,WAAA;AAAApB,eAAA,CArKYoB,WAAW,WA4JP,EAAE;AAAApB,eAAA,CA5JNoB,WAAW,aA8JL8E,kBAAW;AAAAlG,eAAA,CA9JjBoB,WAAW,kBA+JA,CAAC+E,iBAAY,EAAEC,4BAAe,EAAEC,wBAAa,EAAEC,sBAAY,CAAC;AAQpFN,yBAAa,CAACO,UAAU,CAACnF,WAAW,CAAC;AAE9B,SAAS+B,0BAA0BA,CACxCpB,MAA4B,EAC5BH,YAAiF,GAAG,EAAE;AACtF;AACAD,OAAY,EACU;EACtB,IAAI,CAAC6E,KAAK,CAACC,OAAO,CAAC7E,YAAY,CAAC,EAAE,OAAOG,MAAM;EAC/C,MAAM2E,SAAS,GAAG9E,YAAY,CAAC+E,MAAM,CAAC,CAACC,GAAG,EAAEC,WAAW,KAAK;IAC1D;IACA,OAAOA,WAAW,CAACD,GAAG,EAAEjF,OAAO,CAAC;EAClC,CAAC,EAAEI,MAAM,CAAC;EACV,OAAO2E,SAAS;AAClB"}
1
+ {"version":3,"names":["_webpack","data","_interopRequireDefault","require","_pubsub","_bundler","_cli","_logger","_workspace","_webpackMerge","_webpackModules","_transformers","_webpackDev","_webpack2","_webpack3","_webpack4","_webpack5","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","String","r","e","Symbol","toPrimitive","call","TypeError","Number","WebpackMain","constructor","pubsub","workspace","bundler","logger","createDevServer","context","transformers","webpackModulePath","webpackDevServerModulePath","config","createDevServerConfig","entry","path","id","rootPath","publicPath","getComponentPathsRegExps","title","wdsPath","resolve","configMutator","WebpackConfigMutator","transformerContext","assign","mode","internalTransformers","generateTransformers","undefined","afterMutation","runTransformersWithContext","clone","WebpackDevServer","raw","getWebpackInstance","webpack","mergeConfig","target","source","merge","createBundler","initialConfigs","webpackModuleOrPath","isEnvTemplate","metaData","configs","createConfigs","targets","baseConfigFactory","WebpackBundler","factory","bundlerContext","map","baseConfig","_bundlerContext","devServerContext","hostDeps","hostDependencies","aliasHostDependencies","peerAliasesTransformer","generateAddAliasesFromPeersTransformer","push","externalizeHostDependencies","externalsTransformer","generateExternalsTransformer","webpackOrPath","fallback","devServerID","publicRoot","componentPathsRegExps","devServerConfigFactory","provider","logPublisher","createLogger","WebpackAspect","exports","MainRuntime","PubsubAspect","WorkspaceAspect","BundlerAspect","LoggerAspect","addRuntime","Array","isArray","newConfig","reduce","acc","transformer"],"sources":["webpack.main.runtime.ts"],"sourcesContent":["import webpack, { Configuration } from 'webpack';\nimport PubsubAspect, { PubsubMain } from '@teambit/pubsub';\nimport {\n BundlerAspect,\n BundlerContext,\n BundlerMain,\n DevServer,\n DevServerContext,\n BundlerMode,\n Target,\n} from '@teambit/bundler';\nimport { MainRuntime } from '@teambit/cli';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { Workspace, WorkspaceAspect } from '@teambit/workspace';\nimport { merge } from 'webpack-merge';\n// We want to import it to make sure bit recognizes it as a dependency\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport WsDevServer from 'webpack-dev-server';\nimport { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';\n\nimport { generateAddAliasesFromPeersTransformer, generateExternalsTransformer } from './transformers';\nimport { configFactory as devServerConfigFactory } from './config/webpack.dev.config';\nimport { configFactory as baseConfigFactory } from './config/webpack.config';\n\nimport { WebpackAspect } from './webpack.aspect';\nimport { WebpackBundler } from './webpack.bundler';\nimport { WebpackDevServer } from './webpack.dev-server';\n\nexport type WebpackConfigTransformContext = GlobalWebpackConfigTransformContext & {\n target: Target;\n};\n\nexport type WebpackConfigDevServerTransformContext = GlobalWebpackConfigTransformContext & DevServerContext;\n\nexport type GlobalWebpackConfigTransformContext = {\n mode: BundlerMode;\n /**\n * Whether the config is for an env template bundling\n */\n isEnvTemplate?: boolean;\n /**\n * A path for the host root dir\n * Host root dir is usually the env root dir\n * This can be used in different bundle options which run require.resolve\n * for example when configuring webpack aliases or webpack expose loader on the peers deps\n */\n hostRootDir?: string;\n};\n\nexport type WebpackConfigTransformer = (\n config: WebpackConfigMutator,\n context: WebpackConfigTransformContext\n) => WebpackConfigMutator;\n\nexport type WebpackConfigDevServerTransformer = (\n config: WebpackConfigMutator,\n context: WebpackConfigDevServerTransformContext\n) => WebpackConfigMutator;\n\nexport class WebpackMain {\n constructor(\n /**\n * Pubsub extension.\n */\n public pubsub: PubsubMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * bundler extension.\n */\n private bundler: BundlerMain,\n\n /**\n * Logger extension\n */\n public logger: Logger\n ) {}\n\n /**\n * create an instance of bit-compliant webpack dev server for a set of components\n */\n createDevServer(\n context: DevServerContext,\n transformers: WebpackConfigTransformer[] = [],\n webpackModulePath?: string,\n webpackDevServerModulePath?: string\n ): DevServer {\n const config = this.createDevServerConfig(\n context.entry,\n this.workspace.path,\n context.id,\n context.rootPath,\n context.publicPath,\n this.workspace.getComponentPathsRegExps(),\n context.title\n ) as any;\n const wdsPath = webpackDevServerModulePath || require.resolve('webpack-dev-server');\n const configMutator = new WebpackConfigMutator(config);\n const transformerContext: WebpackConfigDevServerTransformContext = Object.assign(context, { mode: 'dev' as const });\n const internalTransformers = this.generateTransformers(undefined, transformerContext);\n\n const afterMutation = runTransformersWithContext(\n configMutator.clone(),\n [...internalTransformers, ...transformers],\n transformerContext\n );\n // @ts-ignore - fix this\n return new WebpackDevServer(afterMutation.raw, this.getWebpackInstance(webpackModulePath, webpack), wdsPath);\n }\n\n mergeConfig(target: any, source: any): any {\n return merge(target, source);\n }\n\n createBundler(\n context: BundlerContext,\n transformers: WebpackConfigTransformer[] = [],\n initialConfigs?: webpack.Configuration[],\n webpackModuleOrPath?: string | any\n ) {\n const transformerContext: GlobalWebpackConfigTransformContext = {\n mode: 'prod',\n isEnvTemplate: context.metaData?.isEnvTemplate,\n };\n // eslint-disable-next-line max-len\n const configs =\n initialConfigs ||\n this.createConfigs(context.targets, baseConfigFactory, transformers, transformerContext, context);\n return new WebpackBundler(\n context.targets,\n configs,\n this.logger,\n this.getWebpackInstance(webpackModuleOrPath, webpack),\n context.metaData\n );\n }\n\n private createConfigs(\n targets: Target[],\n factory: (target: Target, context: BundlerContext) => Configuration,\n transformers: WebpackConfigTransformer[] = [],\n transformerContext: GlobalWebpackConfigTransformContext,\n bundlerContext: BundlerContext\n ) {\n return targets.map((target) => {\n const baseConfig = factory(target, bundlerContext);\n const configMutator = new WebpackConfigMutator(baseConfig);\n const context = Object.assign({}, transformerContext, { target });\n const internalTransformers = this.generateTransformers(context, undefined, target);\n const afterMutation = runTransformersWithContext(\n configMutator.clone(),\n [...internalTransformers, ...transformers],\n context\n );\n return afterMutation.raw;\n });\n }\n\n private generateTransformers(\n _bundlerContext?: WebpackConfigTransformContext,\n devServerContext?: WebpackConfigDevServerTransformContext,\n target?: Target\n ): Array<WebpackConfigTransformer> {\n const transformers: WebpackConfigTransformer[] = [];\n // TODO: handle dev server\n const hostDeps = target?.hostDependencies || devServerContext?.hostDependencies;\n if (hostDeps) {\n if (target?.aliasHostDependencies || devServerContext?.aliasHostDependencies) {\n const peerAliasesTransformer = generateAddAliasesFromPeersTransformer(hostDeps, this.logger);\n transformers.push(peerAliasesTransformer);\n }\n if (target?.externalizeHostDependencies || devServerContext?.externalizeHostDependencies) {\n const externalsTransformer = generateExternalsTransformer(hostDeps);\n transformers.push(externalsTransformer);\n }\n }\n return transformers;\n }\n\n private getWebpackInstance(webpackOrPath?: any | string, fallback?: any) {\n if (!webpackOrPath) {\n return fallback;\n }\n if (typeof webpackOrPath === 'string') {\n // eslint-disable-next-line import/no-dynamic-require, global-require\n return require(webpackOrPath);\n }\n return webpackOrPath;\n }\n\n private createDevServerConfig(\n entry: string[],\n rootPath: string,\n devServerID: string,\n publicRoot: string,\n publicPath: string,\n componentPathsRegExps: RegExp[],\n title?: string\n ) {\n return devServerConfigFactory(\n devServerID,\n rootPath,\n entry,\n publicRoot,\n publicPath,\n componentPathsRegExps,\n this.pubsub,\n title\n );\n }\n\n static slots = [];\n\n static runtime = MainRuntime;\n static dependencies = [PubsubAspect, WorkspaceAspect, BundlerAspect, LoggerAspect];\n\n static async provider([pubsub, workspace, bundler, logger]: [PubsubMain, Workspace, BundlerMain, LoggerMain]) {\n const logPublisher = logger.createLogger(WebpackAspect.id);\n return new WebpackMain(pubsub, workspace, bundler, logPublisher);\n }\n}\n\nWebpackAspect.addRuntime(WebpackMain);\n\nexport function runTransformersWithContext(\n config: WebpackConfigMutator,\n transformers: Array<WebpackConfigTransformer | WebpackConfigDevServerTransformer> = [],\n // context: WebpackConfigTransformContext | WebpackConfigDevServerTransformContext\n context: any\n): WebpackConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n // @ts-ignore\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,QAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,SAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAA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D,QAAQA,CAAC,CAACtE,MAAM,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,CAAmD,EAAE;IAC5G,MAAMoE,YAAY,GAAGpE,MAAM,CAACqE,YAAY,CAACC,yBAAa,CAAC5D,EAAE,CAAC;IAC1D,OAAO,IAAIf,WAAW,CAACE,MAAM,EAAEC,SAAS,EAAEC,OAAO,EAAEqE,YAAY,CAAC;EAClE;AACF;AAACG,OAAA,CAAA5E,WAAA,GAAAA,WAAA;AAAApB,eAAA,CArKYoB,WAAW,WA4JP,EAAE;AAAApB,eAAA,CA5JNoB,WAAW,aA8JL6E,kBAAW;AAAAjG,eAAA,CA9JjBoB,WAAW,kBA+JA,CAAC8E,iBAAY,EAAEC,4BAAe,EAAEC,wBAAa,EAAEC,sBAAY,CAAC;AAQpFN,yBAAa,CAACO,UAAU,CAAClF,WAAW,CAAC;AAE9B,SAAS+B,0BAA0BA,CACxCpB,MAA4B,EAC5BH,YAAiF,GAAG,EAAE;AACtF;AACAD,OAAY,EACU;EACtB,IAAI,CAAC4E,KAAK,CAACC,OAAO,CAAC5E,YAAY,CAAC,EAAE,OAAOG,MAAM;EAC/C,MAAM0E,SAAS,GAAG7E,YAAY,CAAC8E,MAAM,CAAC,CAACC,GAAG,EAAEC,WAAW,KAAK;IAC1D;IACA,OAAOA,WAAW,CAACD,GAAG,EAAEhF,OAAO,CAAC;EAClC,CAAC,EAAEI,MAAM,CAAC;EACV,OAAO0E,SAAS;AAClB"}
package/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ export type {
2
+ WebpackMain,
3
+ WebpackConfigTransformer,
4
+ WebpackConfigTransformContext,
5
+ WebpackConfigDevServerTransformContext,
6
+ GlobalWebpackConfigTransformContext,
7
+ WebpackConfigDevServerTransformer,
8
+ } from './webpack.main.runtime';
9
+ export { runTransformersWithContext } from './webpack.main.runtime';
10
+ export { WebpackAspect } from './webpack.aspect';
11
+ export { WebpackDevServer } from './webpack.dev-server';
12
+ export { WebpackBundler } from './webpack.bundler';
13
+ export type { WebpackConfigWithDevServer } from './webpack.dev-server';
14
+ export * from './events';
15
+ export type { Configuration } from 'webpack';
16
+ export { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';
17
+ export { WebpackBitReporterPlugin } from './plugins/webpack-bit-reporter-plugin';
18
+ export { fallbacks } from './config/webpack-fallbacks';
19
+ export { fallbacksAliases } from './config/webpack-fallbacks-aliases';
20
+ export { fallbacksProvidePluginConfig } from './config/webpack-fallbacks-provide-plugin-config';
21
+ export {
22
+ GenerateBodyInjectionTransformer,
23
+ BodyInjectionOptions,
24
+ generateAddAliasesFromPeersTransformer,
25
+ generateExposePeersTransformer,
26
+ generateExternalsTransformer,
27
+ GenerateHeadInjectionTransformer,
28
+ HeadInjectionOptions,
29
+ } from './transformers';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/webpack",
3
- "version": "1.0.107",
3
+ "version": "1.0.108",
4
4
  "homepage": "https://bit.cloud/teambit/webpack/webpack",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.webpack",
8
8
  "name": "webpack",
9
- "version": "1.0.107"
9
+ "version": "1.0.108"
10
10
  },
11
11
  "dependencies": {
12
12
  "webpack": "5.84.1",
@@ -43,16 +43,14 @@
43
43
  "expose-loader": "3.1.0",
44
44
  "inject-body-webpack-plugin": "1.3.0",
45
45
  "enhanced-resolve": "4.5.0",
46
- "core-js": "^3.0.0",
47
- "@babel/runtime": "7.20.0",
48
46
  "@teambit/harmony": "0.4.6",
49
47
  "@teambit/bit-error": "0.0.404",
50
48
  "@teambit/webpack.modules.config-mutator": "0.0.164",
51
- "@teambit/bundler": "1.0.107",
52
- "@teambit/logger": "0.0.932",
53
- "@teambit/cli": "0.0.839",
54
- "@teambit/pubsub": "1.0.107",
55
- "@teambit/workspace": "1.0.107",
49
+ "@teambit/bundler": "1.0.108",
50
+ "@teambit/logger": "0.0.933",
51
+ "@teambit/cli": "0.0.840",
52
+ "@teambit/pubsub": "1.0.108",
53
+ "@teambit/workspace": "1.0.108",
56
54
  "@teambit/webpack.modules.generate-expose-loaders": "0.0.14",
57
55
  "@teambit/webpack.modules.generate-externals": "0.0.15",
58
56
  "@teambit/webpack.plugins.inject-head-webpack-plugin": "0.0.8"
@@ -60,18 +58,16 @@
60
58
  "devDependencies": {
61
59
  "@types/webpack": "5.28.1",
62
60
  "@types/lodash": "4.14.165",
63
- "@types/react": "^17.0.8",
64
61
  "@types/find-root": "1.1.2",
65
62
  "@types/react-dev-utils": "9.0.10",
66
- "@types/node": "12.20.4",
67
- "@types/react-dom": "^17.0.5",
68
- "@types/jest": "^26.0.0",
69
- "@types/testing-library__jest-dom": "5.9.5"
63
+ "@types/jest": "^29.2.2",
64
+ "@types/testing-library__jest-dom": "^5.9.5",
65
+ "@teambit/harmony.envs.core-aspect-env": "0.0.13"
70
66
  },
71
67
  "peerDependencies": {
72
- "@teambit/legacy": "1.0.624",
73
- "react": "^16.8.0 || ^17.0.0",
74
- "react-dom": "^16.8.0 || ^17.0.0"
68
+ "@teambit/legacy": "1.0.625",
69
+ "react": "^17.0.0 || ^18.0.0",
70
+ "@types/react": "^18.2.12"
75
71
  },
76
72
  "license": "Apache-2.0",
77
73
  "optionalDependencies": {},
@@ -85,7 +81,7 @@
85
81
  },
86
82
  "private": false,
87
83
  "engines": {
88
- "node": ">=12.22.0"
84
+ "node": ">=16.0.0"
89
85
  },
90
86
  "repository": {
91
87
  "type": "git",
@@ -94,12 +90,9 @@
94
90
  "keywords": [
95
91
  "bit",
96
92
  "bit-aspect",
93
+ "bit-core-aspect",
97
94
  "components",
98
95
  "collaboration",
99
- "web",
100
- "react",
101
- "react-components",
102
- "angular",
103
- "angular-components"
96
+ "web"
104
97
  ]
105
98
  }
package/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }
@@ -0,0 +1,5 @@
1
+ import { Aspect } from '@teambit/harmony';
2
+
3
+ export const WebpackAspect = Aspect.create({
4
+ id: 'teambit.webpack/webpack',
5
+ });
@@ -0,0 +1,162 @@
1
+ import { BitError } from '@teambit/bit-error';
2
+ import type { Bundler, BundlerResult, Asset, Target, EntriesAssetsMap, BundlerContextMetaData } from '@teambit/bundler';
3
+ import type { Logger } from '@teambit/logger';
4
+ import { compact, isEmpty } from 'lodash';
5
+ import mapSeries from 'p-map-series';
6
+ import type { Compiler, Configuration, StatsCompilation, StatsAsset } from 'webpack';
7
+ import { sep } from 'path';
8
+
9
+ type AssetsMap = { [assetId: string]: Asset };
10
+ export class WebpackBundler implements Bundler {
11
+ constructor(
12
+ /**
13
+ * targets to bundle.
14
+ */
15
+ private targets: Target[],
16
+
17
+ /**
18
+ * webpack configuration.
19
+ */
20
+ private configs: Configuration[],
21
+
22
+ private logger: Logger,
23
+
24
+ private webpack,
25
+
26
+ private metaData?: BundlerContextMetaData | undefined
27
+ ) {}
28
+
29
+ async run(): Promise<BundlerResult[]> {
30
+ const startTime = Date.now();
31
+ const compilers = this.configs.map((config: any) => this.webpack(config));
32
+ const initiator = this.metaData?.initiator;
33
+ const envId = this.metaData?.envId;
34
+ const initiatorMessage = initiator ? `process initiated by: ${initiator}.` : '';
35
+ const envIdMessage = envId ? `config created by env: ${envId}.` : '';
36
+
37
+ const longProcessLogger = this.logger.createLongProcessLogger('running Webpack bundler', compilers.length);
38
+ const componentOutput = await mapSeries(compilers, (compiler: Compiler) => {
39
+ const components = this.getComponents(compiler.outputPath);
40
+ const componentsLengthMessage = `running on ${components.length} components`;
41
+ const fullMessage = `${initiatorMessage} ${envIdMessage} ${componentsLengthMessage}`;
42
+ const ids = components.map((component) => component.id.toString()).join(', ');
43
+ longProcessLogger.logProgress(`${fullMessage}`);
44
+ this.logger.debug(`${fullMessage}\ncomponents ids: ${ids}`);
45
+ return new Promise((resolve) => {
46
+ // TODO: split to multiple processes to reduce time and configure concurrent builds.
47
+ // @see https://github.com/trivago/parallel-webpack
48
+ return compiler.run((err, stats) => {
49
+ if (err) {
50
+ this.logger.error('get error from webpack compiler, full error:', err);
51
+
52
+ return resolve({
53
+ errors: [`${err.toString()}\n${err.stack}`],
54
+ components,
55
+ });
56
+ }
57
+ if (!stats) throw new BitError('unknown build error');
58
+ // const info = stats.toJson();
59
+
60
+ const info = stats.toJson({
61
+ all: false,
62
+ entrypoints: true,
63
+ warnings: true,
64
+ errors: true,
65
+ assets: true,
66
+ chunkGroupAuxiliary: true,
67
+ relatedAssets: true,
68
+ cachedAssets: true,
69
+ });
70
+ const assetsMap = this.getAssets(info);
71
+ const entriesAssetsMap = this.getEntriesAssetsMap(info, assetsMap);
72
+
73
+ return resolve({
74
+ assets: Object.values(assetsMap),
75
+ assetsByChunkName: info.assetsByChunkName,
76
+ entriesAssetsMap,
77
+ errors: this.getErrors(info),
78
+ outputPath: stats.compilation.outputOptions.path,
79
+ components,
80
+ warnings: info.warnings,
81
+ startTime,
82
+ endTime: Date.now(),
83
+ });
84
+ });
85
+ });
86
+ });
87
+ longProcessLogger.end();
88
+ return componentOutput as BundlerResult[];
89
+ }
90
+
91
+ private getErrors(stats: StatsCompilation): Error[] {
92
+ if (!stats.errors) return [];
93
+ const fieldsToShow = ['message', 'moduleId', 'moduleName', 'moduleIdentifier', 'loc'];
94
+ return stats.errors.map((webpackError) => {
95
+ const lines = fieldsToShow.map((fieldName) => {
96
+ if (webpackError[fieldName]) {
97
+ return `${fieldName}: ${webpackError[fieldName]}`;
98
+ }
99
+ return undefined;
100
+ });
101
+ const errorMessage = compact(lines).join('\n');
102
+ return new BitError(errorMessage);
103
+ });
104
+ }
105
+
106
+ private getAssets(stats: StatsCompilation): AssetsMap {
107
+ if (!stats.assets) return {};
108
+ return stats.assets.reduce((acc, asset) => {
109
+ acc[asset.name] = {
110
+ name: asset.name,
111
+ size: asset.size,
112
+ compressedSize: this.getCompressedSize(asset),
113
+ };
114
+ return acc;
115
+ }, {});
116
+ }
117
+
118
+ private getEntriesAssetsMap(stats: StatsCompilation, assetsMap: AssetsMap): EntriesAssetsMap {
119
+ const entriesMap = stats.entrypoints;
120
+ if (!entriesMap || !Object.keys(assetsMap).length) return {};
121
+ Object.entries(entriesMap).forEach(([, entryVal]) => {
122
+ let compressedAssetsSize = 0;
123
+ let compressedAuxiliaryAssetsSize = 0;
124
+ entryVal.assets?.forEach((asset) => {
125
+ const compressedSize = assetsMap[asset.name]?.compressedSize;
126
+ if (compressedSize) {
127
+ // @ts-ignore
128
+ asset.compressedSize = compressedSize;
129
+ compressedAssetsSize += compressedSize;
130
+ }
131
+ });
132
+ entryVal.auxiliaryAssets?.forEach((asset) => {
133
+ const compressedSize = assetsMap[asset.name]?.compressedSize;
134
+ if (compressedSize) {
135
+ // @ts-ignore
136
+ asset.compressedSize = compressedSize;
137
+ compressedAuxiliaryAssetsSize += compressedSize;
138
+ }
139
+ });
140
+ entryVal.compressedAssetsSize = compressedAssetsSize;
141
+ entryVal.compressedAuxiliaryAssetsSize = compressedAuxiliaryAssetsSize;
142
+ });
143
+ return entriesMap as any as EntriesAssetsMap;
144
+ }
145
+
146
+ private getCompressedSize(asset: StatsAsset): number | undefined {
147
+ if (!asset.related || isEmpty(asset.related)) return undefined;
148
+ const gzipped = asset.related.find((relatedAsset) => {
149
+ return relatedAsset.type === 'gzipped';
150
+ });
151
+ if (!gzipped) return undefined;
152
+ return gzipped.size;
153
+ }
154
+
155
+ private getComponents(outputPath: string) {
156
+ const path = outputPath.substring(0, outputPath.lastIndexOf(sep));
157
+ const target = this.targets.find((targetCandidate) => path === targetCandidate.outputPath);
158
+
159
+ if (!target) throw new Error(`Could not find component id for path "${path}"`);
160
+ return target.components;
161
+ }
162
+ }
@@ -0,0 +1,95 @@
1
+ import { join } from 'path';
2
+ import type { DevServer } from '@teambit/bundler';
3
+ import findRoot from 'find-root';
4
+ import type { Server } from 'http';
5
+ import type { webpack as webpackCompiler, Configuration } from 'webpack';
6
+ import type * as WDS from 'webpack-dev-server';
7
+ import { inspect } from 'util';
8
+ import { WebpackAspect } from './webpack.aspect';
9
+
10
+ export interface WebpackConfigWithDevServer extends Configuration {
11
+ devServer: WDS.Configuration;
12
+ favicon?: string;
13
+ }
14
+ export class WebpackDevServer implements DevServer {
15
+ private readonly WsDevServer: typeof WDS;
16
+ constructor(
17
+ private config: WebpackConfigWithDevServer,
18
+ private webpack: typeof webpackCompiler,
19
+ /**
20
+ * path to the webpack-dev-server module or instance of webpack-dev-server.
21
+ * this accept getting an instance for backward compatibility.
22
+ */
23
+ private webpackDevServer: string | typeof WDS
24
+ ) {
25
+ if (typeof this.webpackDevServer === 'string') {
26
+ // eslint-disable-next-line import/no-dynamic-require, global-require
27
+ this.WsDevServer = require(this.webpackDevServer);
28
+ } else {
29
+ this.WsDevServer = this.webpackDevServer;
30
+ }
31
+ }
32
+
33
+ private getCompiler(): any {
34
+ return this.webpack(this.config);
35
+ }
36
+
37
+ id = WebpackAspect.id;
38
+
39
+ displayName = 'Webpack dev server';
40
+
41
+ version(): string {
42
+ if (typeof this.webpackDevServer !== 'string') {
43
+ return 'unknown';
44
+ }
45
+ // Resolve version from the webpack-dev-server package.json
46
+ try {
47
+ const root = findRoot(this.webpackDevServer);
48
+ const packageJsonPath = join(root, 'package.json');
49
+ // eslint-disable-next-line import/no-dynamic-require, global-require
50
+ const packageJson = require(packageJsonPath);
51
+ return packageJson.version;
52
+ } catch (err) {
53
+ return 'unknown';
54
+ }
55
+ }
56
+
57
+ displayConfig(): string {
58
+ return inspect(this.config, { depth: 10 });
59
+ }
60
+
61
+ async listen(port: number): Promise<Server> {
62
+ if (!this.config.devServer) {
63
+ throw new Error('Missing devServer configuration for webpack');
64
+ }
65
+ // Prevent different port between the config port and the listen arg port
66
+ this.config.devServer.port = port;
67
+
68
+ // Adding signal listeners to make sure we immediately close the process on sigint / sigterm (otherwise webpack dev server closing will take time)
69
+ this.addSignalListener();
70
+
71
+ // Compatibility check for Webpack dev server v3 (e.g. for Angular v8)
72
+ if (typeof (this.WsDevServer as any).addDevServerEntrypoints !== 'undefined') {
73
+ // @ts-ignore in the capsules it throws an error about compatibilities issues between webpack.compiler and webpackDevServer/webpack/compiler
74
+ const webpackDs = new (this.WsDevServer as any)(this.getCompiler(), this.config.devServer);
75
+ return webpackDs.listen(port);
76
+ }
77
+
78
+ // @ts-ignore in the capsules it throws an error about compatibilities issues between webpack.compiler and webpackDevServer/webpack/compiler
79
+ const webpackDs: WDS = new this.WsDevServer(this.config.devServer, this.getCompiler());
80
+ await webpackDs.start();
81
+
82
+ // @ts-ignore
83
+ return webpackDs.server;
84
+ }
85
+
86
+ private addSignalListener() {
87
+ process.on('SIGTERM', () => {
88
+ process.exit();
89
+ });
90
+
91
+ process.on('SIGINT', () => {
92
+ process.exit();
93
+ });
94
+ }
95
+ }
@@ -0,0 +1,241 @@
1
+ import webpack, { Configuration } from 'webpack';
2
+ import PubsubAspect, { PubsubMain } from '@teambit/pubsub';
3
+ import {
4
+ BundlerAspect,
5
+ BundlerContext,
6
+ BundlerMain,
7
+ DevServer,
8
+ DevServerContext,
9
+ BundlerMode,
10
+ Target,
11
+ } from '@teambit/bundler';
12
+ import { MainRuntime } from '@teambit/cli';
13
+ import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
14
+ import { Workspace, WorkspaceAspect } from '@teambit/workspace';
15
+ import { merge } from 'webpack-merge';
16
+ // We want to import it to make sure bit recognizes it as a dependency
17
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
+ import WsDevServer from 'webpack-dev-server';
19
+ import { WebpackConfigMutator } from '@teambit/webpack.modules.config-mutator';
20
+
21
+ import { generateAddAliasesFromPeersTransformer, generateExternalsTransformer } from './transformers';
22
+ import { configFactory as devServerConfigFactory } from './config/webpack.dev.config';
23
+ import { configFactory as baseConfigFactory } from './config/webpack.config';
24
+
25
+ import { WebpackAspect } from './webpack.aspect';
26
+ import { WebpackBundler } from './webpack.bundler';
27
+ import { WebpackDevServer } from './webpack.dev-server';
28
+
29
+ export type WebpackConfigTransformContext = GlobalWebpackConfigTransformContext & {
30
+ target: Target;
31
+ };
32
+
33
+ export type WebpackConfigDevServerTransformContext = GlobalWebpackConfigTransformContext & DevServerContext;
34
+
35
+ export type GlobalWebpackConfigTransformContext = {
36
+ mode: BundlerMode;
37
+ /**
38
+ * Whether the config is for an env template bundling
39
+ */
40
+ isEnvTemplate?: boolean;
41
+ /**
42
+ * A path for the host root dir
43
+ * Host root dir is usually the env root dir
44
+ * This can be used in different bundle options which run require.resolve
45
+ * for example when configuring webpack aliases or webpack expose loader on the peers deps
46
+ */
47
+ hostRootDir?: string;
48
+ };
49
+
50
+ export type WebpackConfigTransformer = (
51
+ config: WebpackConfigMutator,
52
+ context: WebpackConfigTransformContext
53
+ ) => WebpackConfigMutator;
54
+
55
+ export type WebpackConfigDevServerTransformer = (
56
+ config: WebpackConfigMutator,
57
+ context: WebpackConfigDevServerTransformContext
58
+ ) => WebpackConfigMutator;
59
+
60
+ export class WebpackMain {
61
+ constructor(
62
+ /**
63
+ * Pubsub extension.
64
+ */
65
+ public pubsub: PubsubMain,
66
+
67
+ /**
68
+ * workspace extension.
69
+ */
70
+ private workspace: Workspace,
71
+
72
+ /**
73
+ * bundler extension.
74
+ */
75
+ private bundler: BundlerMain,
76
+
77
+ /**
78
+ * Logger extension
79
+ */
80
+ public logger: Logger
81
+ ) {}
82
+
83
+ /**
84
+ * create an instance of bit-compliant webpack dev server for a set of components
85
+ */
86
+ createDevServer(
87
+ context: DevServerContext,
88
+ transformers: WebpackConfigTransformer[] = [],
89
+ webpackModulePath?: string,
90
+ webpackDevServerModulePath?: string
91
+ ): DevServer {
92
+ const config = this.createDevServerConfig(
93
+ context.entry,
94
+ this.workspace.path,
95
+ context.id,
96
+ context.rootPath,
97
+ context.publicPath,
98
+ this.workspace.getComponentPathsRegExps(),
99
+ context.title
100
+ ) as any;
101
+ const wdsPath = webpackDevServerModulePath || require.resolve('webpack-dev-server');
102
+ const configMutator = new WebpackConfigMutator(config);
103
+ const transformerContext: WebpackConfigDevServerTransformContext = Object.assign(context, { mode: 'dev' as const });
104
+ const internalTransformers = this.generateTransformers(undefined, transformerContext);
105
+
106
+ const afterMutation = runTransformersWithContext(
107
+ configMutator.clone(),
108
+ [...internalTransformers, ...transformers],
109
+ transformerContext
110
+ );
111
+ // @ts-ignore - fix this
112
+ return new WebpackDevServer(afterMutation.raw, this.getWebpackInstance(webpackModulePath, webpack), wdsPath);
113
+ }
114
+
115
+ mergeConfig(target: any, source: any): any {
116
+ return merge(target, source);
117
+ }
118
+
119
+ createBundler(
120
+ context: BundlerContext,
121
+ transformers: WebpackConfigTransformer[] = [],
122
+ initialConfigs?: webpack.Configuration[],
123
+ webpackModuleOrPath?: string | any
124
+ ) {
125
+ const transformerContext: GlobalWebpackConfigTransformContext = {
126
+ mode: 'prod',
127
+ isEnvTemplate: context.metaData?.isEnvTemplate,
128
+ };
129
+ // eslint-disable-next-line max-len
130
+ const configs =
131
+ initialConfigs ||
132
+ this.createConfigs(context.targets, baseConfigFactory, transformers, transformerContext, context);
133
+ return new WebpackBundler(
134
+ context.targets,
135
+ configs,
136
+ this.logger,
137
+ this.getWebpackInstance(webpackModuleOrPath, webpack),
138
+ context.metaData
139
+ );
140
+ }
141
+
142
+ private createConfigs(
143
+ targets: Target[],
144
+ factory: (target: Target, context: BundlerContext) => Configuration,
145
+ transformers: WebpackConfigTransformer[] = [],
146
+ transformerContext: GlobalWebpackConfigTransformContext,
147
+ bundlerContext: BundlerContext
148
+ ) {
149
+ return targets.map((target) => {
150
+ const baseConfig = factory(target, bundlerContext);
151
+ const configMutator = new WebpackConfigMutator(baseConfig);
152
+ const context = Object.assign({}, transformerContext, { target });
153
+ const internalTransformers = this.generateTransformers(context, undefined, target);
154
+ const afterMutation = runTransformersWithContext(
155
+ configMutator.clone(),
156
+ [...internalTransformers, ...transformers],
157
+ context
158
+ );
159
+ return afterMutation.raw;
160
+ });
161
+ }
162
+
163
+ private generateTransformers(
164
+ _bundlerContext?: WebpackConfigTransformContext,
165
+ devServerContext?: WebpackConfigDevServerTransformContext,
166
+ target?: Target
167
+ ): Array<WebpackConfigTransformer> {
168
+ const transformers: WebpackConfigTransformer[] = [];
169
+ // TODO: handle dev server
170
+ const hostDeps = target?.hostDependencies || devServerContext?.hostDependencies;
171
+ if (hostDeps) {
172
+ if (target?.aliasHostDependencies || devServerContext?.aliasHostDependencies) {
173
+ const peerAliasesTransformer = generateAddAliasesFromPeersTransformer(hostDeps, this.logger);
174
+ transformers.push(peerAliasesTransformer);
175
+ }
176
+ if (target?.externalizeHostDependencies || devServerContext?.externalizeHostDependencies) {
177
+ const externalsTransformer = generateExternalsTransformer(hostDeps);
178
+ transformers.push(externalsTransformer);
179
+ }
180
+ }
181
+ return transformers;
182
+ }
183
+
184
+ private getWebpackInstance(webpackOrPath?: any | string, fallback?: any) {
185
+ if (!webpackOrPath) {
186
+ return fallback;
187
+ }
188
+ if (typeof webpackOrPath === 'string') {
189
+ // eslint-disable-next-line import/no-dynamic-require, global-require
190
+ return require(webpackOrPath);
191
+ }
192
+ return webpackOrPath;
193
+ }
194
+
195
+ private createDevServerConfig(
196
+ entry: string[],
197
+ rootPath: string,
198
+ devServerID: string,
199
+ publicRoot: string,
200
+ publicPath: string,
201
+ componentPathsRegExps: RegExp[],
202
+ title?: string
203
+ ) {
204
+ return devServerConfigFactory(
205
+ devServerID,
206
+ rootPath,
207
+ entry,
208
+ publicRoot,
209
+ publicPath,
210
+ componentPathsRegExps,
211
+ this.pubsub,
212
+ title
213
+ );
214
+ }
215
+
216
+ static slots = [];
217
+
218
+ static runtime = MainRuntime;
219
+ static dependencies = [PubsubAspect, WorkspaceAspect, BundlerAspect, LoggerAspect];
220
+
221
+ static async provider([pubsub, workspace, bundler, logger]: [PubsubMain, Workspace, BundlerMain, LoggerMain]) {
222
+ const logPublisher = logger.createLogger(WebpackAspect.id);
223
+ return new WebpackMain(pubsub, workspace, bundler, logPublisher);
224
+ }
225
+ }
226
+
227
+ WebpackAspect.addRuntime(WebpackMain);
228
+
229
+ export function runTransformersWithContext(
230
+ config: WebpackConfigMutator,
231
+ transformers: Array<WebpackConfigTransformer | WebpackConfigDevServerTransformer> = [],
232
+ // context: WebpackConfigTransformContext | WebpackConfigDevServerTransformContext
233
+ context: any
234
+ ): WebpackConfigMutator {
235
+ if (!Array.isArray(transformers)) return config;
236
+ const newConfig = transformers.reduce((acc, transformer) => {
237
+ // @ts-ignore
238
+ return transformer(acc, context);
239
+ }, config);
240
+ return newConfig;
241
+ }