diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/web-util/src/index.build.ts | 64 | ||||
-rw-r--r-- | packages/web-util/src/utils/http-impl.browser.ts | 4 |
2 files changed, 46 insertions, 22 deletions
diff --git a/packages/web-util/src/index.build.ts b/packages/web-util/src/index.build.ts index 06961c4b4..ad31afb5c 100644 --- a/packages/web-util/src/index.build.ts +++ b/packages/web-util/src/index.build.ts @@ -70,9 +70,13 @@ function copyFilesPlugin(files: Array<string>) { return { name: "copy-files", setup(build: PluginBuild) { + if (!files || !files.length) { + return; + } const outDir = build.initialOptions.outdir; - if (outDir === undefined) + if (outDir === undefined) { throw Error("esbuild build options does not specify outdir"); + } build.onEnd(() => { for (const file of files) { const name = path.parse(file).base; @@ -143,7 +147,6 @@ function linariaPlugin() { const defaultEsBuildConfig: esbuild.BuildOptions = { bundle: true, - minify: false, loader: { ".svg": "file", ".inline.svg": "text", @@ -157,7 +160,6 @@ const defaultEsBuildConfig: esbuild.BuildOptions = { target: ["es6"], format: "esm", platform: "browser", - sourcemap: true, jsxFactory: "h", jsxFragment: "Fragment", alias: { @@ -171,6 +173,7 @@ const defaultEsBuildConfig: esbuild.BuildOptions = { }; export interface BuildParams { + type: "development" | "test" | "production"; source: { assets: string[]; js: string[]; @@ -186,33 +189,54 @@ export function computeConfig(params: BuildParams): esbuild.BuildOptions { copyFilesPlugin(params.source.assets), ]; - switch (params.css) { - case "sass": { - plugins.push(sassPlugin); - break; - } - case "postcss": { - plugins.push(postCssPlugin); - break; - } + if (params.css) { + switch (params.css) { + case "sass": { + plugins.push(sassPlugin); + break; + } + case "postcss": { + plugins.push(postCssPlugin); + break; + } - case "linaria": { - if (params.linariaPlugin) { - plugins.push(params.linariaPlugin()); + case "linaria": { + if (params.linariaPlugin) { + plugins.push(params.linariaPlugin()); + } + break; } - break; - } - default: { - const cssType: never = params.css; - throw Error(`not supported: ${cssType}`); + default: { + const cssType: never = params.css; + throw Error(`not supported: ${cssType}`); + } } } + if (!params.type) { + throw Error( + `missing build type, it should be "test", "development" or "production"`, + ); + } + + if (!params.source.js) { + throw Error(`no javascript entry points, nothing to compile?`); + } + if (!params.destination) { + throw Error(`missing destination folder`); + } + return { ...defaultEsBuildConfig, entryPoints: params.source.js, publicPath: params.public, outdir: params.destination, + minify: false, //params.type === "production", + sourcemap: true, //params.type !== "production", + define: { + ...defaultEsBuildConfig.define, + "process.env.NODE_ENV": JSON.stringify(params.type), + }, plugins, }; } diff --git a/packages/web-util/src/utils/http-impl.browser.ts b/packages/web-util/src/utils/http-impl.browser.ts index 3bc5bb141..a46e8d63f 100644 --- a/packages/web-util/src/utils/http-impl.browser.ts +++ b/packages/web-util/src/utils/http-impl.browser.ts @@ -108,9 +108,9 @@ export class BrowserHttpLib implements HttpRequestLibrary { }, requestTimeout.d_ms); } - for (const headerName in Object.keys(requestHeadersMap)) { + Object.keys(requestHeadersMap).forEach((headerName) => { myRequest.setRequestHeader(headerName, requestHeadersMap[headerName]); - } + }); myRequest.responseType = "arraybuffer"; myRequest.send(myBody); |