@teambit/webpack 1.0.655 → 1.0.656
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.
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.webpack_webpack@1.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.webpack_webpack@1.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.webpack_webpack@1.0.656/dist/webpack.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.webpack_webpack@1.0.656/dist/webpack.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
package/dist/webpack.bundler.js
CHANGED
@@ -57,14 +57,19 @@ class WebpackBundler {
|
|
57
57
|
const initiatorMessage = initiator ? `process initiated by: ${initiator}.` : '';
|
58
58
|
const envIdMessage = envId ? `config created by env: ${envId}.` : '';
|
59
59
|
const longProcessLogger = this.logger.createLongProcessLogger('running Webpack bundler', compilers.length);
|
60
|
-
|
60
|
+
|
61
|
+
// Process compilers sequentially to control memory usage
|
62
|
+
// For better memory management, webpack compilers are run one at a time
|
63
|
+
// and cleaned up after each run to prevent memory accumulation
|
64
|
+
const componentOutput = await (0, _pMapSeries().default)(compilers, async compiler => {
|
61
65
|
const components = this.getComponents(compiler.outputPath);
|
62
66
|
const componentsLengthMessage = `running on ${components.length} components`;
|
63
67
|
const fullMessage = `${initiatorMessage} ${envIdMessage} ${componentsLengthMessage}`;
|
68
|
+
this.logger.debug(`${fullMessage} memory usage: ${Math.round(process.memoryUsage().heapUsed / 1024 / 1024 / 1024 * 100) / 100} GB`);
|
64
69
|
const ids = components.map(component => component.id.toString()).join(', ');
|
65
70
|
longProcessLogger.logProgress(`${fullMessage}`);
|
66
71
|
this.logger.debug(`${fullMessage}\ncomponents ids: ${ids}`);
|
67
|
-
|
72
|
+
const result = await new Promise(resolve => {
|
68
73
|
// TODO: split to multiple processes to reduce time and configure concurrent builds.
|
69
74
|
// @see https://github.com/trivago/parallel-webpack
|
70
75
|
return compiler.run((err, stats) => {
|
@@ -103,6 +108,21 @@ class WebpackBundler {
|
|
103
108
|
});
|
104
109
|
});
|
105
110
|
});
|
111
|
+
try {
|
112
|
+
// Close the compiler to free up file watchers and resources
|
113
|
+
await new Promise(resolve => {
|
114
|
+
compiler.close(() => {
|
115
|
+
resolve();
|
116
|
+
});
|
117
|
+
});
|
118
|
+
if (compiler.cache) {
|
119
|
+
// Force purge of webpack's internal cache
|
120
|
+
compiler.cache?.purge?.();
|
121
|
+
}
|
122
|
+
} catch (error) {
|
123
|
+
this.logger.debug('Error during compiler cleanup:', error);
|
124
|
+
}
|
125
|
+
return result;
|
106
126
|
});
|
107
127
|
longProcessLogger.end();
|
108
128
|
return componentOutput;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_bitError","data","require","_lodash","_pMapSeries","_interopRequireDefault","_path","e","__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\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,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAGpB,MAAMG,cAAc,CAAoB;EAC7CC,WAAWA;EACT;AACJ;AACA;EACYC,OAAiB;EAEzB;AACJ;AACA;EACYC,OAAwB,EAExBC,M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ACA,KAAK,CAACa,OAAO,IAAI,IAAAC,iBAAO,EAACd,KAAK,CAACa,OAAO,CAAC,EAAE,OAAOlB,SAAS;IAC9D,MAAMoB,OAAO,GAAGf,KAAK,CAACa,OAAO,CAACG,IAAI,CAAEC,YAAY,IAAK;MACnD,OAAOA,YAAY,CAACC,IAAI,KAAK,SAAS;IACxC,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,CAAC,yCAAyCpC,IAAI,GAAG,CAAC;IAC9E,OAAOkC,MAAM,CAACzE,UAAU;EAC1B;AACF;AAAC4E,OAAA,CAAApG,cAAA,GAAAA,cAAA","ignoreList":[]}
|
1
|
+
{"version":3,"names":["_bitError","data","require","_lodash","_pMapSeries","_interopRequireDefault","_path","e","__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","debug","Math","round","process","memoryUsage","heapUsed","ids","component","id","toString","join","logProgress","result","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","close","cache","purge","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\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\n // Process compilers sequentially to control memory usage\n // For better memory management, webpack compilers are run one at a time\n // and cleaned up after each run to prevent memory accumulation\n const componentOutput = await mapSeries(compilers, async (compiler: Compiler) => {\n const components = this.getComponents(compiler.outputPath);\n const componentsLengthMessage = `running on ${components.length} components`;\n const fullMessage = `${initiatorMessage} ${envIdMessage} ${componentsLengthMessage}`;\n this.logger.debug(\n `${fullMessage} memory usage: ${Math.round((process.memoryUsage().heapUsed / 1024 / 1024 / 1024) * 100) / 100} GB`\n );\n const ids = components.map((component) => component.id.toString()).join(', ');\n longProcessLogger.logProgress(`${fullMessage}`);\n this.logger.debug(`${fullMessage}\\ncomponents ids: ${ids}`);\n\n const result = await new Promise<any>((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 try {\n // Close the compiler to free up file watchers and resources\n await new Promise<void>((resolve) => {\n compiler.close(() => {\n resolve();\n });\n });\n if (compiler.cache) {\n // Force purge of webpack's internal cache\n (compiler as any).cache?.purge?.();\n }\n } catch (error) {\n this.logger.debug('Error during compiler cleanup:', error);\n }\n\n return result;\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;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AAI,IAAAC,iBAAO,EAACd,KAAK,CAACa,OAAO,CAAC,EAAE,OAAOlB,SAAS;IAC9D,MAAMoB,OAAO,GAAGf,KAAK,CAACa,OAAO,CAACG,IAAI,CAAEC,YAAY,IAAK;MACnD,OAAOA,YAAY,CAACC,IAAI,KAAK,SAAS;IACxC,CAAC,CAAC;IACF,IAAI,CAACH,OAAO,EAAE,OAAOpB,SAAS;IAC9B,OAAOoB,OAAO,CAACb,IAAI;EACrB;EAEQ7D,aAAaA,CAACC,UAAkB,EAAE;IACxC,MAAM2C,IAAI,GAAG3C,UAAU,CAAC6E,SAAS,CAAC,CAAC,EAAE7E,UAAU,CAAC8E,WAAW,CAACC,WAAG,CAAC,CAAC;IACjE,MAAMC,MAAM,GAAG,IAAI,CAACxG,OAAO,CAACkG,IAAI,CAAEO,eAAe,IAAKtC,IAAI,KAAKsC,eAAe,CAACjF,UAAU,CAAC;IAE1F,IAAI,CAACgF,MAAM,EAAE,MAAM,IAAIE,KAAK,CAAC,yCAAyCvC,IAAI,GAAG,CAAC;IAC9E,OAAOqC,MAAM,CAAClF,UAAU;EAC1B;AACF;AAACqF,OAAA,CAAA7G,cAAA,GAAAA,cAAA","ignoreList":[]}
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/webpack",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.656",
|
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.
|
9
|
+
"version": "1.0.656"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"webpack": "5.97.1",
|
@@ -49,14 +49,14 @@
|
|
49
49
|
"@teambit/bit-error": "0.0.404",
|
50
50
|
"@teambit/toolbox.path.path": "0.0.8",
|
51
51
|
"@teambit/preview.cli.dev-server-events-listener": "0.0.1",
|
52
|
-
"@teambit/
|
53
|
-
"@teambit/
|
54
|
-
"@teambit/
|
55
|
-
"@teambit/
|
56
|
-
"@teambit/
|
57
|
-
"@teambit/
|
58
|
-
"@teambit/
|
59
|
-
"@teambit/
|
52
|
+
"@teambit/bundler": "1.0.656",
|
53
|
+
"@teambit/logger": "0.0.1326",
|
54
|
+
"@teambit/cli": "0.0.1233",
|
55
|
+
"@teambit/pubsub": "1.0.656",
|
56
|
+
"@teambit/workspace": "1.0.656",
|
57
|
+
"@teambit/webpack.modules.generate-expose-loaders": "0.0.22",
|
58
|
+
"@teambit/webpack.modules.generate-externals": "0.0.22",
|
59
|
+
"@teambit/webpack.plugins.inject-head-webpack-plugin": "0.0.15"
|
60
60
|
},
|
61
61
|
"devDependencies": {
|
62
62
|
"@types/webpack": "5.28.5",
|