fix(js-client): Fix CDN flow and move it in modules [fixes DXJ-527] (#376)

* Use type module in html

* Fix autocommit

* Try fix template

* Try fix template

* Try fix template

* Try fix template

* Try fix template

* Fix test

* Update packages/@tests/smoke/web/public/index.html

Co-authored-by: shamsartem <shamsartem@gmail.com>

* Minify es bundle

* Remove autocommit

* Fix lint

* Remove minimal

* Change nox version

* Change nox version

* Fix CDN

---------

Co-authored-by: shamsartem <shamsartem@gmail.com>
This commit is contained in:
Akim
2023-11-10 21:29:49 +07:00
committed by GitHub
parent 1803d83ce7
commit f5e9923974
11 changed files with 322 additions and 54 deletions

View File

@ -68,6 +68,7 @@
"@types/debug": "4.1.7",
"@types/node": "20.7.0",
"@types/uuid": "8.3.2",
"esbuild": "0.19.5",
"hotscript": "1.0.13",
"vite": "4.4.11",
"vite-tsconfig-paths": "4.0.3",

View File

@ -176,16 +176,6 @@ export type {
export { v5_callFunction, v5_registerService } from "./api.js";
// @ts-expect-error Writing to global object like this prohibited by ts
globalThis.new_fluence = Fluence;
// @ts-expect-error Writing to global object like this prohibited by ts
globalThis.fluence = {
clientFactory: createClient,
callAquaFunction,
registerService,
};
export { createClient, callAquaFunction, registerService };
// Deprecated exports. Later they will be exposed only under js-client/keypair path

View File

@ -17,11 +17,30 @@
import inject from "@rollup/plugin-inject";
import tsconfigPaths from "vite-tsconfig-paths";
import { createRequire } from "module";
import { UserConfig } from "vite";
import { PluginOption, UserConfig } from "vite";
import { transform } from "esbuild";
const require = createRequire(import.meta.url);
const esbuildShim = require.resolve("node-stdlib-browser/helpers/esbuild/shim");
function minifyEs(): PluginOption {
return {
name: "minifyEs",
renderChunk: {
order: "post",
async handler(code, chunk, outputOptions) {
if (
outputOptions.format === "es" &&
chunk.fileName.endsWith(".min.js")
) {
return await transform(code, { minify: true });
}
return code;
},
},
};
}
const config: UserConfig = {
build: {
target: "modules",
@ -30,7 +49,7 @@ const config: UserConfig = {
entry: "./src/index.ts",
name: "js-client",
fileName: () => "index.min.js",
formats: ["umd"],
formats: ["es"],
},
outDir: "./dist/browser",
rollupOptions: {
@ -47,7 +66,7 @@ const config: UserConfig = {
],
},
},
plugins: [tsconfigPaths()],
plugins: [tsconfigPaths(), minifyEs()],
optimizeDeps: {
esbuildOptions: {
define: {