Skip to content

Commit

Permalink
Added api.js build script (auto init)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyaoleshko committed Nov 18, 2024
1 parent 5ef9240 commit 1c36d3e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ const options = {
treeShaking: true,
logLevel: "info",
sourcemap: false,
entryPoints: ["./src/main.ts"],
};

async function buildAll() {
Promise.all([
await build({
format: "esm",
outdir: "dist/esm",
entryPoints: ["./src/main.ts"],
plugins: [
esbuildPluginTsc({ force: true }),
{
Expand All @@ -50,6 +50,7 @@ async function buildAll() {
await build({
format: "cjs",
outdir: "dist/cjs",
entryPoints: ["./src/main.ts"],
plugins: [
esbuildPluginTsc({ force: true })
],
Expand All @@ -59,6 +60,7 @@ async function buildAll() {
await build({
format: "iife",
outfile: "./dist/api.js",
entryPoints: ["./src/main.browser.ts"],
...options,
}).catch(() => process.exit(1)),
]);
Expand Down
26 changes: 26 additions & 0 deletions src/main.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import SDK from "./sdk";
import { getConfigFromParams } from "./utils";

window.DocSpace = window.DocSpace || {};

const config = getConfigFromParams();

window.DocSpace.SDK = window.DocSpace.SDK || new SDK();

if (config?.init) window.DocSpace.SDK.init(config);

0 comments on commit 1c36d3e

Please sign in to comment.