env setup
This commit is contained in:
parent
5e4c128319
commit
2332101482
@ -70,9 +70,13 @@ function copyFilesPlugin(files: Array<string>) {
|
|||||||
return {
|
return {
|
||||||
name: "copy-files",
|
name: "copy-files",
|
||||||
setup(build: PluginBuild) {
|
setup(build: PluginBuild) {
|
||||||
|
if (!files || !files.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const outDir = build.initialOptions.outdir;
|
const outDir = build.initialOptions.outdir;
|
||||||
if (outDir === undefined)
|
if (outDir === undefined) {
|
||||||
throw Error("esbuild build options does not specify outdir");
|
throw Error("esbuild build options does not specify outdir");
|
||||||
|
}
|
||||||
build.onEnd(() => {
|
build.onEnd(() => {
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const name = path.parse(file).base;
|
const name = path.parse(file).base;
|
||||||
@ -143,7 +147,6 @@ function linariaPlugin() {
|
|||||||
|
|
||||||
const defaultEsBuildConfig: esbuild.BuildOptions = {
|
const defaultEsBuildConfig: esbuild.BuildOptions = {
|
||||||
bundle: true,
|
bundle: true,
|
||||||
minify: false,
|
|
||||||
loader: {
|
loader: {
|
||||||
".svg": "file",
|
".svg": "file",
|
||||||
".inline.svg": "text",
|
".inline.svg": "text",
|
||||||
@ -157,7 +160,6 @@ const defaultEsBuildConfig: esbuild.BuildOptions = {
|
|||||||
target: ["es6"],
|
target: ["es6"],
|
||||||
format: "esm",
|
format: "esm",
|
||||||
platform: "browser",
|
platform: "browser",
|
||||||
sourcemap: true,
|
|
||||||
jsxFactory: "h",
|
jsxFactory: "h",
|
||||||
jsxFragment: "Fragment",
|
jsxFragment: "Fragment",
|
||||||
alias: {
|
alias: {
|
||||||
@ -171,6 +173,7 @@ const defaultEsBuildConfig: esbuild.BuildOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface BuildParams {
|
export interface BuildParams {
|
||||||
|
type: "development" | "test" | "production";
|
||||||
source: {
|
source: {
|
||||||
assets: string[];
|
assets: string[];
|
||||||
js: string[];
|
js: string[];
|
||||||
@ -186,6 +189,7 @@ export function computeConfig(params: BuildParams): esbuild.BuildOptions {
|
|||||||
copyFilesPlugin(params.source.assets),
|
copyFilesPlugin(params.source.assets),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (params.css) {
|
||||||
switch (params.css) {
|
switch (params.css) {
|
||||||
case "sass": {
|
case "sass": {
|
||||||
plugins.push(sassPlugin);
|
plugins.push(sassPlugin);
|
||||||
@ -208,11 +212,31 @@ export function computeConfig(params: BuildParams): esbuild.BuildOptions {
|
|||||||
throw Error(`not supported: ${cssType}`);
|
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 {
|
return {
|
||||||
...defaultEsBuildConfig,
|
...defaultEsBuildConfig,
|
||||||
entryPoints: params.source.js,
|
entryPoints: params.source.js,
|
||||||
publicPath: params.public,
|
publicPath: params.public,
|
||||||
outdir: params.destination,
|
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,
|
plugins,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -108,9 +108,9 @@ export class BrowserHttpLib implements HttpRequestLibrary {
|
|||||||
}, requestTimeout.d_ms);
|
}, requestTimeout.d_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const headerName in Object.keys(requestHeadersMap)) {
|
Object.keys(requestHeadersMap).forEach((headerName) => {
|
||||||
myRequest.setRequestHeader(headerName, requestHeadersMap[headerName]);
|
myRequest.setRequestHeader(headerName, requestHeadersMap[headerName]);
|
||||||
}
|
});
|
||||||
|
|
||||||
myRequest.responseType = "arraybuffer";
|
myRequest.responseType = "arraybuffer";
|
||||||
myRequest.send(myBody);
|
myRequest.send(myBody);
|
||||||
|
Loading…
Reference in New Issue
Block a user