@teambit/ui 0.0.518 → 0.0.522
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ssr/render-middleware.js +8 -3
- package/dist/ssr/render-middleware.js.map +1 -1
- package/dist/start-plugin.d.ts +2 -1
- package/dist/start.cmd.js +2 -1
- package/dist/start.cmd.js.map +1 -1
- package/dist/ui-server.d.ts +3 -0
- package/dist/ui-server.js +8 -3
- package/dist/ui-server.js.map +1 -1
- package/dist/webpack/webpack.base.config.js +4 -3
- package/dist/webpack/webpack.base.config.js.map +1 -1
- package/package-tar/teambit-ui-0.0.522.tgz +0 -0
- package/package.json +23 -23
- package/ssr/render-middleware.ts +8 -3
- package/start-plugin.ts +4 -1
- package/start.cmd.tsx +3 -1
- package/ui-server.ts +9 -3
- package/webpack/webpack.base.config.ts +4 -3
- package/package-tar/teambit-ui-0.0.518.tgz +0 -0
|
@@ -137,14 +137,14 @@ async function loadRuntime(root, {
|
|
|
137
137
|
const manifestFilepath = _path().default.join(root, 'asset-manifest.json');
|
|
138
138
|
|
|
139
139
|
if (!fs().existsSync(manifestFilepath)) {
|
|
140
|
-
logger.warn('[ssr] -
|
|
140
|
+
logger.warn('[ssr] - Skipping setup (cannot find asset manifest file)');
|
|
141
141
|
return undefined;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
assets = await parseManifest(manifestFilepath);
|
|
145
145
|
|
|
146
146
|
if (!assets) {
|
|
147
|
-
logger.warn('[ssr] - failed parsing assets manifest
|
|
147
|
+
logger.warn('[ssr] - Skipping setup (failed parsing assets manifest)');
|
|
148
148
|
return undefined;
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -166,14 +166,19 @@ async function loadRuntime(root, {
|
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
async function parseManifest(filepath) {
|
|
169
|
+
async function parseManifest(filepath, logger) {
|
|
170
170
|
try {
|
|
171
171
|
const file = await fs().readFile(filepath);
|
|
172
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('[ssr] - ✓ aread manifest file');
|
|
172
173
|
const contents = file.toString();
|
|
173
174
|
const parsed = JSON.parse(contents);
|
|
175
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('[ssr] - ✓ prased manifest file', parsed);
|
|
174
176
|
const assets = getAssets(parsed);
|
|
177
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('[ssr] - ✓ extracted data from manifest file', assets);
|
|
175
178
|
return assets;
|
|
176
179
|
} catch (e) {
|
|
180
|
+
logger === null || logger === void 0 ? void 0 : logger.error('[ssr] - error parsing asset manifest', e);
|
|
181
|
+
process.exit();
|
|
177
182
|
return undefined;
|
|
178
183
|
}
|
|
179
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["render-middleware.ts"],"names":["denyList","createSsrMiddleware","root","port","title","logger","runtime","loadRuntime","undefined","render","assets","serverRenderMiddleware","req","res","next","query","url","browser","test","debug","rendering","method","server","request","response","props","rendered","set","send","e","error","entryFilepath","path","join","fs","existsSync","warn","manifestFilepath","parseManifest","imported","filepath","file","readFile","contents","toString","parsed","JSON","parse","getAssets","manifest","css","js","entrypoints","filter","x","endsWith","map"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;;;;;AAGA,MAAMA,QAAQ,GAAG,iBAAjB;;AAcO,eAAeC,mBAAf,CAAmC;AAAEC,EAAAA,IAAF;AAAQC,EAAAA,IAAR;AAAcC,EAAAA,KAAd;AAAqBC,EAAAA;AAArB,CAAnC,EAAkF;AACvF,QAAMC,OAAO,GAAG,MAAMC,WAAW,CAACL,IAAD,EAAO;AAAEG,IAAAA;AAAF,GAAP,CAAjC;AACA,MAAI,CAACC,OAAL,EAAc,OAAOE,SAAP;A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AAM,CAACyB,KAAP,CAAc,oBAAmBd,GAAI,GAArC,EAAyCa,CAAzC;AACAf,MAAAA,IAAI;AACL;AACF,GA9BD;AA+BD;;AAED,eAAeP,WAAf,CAA2BL,IAA3B,EAAyC;AAAEG,EAAAA;AAAF,CAAzC,EAAyE;AACvE,MAAII,MAAJ;AACA,MAAIC,MAAJ;;AAEA,MAAI;AACF,UAAMqB,aAAa,GAAGC,gBAAKC,IAAL,CAAU/B,IAAV,EAAgB,KAAhB,EAAuB,UAAvB,CAAtB;;AACA,QAAI,CAACgC,EAAE,GAACC,UAAH,CAAcJ,aAAd,CAAL,EAAmC;AACjC1B,MAAAA,MAAM,CAAC+B,IAAP,CAAa,0DAAyDL,aAAc,GAApF;AACA,aAAOvB,SAAP;AACD;;AAED,UAAM6B,gBAAgB,GAAGL,gBAAKC,IAAL,CAAU/B,IAAV,EAAgB,qBAAhB,CAAzB;;AACA,QAAI,CAACgC,EAAE,GAACC,UAAH,CAAcE,gBAAd,CAAL,EAAsC;AACpChC,MAAAA,MAAM,CAAC+B,IAAP,CAAY,
|
|
1
|
+
{"version":3,"sources":["render-middleware.ts"],"names":["denyList","createSsrMiddleware","root","port","title","logger","runtime","loadRuntime","undefined","render","assets","serverRenderMiddleware","req","res","next","query","url","browser","test","debug","rendering","method","server","request","response","props","rendered","set","send","e","error","entryFilepath","path","join","fs","existsSync","warn","manifestFilepath","parseManifest","imported","filepath","file","readFile","contents","toString","parsed","JSON","parse","getAssets","process","exit","manifest","css","js","entrypoints","filter","x","endsWith","map"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;;;;;AAGA,MAAMA,QAAQ,GAAG,iBAAjB;;AAcO,eAAeC,mBAAf,CAAmC;AAAEC,EAAAA,IAAF;AAAQC,EAAAA,IAAR;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Af,GAAvB;AAEA3C,EAAAA,MAAM,CAAC0C,GAAP,4BAAaD,QAAQ,CAACG,WAAtB,0DAAa,sBAAsBC,MAAtB,CAA8BC,CAAD,IAAOA,CAAC,CAACC,QAAF,CAAW,KAAX,CAApC,EAAuDC,GAAvD,CAA4DF,CAAD,IAAOxB,gBAAKC,IAAL,CAAU,GAAV,EAAeuB,CAAf,CAAlE,CAAb;AACA9C,EAAAA,MAAM,CAAC2C,EAAP,6BAAYF,QAAQ,CAACG,WAArB,2DAAY,uBAAsBC,MAAtB,CAA8BC,CAAD,IAAOA,CAAC,CAACC,QAAF,CAAW,IAAX,CAApC,EAAsDC,GAAtD,CAA2DF,CAAD,IAAOxB,gBAAKC,IAAL,CAAU,GAAV,EAAeuB,CAAf,CAAjE,CAAZ;AAEA,SAAO9C,MAAP;AACD","sourcesContent":["import type { Assets } from '@teambit/ui-foundation.ui.rendering.html';\nimport { Request, Response, NextFunction } from 'express';\nimport path from 'path';\nimport * as fs from 'fs-extra';\nimport type { Logger } from '@teambit/logger';\nimport { requestToObj } from './request-browser';\nimport { SsrContent } from './ssr-content';\n\nconst denyList = /^\\/favicon.ico$/;\n\ntype ssrRenderProps = {\n root: string;\n port: number;\n title: string;\n logger: Logger;\n};\n\ntype ManifestFile = {\n files?: Record<string, string>;\n entrypoints?: string[];\n};\n\nexport async function createSsrMiddleware({ root, port, title, logger }: ssrRenderProps) {\n const runtime = await loadRuntime(root, { logger });\n if (!runtime) return undefined;\n\n const { render } = runtime;\n const assets = { ...runtime.assets, title };\n\n return async function serverRenderMiddleware(req: Request, res: Response, next: NextFunction) {\n const { query, url } = req;\n\n const browser = requestToObj(req, port);\n\n if (denyList.test(url)) {\n logger.debug(`[ssr] skipping static denyList file ${url}`);\n next();\n return;\n }\n\n if (query.rendering === 'client') {\n logger.debug(`[ssr] skipping ${url}`);\n next();\n return;\n }\n\n logger.debug(`[ssr] ${req.method} ${url}`);\n const server = { port, request: req, response: res };\n const props: SsrContent = { assets, browser, server };\n\n try {\n const rendered = await render(props);\n res.set('Cache-Control', 'no-cache');\n res.send(rendered);\n logger.debug(`[ssr] success '${url}'`);\n } catch (e: any) {\n logger.error(`[ssr] failed at '${url}'`, e);\n next();\n }\n };\n}\n\nasync function loadRuntime(root: string, { logger }: { logger: Logger }) {\n let render: (...arg: any[]) => any;\n let assets: Assets | undefined;\n\n try {\n const entryFilepath = path.join(root, 'ssr', 'index.js');\n if (!fs.existsSync(entryFilepath)) {\n logger.warn(`[ssr] - Skipping setup - failed finding ssr bundle at \"${entryFilepath}\"`);\n return undefined;\n }\n\n const manifestFilepath = path.join(root, 'asset-manifest.json');\n if (!fs.existsSync(manifestFilepath)) {\n logger.warn('[ssr] - Skipping setup (cannot find asset manifest file)');\n return undefined;\n }\n\n assets = await parseManifest(manifestFilepath);\n if (!assets) {\n logger.warn('[ssr] - Skipping setup (failed parsing assets manifest)');\n return undefined;\n }\n\n const imported = await import(entryFilepath);\n render = imported?.render;\n\n if (!render || typeof render !== 'function') {\n logger.warn('[ssr] - index file does not export a render() function. Skipping setup.');\n return undefined;\n }\n } catch (e: any) {\n logger.error(e);\n return undefined;\n }\n\n return {\n render,\n assets,\n };\n}\n\nasync function parseManifest(filepath: string, logger?: Logger) {\n try {\n const file = await fs.readFile(filepath);\n logger?.debug('[ssr] - ✓ aread manifest file');\n const contents = file.toString();\n const parsed: ManifestFile = JSON.parse(contents);\n logger?.debug('[ssr] - ✓ prased manifest file', parsed);\n const assets = getAssets(parsed);\n logger?.debug('[ssr] - ✓ extracted data from manifest file', assets);\n\n return assets;\n } catch (e: any) {\n logger?.error('[ssr] - error parsing asset manifest', e);\n process.exit();\n return undefined;\n }\n}\n\nfunction getAssets(manifest: ManifestFile) {\n const assets: Assets = { css: [], js: [] };\n\n assets.css = manifest.entrypoints?.filter((x) => x.endsWith('css')).map((x) => path.join('/', x));\n assets.js = manifest.entrypoints?.filter((x) => x.endsWith('js')).map((x) => path.join('/', x));\n\n return assets;\n}\n"]}
|
package/dist/start-plugin.d.ts
CHANGED
package/dist/start.cmd.js
CHANGED
|
@@ -103,10 +103,11 @@ class StartCmd {
|
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
if (!noBrowser) {
|
|
106
|
-
uiServer.then(server => {
|
|
106
|
+
uiServer.then(async server => {
|
|
107
107
|
var _server$buildOptions;
|
|
108
108
|
|
|
109
109
|
if (!((_server$buildOptions = server.buildOptions) !== null && _server$buildOptions !== void 0 && _server$buildOptions.launchBrowserOnStart)) return undefined;
|
|
110
|
+
await server.whenReady;
|
|
110
111
|
return (0, _open().default)(this.ui.publicUrl || server.fullUrl);
|
|
111
112
|
}).catch(error => this.logger.error(error));
|
|
112
113
|
} // DO NOT CHANGE THIS - this meant to be an async hook.
|
package/dist/start.cmd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["start.cmd.tsx"],"names":["StartCmd","constructor","ui","logger","render","uiRootName","userPattern","dev","port","rebuild","verbose","noBrowser","skipCompilation","off","appName","getUiName","invokePreStart","uiServer","createRuntime","pattern","then","server","buildOptions","launchBrowserOnStart","undefined","publicUrl","fullUrl","catch","error","invokeOnStart","clearConsole"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAaO,MAAMA,QAAN,CAAkC;AAevCC,EAAAA,WAAW;AACT;AACJ;AACA;AACYC,EAAAA,EAJC,EAMDC,MANC,EAOT;AAAA,SAHQD,EAGR,GAHQA,EAGR;AAAA,SADQC,MACR,GADQA,MACR;AAAA,kDArBK,wBAqBL;AAAA,yDApBY,iEAoBZ;AAAA,mDAnBM,GAmBN;AAAA,mDAlBM,aAkBN;AAAA,8DAjBiB,EAiBjB;AAAA,qDAhBQ,CACR,CAAC,GAAD,EAAM,KAAN,EAAa,8BAAb,CADQ,EAER,CAAC,GAAD,EAAM,eAAN,EAAuB,wBAAvB,CAFQ,EAGR,CAAC,GAAD,EAAM,SAAN,EAAiB,gBAAjB,CAHQ,EAIR,CAAC,GAAD,EAAM,SAAN,EAAiB,8DAAjB,CAJQ,EAKR,CAAC,EAAD,EAAK,YAAL,EAAmB,8CAAnB,CALQ,EAMR,CAAC,EAAD,EAAK,kBAAL,EAAyB,0DAAzB,CANQ,CAgBR;AAAE,GAtBmC,CAwBvC;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;;AAEY,QAANC,MAAM,CACV,CAACC,UAAD,EAAaC,WAAb,CADU,EAEV;AAAEC,IAAAA,GAAF;AAAOC,IAAAA,IAAP;AAAaC,IAAAA,OAAb;AAAsBC,IAAAA,OAAtB;AAA+BC,IAAAA,SAA/B;AAA0CC,IAAAA;AAA1C,GAFU,EAGmB;AAC7B,SAAKT,MAAL,CAAYU,GAAZ;AACA,UAAMC,OAAO,GAAG,KAAKZ,EAAL,CAAQa,SAAR,CAAkBV,UAAlB,CAAhB;AACA,UAAM,KAAKH,EAAL,CAAQc,cAAR,CAAuB;AAAEJ,MAAAA;AAAF,KAAvB,CAAN;AACA,UAAMK,QAAQ,GAAG,KAAKf,EAAL,CAAQgB,aAAR,CAAsB;AACrCb,MAAAA,UADqC;AAErCc,MAAAA,OAAO,EAAEb,WAF4B;AAGrCC,MAAAA,GAHqC;AAIrCC,MAAAA,IAAI,EAAE,CAACA,IAJ8B;AAKrCC,MAAAA,OALqC;AAMrCC,MAAAA;AANqC,KAAtB,CAAjB;;AASA,QAAI,CAACC,SAAL,EAAgB;AACdM,MAAAA,QAAQ,CACLG,IADH,
|
|
1
|
+
{"version":3,"sources":["start.cmd.tsx"],"names":["StartCmd","constructor","ui","logger","render","uiRootName","userPattern","dev","port","rebuild","verbose","noBrowser","skipCompilation","off","appName","getUiName","invokePreStart","uiServer","createRuntime","pattern","then","server","buildOptions","launchBrowserOnStart","undefined","whenReady","publicU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AAQc,cAAR,CAAuB;AAAEJ,MAAAA;AAAF,KAAvB,CAAN;AACA,UAAMK,QAAQ,GAAG,KAAKf,EAAL,CAAQgB,aAAR,CAAsB;AACrCb,MAAAA,UADqC;AAErCc,MAAAA,OAAO,EAAEb,WAF4B;AAGrCC,MAAAA,GAHqC;AAIrCC,MAAAA,IAAI,EAAE,CAACA,IAJ8B;AAKrCC,MAAAA,OALqC;AAMrCC,MAAAA;AANqC,KAAtB,CAAjB;;AASA,QAAI,CAACC,SAAL,EAAgB;AACdM,MAAAA,QAAQ,CACLG,IADH,CACQ,MAAOC,MAAP,IAAkB;AAAA;;AACtB,YAAI,0BAACA,MAAM,CAACC,YAAR,iDAAC,qBAAqBC,oBAAtB,CAAJ,EAAgD,OAAOC,SAAP;AAEhD,cAAMH,MAAM,CAACI,SAAb;AAEA,eAAO,qBAAK,KAAKvB,EAAL,CAAQwB,SAAR,IAAqBL,MAAM,CAACM,OAAjC,CAAP;AACD,OAPH,EAQGC,KARH,CAQUC,KAAD,IAAW,KAAK1B,MAAL,CAAY0B,KAAZ,CAAkBA,KAAlB,CARpB;AASD,KAvB4B,CAyB7B;AACA;;;AACA,SAAK3B,EAAL,CAAQ4B,aAAR;AACA,SAAK5B,EAAL,CAAQ6B,YAAR;AAEA,wBAAO,+BAAC,kCAAD;AAAiB,MAAA,OAAO,EAAEjB,OAA1B;AAAmC,MAAA,cAAc,EAAEG,QAAnD;AAA6D,MAAA,GAAG,EAAE,KAAKf,EAAL,CAAQwB;AAA1E,MAAP;AACD;;AA1EsC","sourcesContent":["import React from 'react';\nimport open from 'open';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport { Logger } from '@teambit/logger';\nimport { UIServerConsole } from '@teambit/ui-foundation.cli.ui-server-console';\nimport type { UiMain } from './ui.main.runtime';\n\ntype StartArgs = [uiName: string, userPattern: string];\ntype StartFlags = {\n dev: boolean;\n port: string;\n rebuild: boolean;\n verbose: boolean;\n noBrowser: boolean;\n skipCompilation: boolean;\n};\n\nexport class StartCmd implements Command {\n name = 'start [type] [pattern]';\n description = 'Start a dev environment for a workspace or a specific component';\n alias = 'c';\n group = 'development';\n shortDescription = '';\n options = [\n ['d', 'dev', 'start UI server in dev mode.'],\n ['p', 'port [number]', 'port of the UI server.'],\n ['r', 'rebuild', 'rebuild the UI'],\n ['v', 'verbose', 'showing verbose output for inspection and prints stack trace'],\n ['', 'no-browser', 'do not automatically open browser when ready'],\n ['', 'skip-compilation', 'skip the auto-compilation before starting the web-server'],\n ] as CommandOptions;\n\n constructor(\n /**\n * access to the extension instance.\n */\n private ui: UiMain,\n\n private logger: Logger\n ) {}\n\n // async report([uiRootName, userPattern]: StartArgs, { dev, port, rebuild, verbose }: StartFlags): Promise<string> {\n // this.logger.off();\n // const pattern = userPattern && userPattern.toString();\n\n // const uiServer = await this.ui.createRuntime({\n // uiRootName,\n // pattern,\n // dev,\n // port: port ? parseInt(port) : undefined,\n // rebuild,\n // verbose,\n // });\n\n // return `Bit server has started on port ${uiServer.port}`;\n // }\n\n async render(\n [uiRootName, userPattern]: StartArgs,\n { dev, port, rebuild, verbose, noBrowser, skipCompilation }: StartFlags\n ): Promise<React.ReactElement> {\n this.logger.off();\n const appName = this.ui.getUiName(uiRootName);\n await this.ui.invokePreStart({ skipCompilation });\n const uiServer = this.ui.createRuntime({\n uiRootName,\n pattern: userPattern,\n dev,\n port: +port,\n rebuild,\n verbose,\n });\n\n if (!noBrowser) {\n uiServer\n .then(async (server) => {\n if (!server.buildOptions?.launchBrowserOnStart) return undefined;\n\n await server.whenReady;\n\n return open(this.ui.publicUrl || server.fullUrl);\n })\n .catch((error) => this.logger.error(error));\n }\n\n // DO NOT CHANGE THIS - this meant to be an async hook.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.ui.invokeOnStart();\n this.ui.clearConsole();\n\n return <UIServerConsole appName={appName} futureUiServer={uiServer} url={this.ui.publicUrl} />;\n }\n}\n"]}
|
package/dist/ui-server.d.ts
CHANGED
|
@@ -39,6 +39,9 @@ export declare class UIServer {
|
|
|
39
39
|
launchBrowserOnStart?: boolean | undefined;
|
|
40
40
|
} | undefined;
|
|
41
41
|
getDevConfig(): Promise<any>;
|
|
42
|
+
private setReady;
|
|
43
|
+
private startPromise;
|
|
44
|
+
get whenReady(): Promise<void[]>;
|
|
42
45
|
start({ portRange }?: StartOptions): Promise<void>;
|
|
43
46
|
getPluginsComponents(): import("react").ComponentType<{}>[];
|
|
44
47
|
private setupServerSideRendering;
|
package/dist/ui-server.js
CHANGED
|
@@ -140,6 +140,8 @@ class UIServer {
|
|
|
140
140
|
this.publicDir = publicDir;
|
|
141
141
|
this.plugins = plugins;
|
|
142
142
|
(0, _defineProperty2().default)(this, "_port", 0);
|
|
143
|
+
(0, _defineProperty2().default)(this, "setReady", void 0);
|
|
144
|
+
(0, _defineProperty2().default)(this, "startPromise", new Promise(resolve => this.setReady = resolve));
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
getName() {
|
|
@@ -176,6 +178,10 @@ class UIServer {
|
|
|
176
178
|
const aspectsPaths = aspects.map(aspect => aspect.aspectPath);
|
|
177
179
|
return devConfig(this.uiRoot.path, [await this.ui.generateRoot(aspects, this.uiRootExtension)], this.uiRoot.name, aspectsPaths);
|
|
178
180
|
}
|
|
181
|
+
|
|
182
|
+
get whenReady() {
|
|
183
|
+
return Promise.all([this.startPromise, ...this.plugins.map(x => x === null || x === void 0 ? void 0 : x.whenReady)]);
|
|
184
|
+
}
|
|
179
185
|
/**
|
|
180
186
|
* start a UI server.
|
|
181
187
|
*/
|
|
@@ -213,12 +219,11 @@ class UIServer {
|
|
|
213
219
|
// please make sure you change the `HTTP_SERVER_READY_MSG` const.
|
|
214
220
|
|
|
215
221
|
this.logger.info(`UI server of ${this.uiRootExtension} is listening to port ${port}`);
|
|
222
|
+
this.setReady();
|
|
216
223
|
}
|
|
217
224
|
|
|
218
225
|
getPluginsComponents() {
|
|
219
|
-
return this.plugins.map(plugin =>
|
|
220
|
-
return plugin.render();
|
|
221
|
-
});
|
|
226
|
+
return this.plugins.map(plugin => plugin.render);
|
|
222
227
|
}
|
|
223
228
|
|
|
224
229
|
async setupServerSideRendering({
|
package/dist/ui-server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ui-server.ts"],"names":["devConfig","require","UIServer","constructor","graphql","expressExtension","ui","uiRoot","uiRootExtension","logger","publicDir","plugins","getName","name","port","_port","host","fullUrl","buildOptions","getDevConfig","aspects","resolveAspects","UIRuntime","aspectsPaths","map","aspect","aspectPath","path","generateRoot","start","portRange","app","createApp","root","server","createServer","configureProxy","use","express","static","index","Port","getPortFromRange","setupServerSideRendering","listen","info","getPluginsComponents","plugin","render","ssr","ssrMiddleware","title","warn","get","debug","proxServer","httpProxy","createProxyServer","on","e","error","message","proxyEntries","getProxyFromPlugins","req","socket","head","entry","find","proxy","context","some","item","url","ws","target","forEach","route","res","web","originalUrl","dev","selectedPort","selectPort","config","compiler","devServerConfig","getDevServerConfig","devServer","WebpackDevServer","proxiesByPlugin","getProxy","Promise","all","gqlProxies","changeOrigin","concat","devServerConf","create","props","startPlugins"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAGA,MAAM;AAAEA,EAAAA;AAAF,IAAgBC,OAAO,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AAA;AAAhB,MAAnB;;AAEA,WAAO4B,aAAP;AACD;;AAEY,SAANC,MAAM,CAACC,KAAD,EAAuB;AAClC,WAAO,IAAIjG,QAAJ,CACLiG,KAAK,CAAC/F,OADD,EAEL+F,KAAK,CAAC7D,OAFD,EAGL6D,KAAK,CAAC7F,EAHD,EAIL6F,KAAK,CAAC5F,MAJD,EAKL4F,KAAK,CAAC3F,eALD,EAML2F,KAAK,CAAC1F,MAND,EAOL0F,KAAK,CAACzF,SAPD,EAQLyF,KAAK,CAACC,YARD,CAAP;AAUD;;AApMmB","sourcesContent":["import { flatten } from 'lodash';\nimport { ExpressMain } from '@teambit/express';\nimport { GraphqlMain } from '@teambit/graphql';\nimport { Logger } from '@teambit/logger';\nimport express, { Express } from 'express';\nimport fallback from 'express-history-api-fallback';\nimport { Port } from '@teambit/toolbox.network.get-port';\nimport { Server } from 'http';\nimport httpProxy from 'http-proxy';\nimport { join } from 'path';\nimport webpack from 'webpack';\nimport WebpackDevServer, { Configuration as WdsConfiguration } from 'webpack-dev-server';\nimport { createSsrMiddleware } from './ssr/render-middleware';\nimport { StartPlugin } from './start-plugin';\nimport { ProxyEntry, UIRoot } from './ui-root';\nimport { UIRuntime } from './ui.aspect';\nimport { UiMain } from './ui.main.runtime';\n\nconst { devConfig } = require('./webpack/webpack.dev.config');\n\nexport type UIServerProps = {\n graphql: GraphqlMain;\n express: ExpressMain;\n ui: UiMain;\n uiRoot: UIRoot;\n uiRootExtension: string;\n logger: Logger;\n publicDir: string;\n startPlugins: StartPlugin[];\n};\n\nexport type StartOptions = {\n /**\n * port range for the UI server to bind. default is a port range of 4000-4200.\n */\n portRange?: number[] | number;\n};\n\nexport class UIServer {\n constructor(\n private graphql: GraphqlMain,\n private expressExtension: ExpressMain,\n private ui: UiMain,\n private uiRoot: UIRoot,\n private uiRootExtension: string,\n private logger: Logger,\n private publicDir: string,\n private plugins: StartPlugin[]\n ) {}\n\n getName() {\n return this.uiRoot.name;\n }\n\n private _port = 0;\n\n get port() {\n return this._port;\n }\n\n /** the hostname for the server to listen at. Currently statically 'localhost' */\n get host() {\n return 'localhost';\n }\n\n /** the server listens at this url */\n get fullUrl() {\n const port = this.port !== 80 ? `:${this.port}` : '';\n return `http://${this.host}${port}`;\n }\n\n get buildOptions() {\n return this.uiRoot.buildOptions;\n }\n\n /**\n * get the webpack configuration of the UI server.\n */\n async getDevConfig(): Promise<any> {\n const aspects = await this.uiRoot.resolveAspects(UIRuntime.name);\n const aspectsPaths = aspects.map((aspect) => aspect.aspectPath);\n\n return devConfig(\n this.uiRoot.path,\n [await this.ui.generateRoot(aspects, this.uiRootExtension)],\n this.uiRoot.name,\n aspectsPaths\n );\n }\n\n /**\n * start a UI server.\n */\n async start({ portRange }: StartOptions = {}) {\n const app = this.expressExtension.createApp();\n const publicDir = `/${this.publicDir}`;\n const root = join(this.uiRoot.path, publicDir);\n const server = await this.graphql.createServer({ app });\n\n // set up proxy, for things like preview, e.g. '/preview/teambit.react/react'\n await this.configureProxy(app, server);\n\n // pass through files from public /folder:\n // setting `index: false` so index.html will be served by the fallback() middleware\n app.use(express.static(root, { index: false }));\n\n const port = await Port.getPortFromRange(portRange || [3100, 3200]);\n\n await this.setupServerSideRendering({ root, port, app });\n\n // in any and all other cases, serve index.html.\n // No any other endpoints past this will execute\n app.use(fallback('index.html', { root }));\n\n server.listen(port);\n this._port = port;\n\n // important: we use the string of the following message for the http.e2e.ts. if you change the message,\n // please make sure you change the `HTTP_SERVER_READY_MSG` const.\n this.logger.info(`UI server of ${this.uiRootExtension} is listening to port ${port}`);\n }\n\n getPluginsComponents() {\n return this.plugins.map((plugin) => {\n return plugin.render();\n });\n }\n\n private async setupServerSideRendering({ root, port, app }: { root: string; port: number; app: Express }) {\n if (!this.buildOptions?.ssr) return;\n\n const ssrMiddleware = await createSsrMiddleware({\n root,\n port,\n title: this.uiRoot.name,\n logger: this.logger,\n });\n\n if (!ssrMiddleware) {\n this.logger.warn('[ssr] middleware failed setup');\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n app.get('*', ssrMiddleware);\n this.logger.debug('[ssr] serving for \"*\"');\n }\n\n private async configureProxy(app: Express, server: Server) {\n const proxServer = httpProxy.createProxyServer();\n proxServer.on('error', (e) => this.logger.error(e.message));\n const proxyEntries = await this.getProxyFromPlugins();\n server.on('upgrade', function (req, socket, head) {\n const entry = proxyEntries.find((proxy) => proxy.context.some((item) => item === req.url));\n if (!entry) return;\n proxServer.ws(req, socket, head, {\n target: entry.target,\n });\n });\n\n proxyEntries.forEach((entry) => {\n entry.context.forEach((route) => {\n app.use(`${route}/*`, (req, res) => {\n proxServer.web(req, res, { ...entry, target: `${entry.target}/${req.originalUrl}` });\n });\n });\n });\n }\n\n /**\n * start a UI dev server.\n */\n async dev({ portRange }: StartOptions = {}) {\n const selectedPort = await this.selectPort(portRange);\n await this.start({ portRange: [4100, 4200] });\n const config = await this.getDevConfig();\n const compiler = webpack(config);\n const devServerConfig = await this.getDevServerConfig(this._port, config.devServer);\n // @ts-ignore in the capsules it throws an error about compatibilities issues between webpack.compiler and webpackDevServer/webpack/compiler\n const devServer = new WebpackDevServer(compiler, devServerConfig);\n devServer.listen(selectedPort);\n this._port = selectedPort;\n return devServer;\n }\n\n private async selectPort(portRange?: number[] | number) {\n return Port.getPortFromRange(portRange || [3100, 3200]);\n }\n\n private async getProxyFromPlugins(): Promise<ProxyEntry[]> {\n const proxiesByPlugin = this.plugins.map((plugin) => {\n return plugin.getProxy ? plugin.getProxy() : [];\n });\n\n return flatten(await Promise.all(proxiesByPlugin));\n }\n\n private async getProxy(port = 4000) {\n const proxyEntries = await this.getProxyFromPlugins();\n\n const gqlProxies: ProxyEntry[] = [\n {\n context: ['/graphql', '/api'],\n target: `http://${this.host}:${port}`,\n changeOrigin: true,\n },\n {\n context: ['/subscriptions'],\n target: `ws://${this.host}:${port}`,\n ws: true,\n },\n ];\n\n return gqlProxies.concat(proxyEntries);\n }\n\n private async getDevServerConfig(port: number, config?: WdsConfiguration): Promise<WdsConfiguration> {\n const proxy = await this.getProxy(port);\n const devServerConf = { ...config, proxy };\n\n return devServerConf;\n }\n\n static create(props: UIServerProps) {\n return new UIServer(\n props.graphql,\n props.express,\n props.ui,\n props.uiRoot,\n props.uiRootExtension,\n props.logger,\n props.publicDir,\n props.startPlugins\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["ui-server.ts"],"names":["devConfig","require","UIServer","constructor","graphql","expressExtension","ui","uiRoot","uiRootExtension","logger","publicDir","plugins","Promise","resolve","setReady","getName","name","port","_port","host","fullUrl","buildOptions","getDevConfig","aspects","resolveAspects","UIRuntime","aspectsPaths","map","aspect","aspectPath","path","generateRoot","whenReady","all","startPromise","x","start","portRange","app","createApp","root","server","createServer","configureProxy","use","express","static","index","Port","getPortFromRange","setupServerSideRendering","listen","info","getPluginsComponents","plugin","render","ssr","ssrMiddleware","title","warn","get","debug","proxServer","httpProxy","createProxyServer","on","e","error","message","proxyEntries","getProxyFromPlugins","req","socket","head","entry","find","proxy","context","some","item","url","ws","target","forEach","route","res","web","originalUrl","dev","selectedPort","selectPort","config","compiler","devServerConfig","getDevServerConfig","devServer","WebpackDevServer","proxiesByPlugin","getProxy","gqlProxies","changeOrigin","concat","devServerConf","create","props","startPlugins"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;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B;AACEvB,MAAAA,OAAO,EAAE,CAAC,gBAAD,CADX;AAEEK,MAAAA,MAAM,EAAG,QAAO,KAAK/D,IAAK,IAAGF,IAAK,EAFpC;AAGEgE,MAAAA,EAAE,EAAE;AAHN,KAN+B,CAAjC;AAaA,WAAOkB,UAAU,CAACE,MAAX,CAAkBhC,YAAlB,CAAP;AACD;;AAE+B,QAAlByB,kBAAkB,CAAC7E,IAAD,EAAe0E,MAAf,EAAqE;AACnG,UAAMf,KAAK,GAAG,MAAM,KAAKsB,QAAL,CAAcjF,IAAd,CAApB;;AACA,UAAMqF,aAAa,mCAAQX,MAAR;AAAgBf,MAAAA;AAAhB,MAAnB;;AAEA,WAAO0B,aAAP;AACD;;AAEY,SAANC,MAAM,CAACC,KAAD,EAAuB;AAClC,WAAO,IAAItG,QAAJ,CACLsG,KAAK,CAACpG,OADD,EAELoG,KAAK,CAAC3D,OAFD,EAGL2D,KAAK,CAAClG,EAHD,EAILkG,KAAK,CAACjG,MAJD,EAKLiG,KAAK,CAAChG,eALD,EAMLgG,KAAK,CAAC/F,MAND,EAOL+F,KAAK,CAAC9F,SAPD,EAQL8F,KAAK,CAACC,YARD,CAAP;AAUD;;AA1MmB","sourcesContent":["import { flatten } from 'lodash';\nimport { ExpressMain } from '@teambit/express';\nimport { GraphqlMain } from '@teambit/graphql';\nimport { Logger } from '@teambit/logger';\nimport express, { Express } from 'express';\nimport fallback from 'express-history-api-fallback';\nimport { Port } from '@teambit/toolbox.network.get-port';\nimport { Server } from 'http';\nimport httpProxy from 'http-proxy';\nimport { join } from 'path';\nimport webpack from 'webpack';\nimport WebpackDevServer, { Configuration as WdsConfiguration } from 'webpack-dev-server';\nimport { createSsrMiddleware } from './ssr/render-middleware';\nimport { StartPlugin } from './start-plugin';\nimport { ProxyEntry, UIRoot } from './ui-root';\nimport { UIRuntime } from './ui.aspect';\nimport { UiMain } from './ui.main.runtime';\n\nconst { devConfig } = require('./webpack/webpack.dev.config');\n\nexport type UIServerProps = {\n graphql: GraphqlMain;\n express: ExpressMain;\n ui: UiMain;\n uiRoot: UIRoot;\n uiRootExtension: string;\n logger: Logger;\n publicDir: string;\n startPlugins: StartPlugin[];\n};\n\nexport type StartOptions = {\n /**\n * port range for the UI server to bind. default is a port range of 4000-4200.\n */\n portRange?: number[] | number;\n};\n\nexport class UIServer {\n constructor(\n private graphql: GraphqlMain,\n private expressExtension: ExpressMain,\n private ui: UiMain,\n private uiRoot: UIRoot,\n private uiRootExtension: string,\n private logger: Logger,\n private publicDir: string,\n private plugins: StartPlugin[]\n ) {}\n\n getName() {\n return this.uiRoot.name;\n }\n\n private _port = 0;\n\n get port() {\n return this._port;\n }\n\n /** the hostname for the server to listen at. Currently statically 'localhost' */\n get host() {\n return 'localhost';\n }\n\n /** the server listens at this url */\n get fullUrl() {\n const port = this.port !== 80 ? `:${this.port}` : '';\n return `http://${this.host}${port}`;\n }\n\n get buildOptions() {\n return this.uiRoot.buildOptions;\n }\n\n /**\n * get the webpack configuration of the UI server.\n */\n async getDevConfig(): Promise<any> {\n const aspects = await this.uiRoot.resolveAspects(UIRuntime.name);\n const aspectsPaths = aspects.map((aspect) => aspect.aspectPath);\n\n return devConfig(\n this.uiRoot.path,\n [await this.ui.generateRoot(aspects, this.uiRootExtension)],\n this.uiRoot.name,\n aspectsPaths\n );\n }\n\n private setReady: () => void;\n private startPromise = new Promise<void>((resolve) => (this.setReady = resolve));\n get whenReady() {\n return Promise.all([this.startPromise, ...this.plugins.map((x) => x?.whenReady)]);\n }\n\n /**\n * start a UI server.\n */\n async start({ portRange }: StartOptions = {}) {\n const app = this.expressExtension.createApp();\n const publicDir = `/${this.publicDir}`;\n const root = join(this.uiRoot.path, publicDir);\n const server = await this.graphql.createServer({ app });\n\n // set up proxy, for things like preview, e.g. '/preview/teambit.react/react'\n await this.configureProxy(app, server);\n\n // pass through files from public /folder:\n // setting `index: false` so index.html will be served by the fallback() middleware\n app.use(express.static(root, { index: false }));\n\n const port = await Port.getPortFromRange(portRange || [3100, 3200]);\n\n await this.setupServerSideRendering({ root, port, app });\n\n // in any and all other cases, serve index.html.\n // No any other endpoints past this will execute\n app.use(fallback('index.html', { root }));\n\n server.listen(port);\n this._port = port;\n\n // important: we use the string of the following message for the http.e2e.ts. if you change the message,\n // please make sure you change the `HTTP_SERVER_READY_MSG` const.\n this.logger.info(`UI server of ${this.uiRootExtension} is listening to port ${port}`);\n\n this.setReady();\n }\n\n getPluginsComponents() {\n return this.plugins.map((plugin) => plugin.render);\n }\n\n private async setupServerSideRendering({ root, port, app }: { root: string; port: number; app: Express }) {\n if (!this.buildOptions?.ssr) return;\n\n const ssrMiddleware = await createSsrMiddleware({\n root,\n port,\n title: this.uiRoot.name,\n logger: this.logger,\n });\n\n if (!ssrMiddleware) {\n this.logger.warn('[ssr] middleware failed setup');\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n app.get('*', ssrMiddleware);\n this.logger.debug('[ssr] serving for \"*\"');\n }\n\n private async configureProxy(app: Express, server: Server) {\n const proxServer = httpProxy.createProxyServer();\n proxServer.on('error', (e) => this.logger.error(e.message));\n const proxyEntries = await this.getProxyFromPlugins();\n server.on('upgrade', function (req, socket, head) {\n const entry = proxyEntries.find((proxy) => proxy.context.some((item) => item === req.url));\n if (!entry) return;\n proxServer.ws(req, socket, head, {\n target: entry.target,\n });\n });\n\n proxyEntries.forEach((entry) => {\n entry.context.forEach((route) => {\n app.use(`${route}/*`, (req, res) => {\n proxServer.web(req, res, { ...entry, target: `${entry.target}/${req.originalUrl}` });\n });\n });\n });\n }\n\n /**\n * start a UI dev server.\n */\n async dev({ portRange }: StartOptions = {}) {\n const selectedPort = await this.selectPort(portRange);\n await this.start({ portRange: [4100, 4200] });\n const config = await this.getDevConfig();\n const compiler = webpack(config);\n const devServerConfig = await this.getDevServerConfig(this._port, config.devServer);\n // @ts-ignore in the capsules it throws an error about compatibilities issues between webpack.compiler and webpackDevServer/webpack/compiler\n const devServer = new WebpackDevServer(compiler, devServerConfig);\n devServer.listen(selectedPort);\n this._port = selectedPort;\n return devServer;\n }\n\n private async selectPort(portRange?: number[] | number) {\n return Port.getPortFromRange(portRange || [3100, 3200]);\n }\n\n private async getProxyFromPlugins(): Promise<ProxyEntry[]> {\n const proxiesByPlugin = this.plugins.map((plugin) => {\n return plugin.getProxy ? plugin.getProxy() : [];\n });\n\n return flatten(await Promise.all(proxiesByPlugin));\n }\n\n private async getProxy(port = 4000) {\n const proxyEntries = await this.getProxyFromPlugins();\n\n const gqlProxies: ProxyEntry[] = [\n {\n context: ['/graphql', '/api'],\n target: `http://${this.host}:${port}`,\n changeOrigin: true,\n },\n {\n context: ['/subscriptions'],\n target: `ws://${this.host}:${port}`,\n ws: true,\n },\n ];\n\n return gqlProxies.concat(proxyEntries);\n }\n\n private async getDevServerConfig(port: number, config?: WdsConfiguration): Promise<WdsConfiguration> {\n const proxy = await this.getProxy(port);\n const devServerConf = { ...config, proxy };\n\n return devServerConf;\n }\n\n static create(props: UIServerProps) {\n return new UIServer(\n props.graphql,\n props.express,\n props.ui,\n props.uiRoot,\n props.uiRootExtension,\n props.logger,\n props.publicDir,\n props.startPlugins\n );\n }\n}\n"]}
|
|
@@ -408,10 +408,11 @@ function createWebpackConfig(workspaceDir, entryFiles, publicDir = 'public') {
|
|
|
408
408
|
manifest[file.name] = file.path;
|
|
409
409
|
return manifest;
|
|
410
410
|
}, seed);
|
|
411
|
-
const entrypointFiles = entrypoints.main.filter(fileName => !fileName.endsWith('.map'));
|
|
411
|
+
const entrypointFiles = entrypoints.main.filter(fileName => !fileName.endsWith('.map')); // @ts-ignore - https://github.com/shellscape/webpack-manifest-plugin/issues/276
|
|
412
|
+
|
|
412
413
|
return {
|
|
413
|
-
files:
|
|
414
|
-
entrypoints:
|
|
414
|
+
files: manifestFiles,
|
|
415
|
+
entrypoints: entrypointFiles
|
|
415
416
|
};
|
|
416
417
|
}
|
|
417
418
|
}), // Moment.js is an extremely popular library that bundles large locale files
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["webpack.base.config.ts"],"names":["baseStyleLoadersOptions","injectingLoader","MiniCssExtractPlugin","loader","cssLoaderPath","require","resolve","postCssLoaderPath","postCssConfig","moduleFileExtensions","shouldUseSourceMap","process","env","GENERATE_SOURCEMAP","imageInlineSizeLimit","parseInt","IMAGE_INLINE_SIZE_LIMIT","isEnvProduction","createWebpackConfig","workspaceDir","entryFiles","publicDir","isEnvProductionProfile","argv","includes","stats","children","mode","entry","main","output","path","join","filename","chunkFilename","extensions","map","ext","alias","react","fallback","module","dgram","dns","fs","stream","http2","net","tls","child_process","strictExportPresence","rules","test","fullySpecified","oneOf","stylesRegexps","cssNoModulesRegex","use","cssLoaderOpts","importLoaders","sourceMap","sideEffects","type","parser","dataUrlCondition","maxSize","options","babelrc","configFile","customize","cacheDirectory","cacheCompression","compact","cssModuleRegex","modules","getLocalIdent","getCSSModuleLocalIdent","sassNoModuleRegex","preProcessOptions","resolveUrlLoaderPath","preProcessorPath","sassModuleRegex","lessNoModuleRegex","lessModuleRegex","exclude","plugins","WebpackManifestPlugin","fileName","generate","seed","files","entrypoints","manifestFiles","reduce","manifest","file","name","entrypointFiles","filter","endsWith","JSON","stringify","webpack","IgnorePlugin","resourceRegExp","contextRegExp","WorkboxWebpackPlugin","GenerateSW","clientsClaim","maximumFileSizeToCacheInBytes","navigateFallback","navigateFallbackDenylist","RegExp","Boolean","performance"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAA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KAAzB,CAhCO,EAoCP;AACA;AACAxF,IAAAA,eAAe,IACb,KAAIyF,gCAAqBC,UAAzB,EAAoC;AAClCC,MAAAA,YAAY,EAAE,IADoB;AAElCC,MAAAA,6BAA6B,EAAE,OAFG;AAGlCzB,MAAAA,OAAO,EAAE,CAAC,QAAD,EAAW,uBAAX,CAHyB;AAIlC;AACA0B,MAAAA,gBAAgB,EAAE,mBALgB;AAMlCC,MAAAA,wBAAwB,EAAE,CACxB;AACA,UAAIC,MAAJ,CAAW,KAAX,CAFwB,EAGxB;AACA;AACA;AACA;AACA,UAAIA,MAAJ,CAAW,kBAAX,CAPwB;AANQ,KAApC,CAvCK,EAuDPd,MAvDO,CAuDAe,OAvDA,CA/QJ;AAuUL;AACA;AACA;AACA;AACAC,IAAAA,WAAW,EAAE;AA3UR,GAAP;AA6UD","sourcesContent":["import { merge } from 'lodash';\nimport webpack, { Configuration } from 'webpack';\nimport MiniCssExtractPlugin from 'mini-css-extract-plugin';\nimport { WebpackManifestPlugin } from 'webpack-manifest-plugin';\nimport WorkboxWebpackPlugin from 'workbox-webpack-plugin';\nimport getCSSModuleLocalIdent from 'react-dev-utils/getCSSModuleLocalIdent';\nimport path from 'path';\nimport * as stylesRegexps from '@teambit/webpack.modules.style-regexps';\nimport { generateStyleLoaders } from '@teambit/webpack.modules.generate-style-loaders';\nimport { postCssConfig } from './postcss.config';\n\nconst baseStyleLoadersOptions = {\n injectingLoader: MiniCssExtractPlugin.loader,\n cssLoaderPath: require.resolve('css-loader'),\n postCssLoaderPath: require.resolve('postcss-loader'),\n postCssConfig,\n};\n\nconst moduleFileExtensions = [\n 'web.mjs',\n 'mjs',\n 'web.js',\n 'js',\n 'web.ts',\n 'ts',\n 'web.tsx',\n 'tsx',\n 'json',\n 'web.jsx',\n 'jsx',\n];\n\n// Source maps are resource heavy and can cause out of memory issue for large source files.\nconst shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';\n\nconst imageInlineSizeLimit = parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '10000');\n\nconst isEnvProduction = true;\n\n// This is the production and development configuration.\n// It is focused on developer experience, fast rebuilds, and a minimal bundle.\n// eslint-disable-next-line complexity\nexport default function createWebpackConfig(\n workspaceDir: string,\n entryFiles: string[],\n publicDir = 'public'\n): Configuration {\n // Variable used for enabling profiling in Production\n // passed into alias object. Uses a flag if passed into the build command\n const isEnvProductionProfile = process.argv.includes('--profile');\n\n // We will provide `paths.publicUrlOrPath` to our app\n // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.\n // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.\n // Get environment variables to inject into our app.\n // const env = getClientEnvironment(publicUrlOrPath.slice(0, -1));\n\n return {\n stats: {\n children: true,\n },\n mode: 'production',\n entry: {\n main: entryFiles,\n },\n\n output: {\n // The build folder.\n path: path.join(workspaceDir, publicDir), // default value\n\n filename: 'static/js/[name].[contenthash:8].js',\n // TODO: remove this when upgrading to webpack 5\n // futureEmitAssets: true,\n // There are also additional JS chunk files if you use code splitting.\n chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',\n // this defaults to 'window', but by setting it to 'this' then\n // module chunks which are built will work in web workers as well.\n // Commented out to use the default (self) as according to tobias with webpack5 self is working with workers as well\n // globalObject: 'this',\n },\n\n resolve: {\n // These are the reasonable defaults supported by the Node ecosystem.\n // We also include JSX as a common component filename extension to support\n // some tools, although we do not recommend using it, see:\n // https://github.com/facebook/create-react-app/issues/290\n // `web` extension prefixes have been added for better support\n // for React Native Web.\n extensions: moduleFileExtensions.map((ext) => `.${ext}`),\n\n alias: {\n // TODO: @uri please remember to remove after publishing evangelist and base-ui\n react: require.resolve('react'),\n 'react-dom/server': require.resolve('react-dom/server'),\n 'react-dom': require.resolve('react-dom'),\n // Allows for better profiling with ReactDevTools\n ...(isEnvProductionProfile && {\n 'react-dom$': 'react-dom/profiling',\n 'scheduler/tracing': 'scheduler/tracing-profiling',\n }),\n },\n fallback: {\n module: false,\n path: require.resolve('path-browserify'),\n dgram: false,\n dns: false,\n fs: false,\n stream: false,\n http2: false,\n net: false,\n tls: false,\n child_process: false,\n },\n },\n module: {\n strictExportPresence: true,\n rules: [\n {\n test: /\\.m?js/,\n resolve: {\n fullySpecified: false,\n },\n },\n // Disable require.ensure as it's not a standard language feature.\n // { parser: { requireEnsure: false } },\n {\n // \"oneOf\" will traverse all following loaders until one will\n // match the requirements. When no loader matches it will fall\n // back to the \"file\" loader at the end of the loader list.\n oneOf: [\n // \"postcss\" loader applies autoprefixer to our CSS.\n // \"css\" loader resolves paths in CSS and adds assets as dependencies.\n // \"style\" loader turns CSS into JS modules that inject <style> tags.\n // In production, we use MiniCSSExtractPlugin to extract that CSS\n // to a file, but in development \"style\" loader enables hot editing\n // of CSS.\n // By default we support CSS Modules with the extension .module.css\n {\n test: stylesRegexps.cssNoModulesRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 1,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n },\n })\n ),\n // Don't consider CSS imports dead code even if the\n // containing package claims to have no side effects.\n // Remove this when webpack adds a warning or an error for this.\n // See https://github.com/webpack/webpack/issues/6571\n sideEffects: true,\n },\n // \"url\" loader works like \"file\" loader except that it embeds assets\n // smaller than specified limit in bytes as data URLs to avoid requests.\n // A missing `test` is equivalent to a match.\n {\n test: [/\\.bmp$/, /\\.gif$/, /\\.jpe?g$/, /\\.png$/, /\\.svg$/],\n type: 'asset',\n parser: {\n dataUrlCondition: {\n maxSize: imageInlineSizeLimit,\n },\n },\n },\n // Process application JS with Babel.\n // The preset includes JSX, Flow, TypeScript, and some ESnext features.\n {\n test: /\\.(js|mjs|jsx|ts|tsx)$/,\n loader: require.resolve('babel-loader'),\n options: {\n babelrc: false,\n configFile: false,\n customize: require.resolve('babel-preset-react-app/webpack-overrides'),\n // This is a feature of `babel-loader` for webpack (not Babel itself).\n // It enables caching results in ./node_modules/.cache/babel-loader/\n // directory for faster rebuilds.\n cacheDirectory: true,\n // See #6846 for context on why cacheCompression is disabled\n cacheCompression: false,\n compact: isEnvProduction,\n },\n },\n // Process any JS outside of the app with Babel.\n // Unlike the application JS, we only compile the standard ES features.\n // Probably not needed in our use case\n // {\n // test: /\\.(js|mjs)$/,\n // exclude: /@babel(?:\\/|\\\\{1,2})runtime/,\n // loader: require.resolve('babel-loader'),\n // options: {\n // babelrc: false,\n // configFile: false,\n // compact: false,\n // presets: [[require.resolve('babel-preset-react-app/dependencies'), { helpers: true }]],\n // cacheDirectory: true,\n // // See #6846 for context on why cacheCompression is disabled\n // cacheCompression: false,\n\n // // Babel sourcemaps are needed for debugging into node_modules\n // // code. Without the options below, debuggers like VSCode\n // // show incorrect code and set breakpoints on the wrong lines.\n // sourceMaps: shouldUseSourceMap,\n // inputSourceMap: shouldUseSourceMap,\n // },\n // },\n\n // Adds support for CSS Modules (https://github.com/css-modules/css-modules)\n // using the extension .module.css\n {\n test: stylesRegexps.cssModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 1,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n modules: {\n getLocalIdent: getCSSModuleLocalIdent,\n },\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n })\n ),\n },\n // Opt-in support for SASS (using .scss or .sass extensions).\n // By default we support SASS Modules with the\n // extensions .module.scss or .module.sass\n {\n test: stylesRegexps.sassNoModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 3,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n preProcessOptions: {\n resolveUrlLoaderPath: require.resolve('resolve-url-loader'),\n preProcessorPath: require.resolve('sass-loader'),\n },\n })\n ),\n // Don't consider CSS imports dead code even if the\n // containing package claims to have no side effects.\n // Remove this when webpack adds a warning or an error for this.\n // See https://github.com/webpack/webpack/issues/6571\n sideEffects: true,\n },\n // Adds support for CSS Modules, but using SASS\n // using the extension .module.scss or .module.sass\n {\n test: stylesRegexps.sassModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 3,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n modules: {\n getLocalIdent: getCSSModuleLocalIdent,\n },\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n preProcessOptions: {\n resolveUrlLoaderPath: require.resolve('resolve-url-loader'),\n preProcessorPath: require.resolve('sass-loader'),\n },\n })\n ),\n },\n {\n test: stylesRegexps.lessNoModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 1,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n preProcessOptions: {\n resolveUrlLoaderPath: require.resolve('resolve-url-loader'),\n preProcessorPath: require.resolve('less-loader'),\n },\n })\n ),\n // Don't consider CSS imports dead code even if the\n // containing package claims to have no side effects.\n // Remove this when webpack adds a warning or an error for this.\n // See https://github.com/webpack/webpack/issues/6571\n sideEffects: true,\n },\n {\n test: stylesRegexps.lessModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 1,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n modules: {\n getLocalIdent: getCSSModuleLocalIdent,\n },\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n preProcessOptions: {\n resolveUrlLoaderPath: require.resolve('resolve-url-loader'),\n preProcessorPath: require.resolve('less-loader'),\n },\n })\n ),\n },\n // \"file\" loader makes sure those assets get served by WebpackDevServer.\n // When you `import` an asset, you get its (virtual) filename.\n // In production, they would get copied to the `build` folder.\n // This loader doesn't use a \"test\" so it will catch all modules\n // that fall through the other loaders.\n {\n // Exclude `js` files to keep \"css\" loader working as it injects\n // its runtime that would otherwise be processed through \"file\" loader.\n // Also exclude `html` and `json` extensions so they get processed\n // by webpacks internal loaders.\n exclude: [/\\.(js|mjs|jsx|ts|tsx)$/, /\\.html$/, /\\.json$/, /\\.css$/],\n type: 'asset/resource',\n },\n // ** STOP ** Are you adding a new loader?\n // Make sure to add the new loader(s) before the \"file\" loader.\n ],\n },\n ],\n },\n plugins: [\n new MiniCssExtractPlugin({\n // Options similar to the same options in webpackOptions.output\n // both options are optional\n filename: 'static/css/[name].[contenthash:8].css',\n chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',\n }),\n // Generate an asset manifest file with the following content:\n // - \"files\" key: Mapping of all asset filenames to their corresponding\n // output file so that tools can pick it up without having to parse\n // `index.html`\n // can be used to reconstruct the HTML if necessary\n new WebpackManifestPlugin({\n fileName: 'asset-manifest.json',\n generate: (seed, files, entrypoints) => {\n const manifestFiles = files.reduce((manifest, file) => {\n manifest[file.name] = file.path;\n return manifest;\n }, seed);\n const entrypointFiles = entrypoints.main.filter((fileName) => !fileName.endsWith('.map'));\n\n return {\n files: JSON.stringify(manifestFiles),\n entrypoints: JSON.stringify(entrypointFiles),\n };\n },\n }),\n // Moment.js is an extremely popular library that bundles large locale files\n // by default due to how webpack interprets its code. This is a practical\n // solution that requires the user to opt into importing specific locales.\n // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack\n // You can remove this if you don't use Moment.js:\n new webpack.IgnorePlugin({\n resourceRegExp: /^\\.\\/locale$/,\n contextRegExp: /moment$/,\n }),\n // Generate a service worker script that will precache, and keep up to date,\n // the HTML & assets that are part of the webpack build.\n isEnvProduction &&\n new WorkboxWebpackPlugin.GenerateSW({\n clientsClaim: true,\n maximumFileSizeToCacheInBytes: 5000000,\n exclude: [/\\.map$/, /asset-manifest\\.json$/],\n // importWorkboxFrom: 'cdn',\n navigateFallback: 'public/index.html',\n navigateFallbackDenylist: [\n // Exclude URLs starting with /_, as they're likely an API call\n new RegExp('^/_'),\n // Exclude any URLs whose last part seems to be a file extension\n // as they're likely a resource and not a SPA route.\n // URLs containing a \"?\" character won't be blacklisted as they're likely\n // a route with query params (e.g. auth callbacks).\n new RegExp('/[^/?]+\\\\.[^/]+$'),\n ],\n }),\n ].filter(Boolean),\n // Some libraries import Node modules but don't use them in the browser.\n // Tell webpack to provide empty mocks for them so importing them works.\n // Turn off performance processing because we utilize\n // our own hints via the FileSizeReporter\n performance: false,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["webpack.base.config.ts"],"names":["baseStyleLoadersOptions","injectingLoader","MiniCssExtractPlugin","loader","cssLoaderPath","require","resolve","postCssLoaderPath","postCssConfig","moduleFileExtensions","shouldUseSourceMap","process","env","GENERATE_SOURCEMAP","imageInlineSizeLimit","parseInt","IMAGE_INLINE_SIZE_LIMIT","isEnvProduction","createWebpackConfig","workspaceDir","entryFiles","publicDir","isEnvProductionProfile","argv","includes","stats","children","mode","entry","main","output","path","join","filename","chunkFilename","extensions","map","ext","alias","react","fallback","module","dgram","dns","fs","stream","http2","net","tls","child_process","strictExportPresence","rules","test","fullySpecified","oneOf","stylesRegexps","cssNoModulesRegex","use","cssLoaderOpts","importLoaders","sourceMap","sideEffects","type","parser","dataUrlCondition","maxSize","options","babelrc","configFile","customize","cacheDirectory","cacheCompression","compact","cssModuleRegex","modules","getLocalIdent","getCSSModuleLocalIdent","sassNoModuleRegex","preProcessOptions","resolveUrlLoaderPath","preProcessorPath","sassModuleRegex","lessNoModuleRegex","lessModuleRegex","exclude","plugins","WebpackManifestPlugin","fileName","generate","seed","files","entrypoints","manifestFiles","reduce","manifest","file","name","entrypointFiles","filter","endsWith","webpack","IgnorePlugin","resourceRegExp","contextRegExp","WorkboxWebpackPlugin","GenerateSW","clientsClaim","maximumFileSizeToCacheInBytes","navigateFallback","navigateFallbackDenylist","RegExp","Boolean","performance"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAA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A,eAAO;AACLT,UAAAA,KAAK,EAAEE,aADF;AAELD,UAAAA,WAAW,EAAEM;AAFR,SAAP;AAID;AAduB,KAA1B,CAZO,EA4BP;AACA;AACA;AACA;AACA;AACA,SAAIG,mBAAQC,YAAZ,EAAyB;AACvBC,MAAAA,cAAc,EAAE,cADO;AAEvBC,MAAAA,aAAa,EAAE;AAFQ,KAAzB,CAjCO,EAqCP;AACA;AACAtF,IAAAA,eAAe,IACb,KAAIuF,gCAAqBC,UAAzB,EAAoC;AAClCC,MAAAA,YAAY,EAAE,IADoB;AAElCC,MAAAA,6BAA6B,EAAE,OAFG;AAGlCvB,MAAAA,OAAO,EAAE,CAAC,QAAD,EAAW,uBAAX,CAHyB;AAIlC;AACAwB,MAAAA,gBAAgB,EAAE,mBALgB;AAMlCC,MAAAA,wBAAwB,EAAE,CACxB;AACA,UAAIC,MAAJ,CAAW,KAAX,CAFwB,EAGxB;AACA;AACA;AACA;AACA,UAAIA,MAAJ,CAAW,kBAAX,CAPwB;AANQ,KAApC,CAxCK,EAwDPZ,MAxDO,CAwDAa,OAxDA,CA/QJ;AAwUL;AACA;AACA;AACA;AACAC,IAAAA,WAAW,EAAE;AA5UR,GAAP;AA8UD","sourcesContent":["import { merge } from 'lodash';\nimport webpack, { Configuration } from 'webpack';\nimport MiniCssExtractPlugin from 'mini-css-extract-plugin';\nimport { WebpackManifestPlugin } from 'webpack-manifest-plugin';\nimport WorkboxWebpackPlugin from 'workbox-webpack-plugin';\nimport getCSSModuleLocalIdent from 'react-dev-utils/getCSSModuleLocalIdent';\nimport path from 'path';\nimport * as stylesRegexps from '@teambit/webpack.modules.style-regexps';\nimport { generateStyleLoaders } from '@teambit/webpack.modules.generate-style-loaders';\nimport { postCssConfig } from './postcss.config';\n\nconst baseStyleLoadersOptions = {\n injectingLoader: MiniCssExtractPlugin.loader,\n cssLoaderPath: require.resolve('css-loader'),\n postCssLoaderPath: require.resolve('postcss-loader'),\n postCssConfig,\n};\n\nconst moduleFileExtensions = [\n 'web.mjs',\n 'mjs',\n 'web.js',\n 'js',\n 'web.ts',\n 'ts',\n 'web.tsx',\n 'tsx',\n 'json',\n 'web.jsx',\n 'jsx',\n];\n\n// Source maps are resource heavy and can cause out of memory issue for large source files.\nconst shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';\n\nconst imageInlineSizeLimit = parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '10000');\n\nconst isEnvProduction = true;\n\n// This is the production and development configuration.\n// It is focused on developer experience, fast rebuilds, and a minimal bundle.\n// eslint-disable-next-line complexity\nexport default function createWebpackConfig(\n workspaceDir: string,\n entryFiles: string[],\n publicDir = 'public'\n): Configuration {\n // Variable used for enabling profiling in Production\n // passed into alias object. Uses a flag if passed into the build command\n const isEnvProductionProfile = process.argv.includes('--profile');\n\n // We will provide `paths.publicUrlOrPath` to our app\n // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.\n // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.\n // Get environment variables to inject into our app.\n // const env = getClientEnvironment(publicUrlOrPath.slice(0, -1));\n\n return {\n stats: {\n children: true,\n },\n mode: 'production',\n entry: {\n main: entryFiles,\n },\n\n output: {\n // The build folder.\n path: path.join(workspaceDir, publicDir), // default value\n\n filename: 'static/js/[name].[contenthash:8].js',\n // TODO: remove this when upgrading to webpack 5\n // futureEmitAssets: true,\n // There are also additional JS chunk files if you use code splitting.\n chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',\n // this defaults to 'window', but by setting it to 'this' then\n // module chunks which are built will work in web workers as well.\n // Commented out to use the default (self) as according to tobias with webpack5 self is working with workers as well\n // globalObject: 'this',\n },\n\n resolve: {\n // These are the reasonable defaults supported by the Node ecosystem.\n // We also include JSX as a common component filename extension to support\n // some tools, although we do not recommend using it, see:\n // https://github.com/facebook/create-react-app/issues/290\n // `web` extension prefixes have been added for better support\n // for React Native Web.\n extensions: moduleFileExtensions.map((ext) => `.${ext}`),\n\n alias: {\n // TODO: @uri please remember to remove after publishing evangelist and base-ui\n react: require.resolve('react'),\n 'react-dom/server': require.resolve('react-dom/server'),\n 'react-dom': require.resolve('react-dom'),\n // Allows for better profiling with ReactDevTools\n ...(isEnvProductionProfile && {\n 'react-dom$': 'react-dom/profiling',\n 'scheduler/tracing': 'scheduler/tracing-profiling',\n }),\n },\n fallback: {\n module: false,\n path: require.resolve('path-browserify'),\n dgram: false,\n dns: false,\n fs: false,\n stream: false,\n http2: false,\n net: false,\n tls: false,\n child_process: false,\n },\n },\n module: {\n strictExportPresence: true,\n rules: [\n {\n test: /\\.m?js/,\n resolve: {\n fullySpecified: false,\n },\n },\n // Disable require.ensure as it's not a standard language feature.\n // { parser: { requireEnsure: false } },\n {\n // \"oneOf\" will traverse all following loaders until one will\n // match the requirements. When no loader matches it will fall\n // back to the \"file\" loader at the end of the loader list.\n oneOf: [\n // \"postcss\" loader applies autoprefixer to our CSS.\n // \"css\" loader resolves paths in CSS and adds assets as dependencies.\n // \"style\" loader turns CSS into JS modules that inject <style> tags.\n // In production, we use MiniCSSExtractPlugin to extract that CSS\n // to a file, but in development \"style\" loader enables hot editing\n // of CSS.\n // By default we support CSS Modules with the extension .module.css\n {\n test: stylesRegexps.cssNoModulesRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 1,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n },\n })\n ),\n // Don't consider CSS imports dead code even if the\n // containing package claims to have no side effects.\n // Remove this when webpack adds a warning or an error for this.\n // See https://github.com/webpack/webpack/issues/6571\n sideEffects: true,\n },\n // \"url\" loader works like \"file\" loader except that it embeds assets\n // smaller than specified limit in bytes as data URLs to avoid requests.\n // A missing `test` is equivalent to a match.\n {\n test: [/\\.bmp$/, /\\.gif$/, /\\.jpe?g$/, /\\.png$/, /\\.svg$/],\n type: 'asset',\n parser: {\n dataUrlCondition: {\n maxSize: imageInlineSizeLimit,\n },\n },\n },\n // Process application JS with Babel.\n // The preset includes JSX, Flow, TypeScript, and some ESnext features.\n {\n test: /\\.(js|mjs|jsx|ts|tsx)$/,\n loader: require.resolve('babel-loader'),\n options: {\n babelrc: false,\n configFile: false,\n customize: require.resolve('babel-preset-react-app/webpack-overrides'),\n // This is a feature of `babel-loader` for webpack (not Babel itself).\n // It enables caching results in ./node_modules/.cache/babel-loader/\n // directory for faster rebuilds.\n cacheDirectory: true,\n // See #6846 for context on why cacheCompression is disabled\n cacheCompression: false,\n compact: isEnvProduction,\n },\n },\n // Process any JS outside of the app with Babel.\n // Unlike the application JS, we only compile the standard ES features.\n // Probably not needed in our use case\n // {\n // test: /\\.(js|mjs)$/,\n // exclude: /@babel(?:\\/|\\\\{1,2})runtime/,\n // loader: require.resolve('babel-loader'),\n // options: {\n // babelrc: false,\n // configFile: false,\n // compact: false,\n // presets: [[require.resolve('babel-preset-react-app/dependencies'), { helpers: true }]],\n // cacheDirectory: true,\n // // See #6846 for context on why cacheCompression is disabled\n // cacheCompression: false,\n\n // // Babel sourcemaps are needed for debugging into node_modules\n // // code. Without the options below, debuggers like VSCode\n // // show incorrect code and set breakpoints on the wrong lines.\n // sourceMaps: shouldUseSourceMap,\n // inputSourceMap: shouldUseSourceMap,\n // },\n // },\n\n // Adds support for CSS Modules (https://github.com/css-modules/css-modules)\n // using the extension .module.css\n {\n test: stylesRegexps.cssModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 1,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n modules: {\n getLocalIdent: getCSSModuleLocalIdent,\n },\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n })\n ),\n },\n // Opt-in support for SASS (using .scss or .sass extensions).\n // By default we support SASS Modules with the\n // extensions .module.scss or .module.sass\n {\n test: stylesRegexps.sassNoModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 3,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n preProcessOptions: {\n resolveUrlLoaderPath: require.resolve('resolve-url-loader'),\n preProcessorPath: require.resolve('sass-loader'),\n },\n })\n ),\n // Don't consider CSS imports dead code even if the\n // containing package claims to have no side effects.\n // Remove this when webpack adds a warning or an error for this.\n // See https://github.com/webpack/webpack/issues/6571\n sideEffects: true,\n },\n // Adds support for CSS Modules, but using SASS\n // using the extension .module.scss or .module.sass\n {\n test: stylesRegexps.sassModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 3,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n modules: {\n getLocalIdent: getCSSModuleLocalIdent,\n },\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n preProcessOptions: {\n resolveUrlLoaderPath: require.resolve('resolve-url-loader'),\n preProcessorPath: require.resolve('sass-loader'),\n },\n })\n ),\n },\n {\n test: stylesRegexps.lessNoModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 1,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n preProcessOptions: {\n resolveUrlLoaderPath: require.resolve('resolve-url-loader'),\n preProcessorPath: require.resolve('less-loader'),\n },\n })\n ),\n // Don't consider CSS imports dead code even if the\n // containing package claims to have no side effects.\n // Remove this when webpack adds a warning or an error for this.\n // See https://github.com/webpack/webpack/issues/6571\n sideEffects: true,\n },\n {\n test: stylesRegexps.lessModuleRegex,\n use: generateStyleLoaders(\n merge({}, baseStyleLoadersOptions, {\n cssLoaderOpts: {\n importLoaders: 1,\n sourceMap: isEnvProduction || shouldUseSourceMap,\n modules: {\n getLocalIdent: getCSSModuleLocalIdent,\n },\n },\n shouldUseSourceMap: isEnvProduction || shouldUseSourceMap,\n preProcessOptions: {\n resolveUrlLoaderPath: require.resolve('resolve-url-loader'),\n preProcessorPath: require.resolve('less-loader'),\n },\n })\n ),\n },\n // \"file\" loader makes sure those assets get served by WebpackDevServer.\n // When you `import` an asset, you get its (virtual) filename.\n // In production, they would get copied to the `build` folder.\n // This loader doesn't use a \"test\" so it will catch all modules\n // that fall through the other loaders.\n {\n // Exclude `js` files to keep \"css\" loader working as it injects\n // its runtime that would otherwise be processed through \"file\" loader.\n // Also exclude `html` and `json` extensions so they get processed\n // by webpacks internal loaders.\n exclude: [/\\.(js|mjs|jsx|ts|tsx)$/, /\\.html$/, /\\.json$/, /\\.css$/],\n type: 'asset/resource',\n },\n // ** STOP ** Are you adding a new loader?\n // Make sure to add the new loader(s) before the \"file\" loader.\n ],\n },\n ],\n },\n plugins: [\n new MiniCssExtractPlugin({\n // Options similar to the same options in webpackOptions.output\n // both options are optional\n filename: 'static/css/[name].[contenthash:8].css',\n chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',\n }),\n // Generate an asset manifest file with the following content:\n // - \"files\" key: Mapping of all asset filenames to their corresponding\n // output file so that tools can pick it up without having to parse\n // `index.html`\n // can be used to reconstruct the HTML if necessary\n new WebpackManifestPlugin({\n fileName: 'asset-manifest.json',\n generate: (seed, files, entrypoints) => {\n const manifestFiles = files.reduce((manifest, file) => {\n manifest[file.name] = file.path;\n return manifest;\n }, seed);\n const entrypointFiles = entrypoints.main.filter((fileName) => !fileName.endsWith('.map'));\n\n // @ts-ignore - https://github.com/shellscape/webpack-manifest-plugin/issues/276\n return {\n files: manifestFiles,\n entrypoints: entrypointFiles,\n } as Record<string, string>;\n },\n }),\n // Moment.js is an extremely popular library that bundles large locale files\n // by default due to how webpack interprets its code. This is a practical\n // solution that requires the user to opt into importing specific locales.\n // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack\n // You can remove this if you don't use Moment.js:\n new webpack.IgnorePlugin({\n resourceRegExp: /^\\.\\/locale$/,\n contextRegExp: /moment$/,\n }),\n // Generate a service worker script that will precache, and keep up to date,\n // the HTML & assets that are part of the webpack build.\n isEnvProduction &&\n new WorkboxWebpackPlugin.GenerateSW({\n clientsClaim: true,\n maximumFileSizeToCacheInBytes: 5000000,\n exclude: [/\\.map$/, /asset-manifest\\.json$/],\n // importWorkboxFrom: 'cdn',\n navigateFallback: 'public/index.html',\n navigateFallbackDenylist: [\n // Exclude URLs starting with /_, as they're likely an API call\n new RegExp('^/_'),\n // Exclude any URLs whose last part seems to be a file extension\n // as they're likely a resource and not a SPA route.\n // URLs containing a \"?\" character won't be blacklisted as they're likely\n // a route with query params (e.g. auth callbacks).\n new RegExp('/[^/?]+\\\\.[^/]+$'),\n ],\n }),\n ].filter(Boolean),\n // Some libraries import Node modules but don't use them in the browser.\n // Tell webpack to provide empty mocks for them so importing them works.\n // Turn off performance processing because we utilize\n // our own hints via the FileSizeReporter\n performance: false,\n };\n}\n"]}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.522",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/ui-foundation/ui",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.ui-foundation",
|
|
8
8
|
"name": "ui",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.522"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -53,28 +53,28 @@
|
|
|
53
53
|
"@teambit/base-ui.loaders.loader-ribbon": "1.0.0",
|
|
54
54
|
"@teambit/base-ui.theme.fonts.roboto": "1.0.0",
|
|
55
55
|
"@teambit/base-ui.theme.theme-provider": "1.0.1",
|
|
56
|
-
"@teambit/aspect-loader": "0.0.
|
|
57
|
-
"@teambit/toolbox.path.to-windows-compatible-path": "0.0.
|
|
58
|
-
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.
|
|
59
|
-
"@teambit/logger": "0.0.
|
|
56
|
+
"@teambit/aspect-loader": "0.0.522",
|
|
57
|
+
"@teambit/toolbox.path.to-windows-compatible-path": "0.0.442",
|
|
58
|
+
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.446",
|
|
59
|
+
"@teambit/logger": "0.0.449",
|
|
60
60
|
"@teambit/cli": "0.0.379",
|
|
61
|
-
"@teambit/ui-foundation.cli.ui-server-console": "0.0.
|
|
62
|
-
"@teambit/bundler": "0.0.
|
|
63
|
-
"@teambit/component": "0.0.
|
|
64
|
-
"@teambit/express": "0.0.
|
|
65
|
-
"@teambit/graphql": "0.0.
|
|
66
|
-
"@teambit/toolbox.network.get-port": "0.0.
|
|
67
|
-
"@teambit/aspect": "0.0.
|
|
68
|
-
"@teambit/cache": "0.0.
|
|
69
|
-
"@teambit/pubsub": "0.0.
|
|
70
|
-
"@teambit/react-router": "0.0.
|
|
71
|
-
"@teambit/ui-foundation.ui.rendering.html": "0.0.
|
|
61
|
+
"@teambit/ui-foundation.cli.ui-server-console": "0.0.447",
|
|
62
|
+
"@teambit/bundler": "0.0.522",
|
|
63
|
+
"@teambit/component": "0.0.522",
|
|
64
|
+
"@teambit/express": "0.0.453",
|
|
65
|
+
"@teambit/graphql": "0.0.522",
|
|
66
|
+
"@teambit/toolbox.network.get-port": "0.0.72",
|
|
67
|
+
"@teambit/aspect": "0.0.522",
|
|
68
|
+
"@teambit/cache": "0.0.449",
|
|
69
|
+
"@teambit/pubsub": "0.0.522",
|
|
70
|
+
"@teambit/react-router": "0.0.522",
|
|
71
|
+
"@teambit/ui-foundation.ui.rendering.html": "0.0.28",
|
|
72
72
|
"@teambit/design.theme.icons-font": "1.0.1",
|
|
73
73
|
"@teambit/design.ui.tooltip": "0.0.351",
|
|
74
|
-
"@teambit/ui-foundation.ui.global-loader": "0.0.
|
|
75
|
-
"@teambit/webpack.modules.generate-style-loaders": "0.0.
|
|
76
|
-
"@teambit/webpack.modules.style-regexps": "0.0.
|
|
77
|
-
"@teambit/webpack": "0.0.
|
|
74
|
+
"@teambit/ui-foundation.ui.global-loader": "0.0.445",
|
|
75
|
+
"@teambit/webpack.modules.generate-style-loaders": "0.0.62",
|
|
76
|
+
"@teambit/webpack.modules.style-regexps": "0.0.91",
|
|
77
|
+
"@teambit/webpack": "0.0.522"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/react": "^17.0.8",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
},
|
|
97
97
|
"peerDependencies": {
|
|
98
98
|
"@apollo/client": "^3.0.0",
|
|
99
|
-
"@teambit/legacy": "1.0.
|
|
99
|
+
"@teambit/legacy": "1.0.160",
|
|
100
100
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
101
101
|
"react": "^16.8.0 || ^17.0.0"
|
|
102
102
|
},
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
"react": "-"
|
|
142
142
|
},
|
|
143
143
|
"peerDependencies": {
|
|
144
|
-
"@teambit/legacy": "1.0.
|
|
144
|
+
"@teambit/legacy": "1.0.160",
|
|
145
145
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
146
146
|
"react": "^16.8.0 || ^17.0.0"
|
|
147
147
|
}
|
package/ssr/render-middleware.ts
CHANGED
|
@@ -73,13 +73,13 @@ async function loadRuntime(root: string, { logger }: { logger: Logger }) {
|
|
|
73
73
|
|
|
74
74
|
const manifestFilepath = path.join(root, 'asset-manifest.json');
|
|
75
75
|
if (!fs.existsSync(manifestFilepath)) {
|
|
76
|
-
logger.warn('[ssr] -
|
|
76
|
+
logger.warn('[ssr] - Skipping setup (cannot find asset manifest file)');
|
|
77
77
|
return undefined;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
assets = await parseManifest(manifestFilepath);
|
|
81
81
|
if (!assets) {
|
|
82
|
-
logger.warn('[ssr] - failed parsing assets manifest
|
|
82
|
+
logger.warn('[ssr] - Skipping setup (failed parsing assets manifest)');
|
|
83
83
|
return undefined;
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -101,15 +101,20 @@ async function loadRuntime(root: string, { logger }: { logger: Logger }) {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
async function parseManifest(filepath: string) {
|
|
104
|
+
async function parseManifest(filepath: string, logger?: Logger) {
|
|
105
105
|
try {
|
|
106
106
|
const file = await fs.readFile(filepath);
|
|
107
|
+
logger?.debug('[ssr] - ✓ aread manifest file');
|
|
107
108
|
const contents = file.toString();
|
|
108
109
|
const parsed: ManifestFile = JSON.parse(contents);
|
|
110
|
+
logger?.debug('[ssr] - ✓ prased manifest file', parsed);
|
|
109
111
|
const assets = getAssets(parsed);
|
|
112
|
+
logger?.debug('[ssr] - ✓ extracted data from manifest file', assets);
|
|
110
113
|
|
|
111
114
|
return assets;
|
|
112
115
|
} catch (e: any) {
|
|
116
|
+
logger?.error('[ssr] - error parsing asset manifest', e);
|
|
117
|
+
process.exit();
|
|
113
118
|
return undefined;
|
|
114
119
|
}
|
|
115
120
|
}
|
package/start-plugin.ts
CHANGED
package/start.cmd.tsx
CHANGED
|
@@ -73,9 +73,11 @@ export class StartCmd implements Command {
|
|
|
73
73
|
|
|
74
74
|
if (!noBrowser) {
|
|
75
75
|
uiServer
|
|
76
|
-
.then((server) => {
|
|
76
|
+
.then(async (server) => {
|
|
77
77
|
if (!server.buildOptions?.launchBrowserOnStart) return undefined;
|
|
78
78
|
|
|
79
|
+
await server.whenReady;
|
|
80
|
+
|
|
79
81
|
return open(this.ui.publicUrl || server.fullUrl);
|
|
80
82
|
})
|
|
81
83
|
.catch((error) => this.logger.error(error));
|
package/ui-server.ts
CHANGED
|
@@ -88,6 +88,12 @@ export class UIServer {
|
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
private setReady: () => void;
|
|
92
|
+
private startPromise = new Promise<void>((resolve) => (this.setReady = resolve));
|
|
93
|
+
get whenReady() {
|
|
94
|
+
return Promise.all([this.startPromise, ...this.plugins.map((x) => x?.whenReady)]);
|
|
95
|
+
}
|
|
96
|
+
|
|
91
97
|
/**
|
|
92
98
|
* start a UI server.
|
|
93
99
|
*/
|
|
@@ -118,12 +124,12 @@ export class UIServer {
|
|
|
118
124
|
// important: we use the string of the following message for the http.e2e.ts. if you change the message,
|
|
119
125
|
// please make sure you change the `HTTP_SERVER_READY_MSG` const.
|
|
120
126
|
this.logger.info(`UI server of ${this.uiRootExtension} is listening to port ${port}`);
|
|
127
|
+
|
|
128
|
+
this.setReady();
|
|
121
129
|
}
|
|
122
130
|
|
|
123
131
|
getPluginsComponents() {
|
|
124
|
-
return this.plugins.map((plugin) =>
|
|
125
|
-
return plugin.render();
|
|
126
|
-
});
|
|
132
|
+
return this.plugins.map((plugin) => plugin.render);
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
private async setupServerSideRendering({ root, port, app }: { root: string; port: number; app: Express }) {
|
|
@@ -347,10 +347,11 @@ export default function createWebpackConfig(
|
|
|
347
347
|
}, seed);
|
|
348
348
|
const entrypointFiles = entrypoints.main.filter((fileName) => !fileName.endsWith('.map'));
|
|
349
349
|
|
|
350
|
+
// @ts-ignore - https://github.com/shellscape/webpack-manifest-plugin/issues/276
|
|
350
351
|
return {
|
|
351
|
-
files:
|
|
352
|
-
entrypoints:
|
|
353
|
-
}
|
|
352
|
+
files: manifestFiles,
|
|
353
|
+
entrypoints: entrypointFiles,
|
|
354
|
+
} as Record<string, string>;
|
|
354
355
|
},
|
|
355
356
|
}),
|
|
356
357
|
// Moment.js is an extremely popular library that bundles large locale files
|
|
Binary file
|