Skip to content

Commit a6064e1

Browse files
committed
feat: support ES5
1 parent 83f7522 commit a6064e1

4 files changed

Lines changed: 159 additions & 21 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"devDependencies": {
6060
"@mvlchain/eslint-config": "^1.0.3",
6161
"@mvlchain/prettier-config": "^1.0.1",
62+
"@swc/core": "^1.3.101",
6263
"@types/google.maps": "^3.54.10",
6364
"@types/react": "^18.2.33",
6465
"@types/react-dom": "^18.2.14",

pnpm-lock.yaml

Lines changed: 130 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/appendScript.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@ export const appendLibImportScript = ({ apiKey, v = 'weekly', libraries, languag
1313
const lib = Array.from(new Set<LibraryName>((['maps', 'core'] as LibraryName[]).concat(libraries ?? []))).join(',');
1414

1515
// code from https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import
16-
script.innerHTML = `(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=\`https://maps.\${c}apis.com/maps/api/js?\`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
17-
key: "${apiKey}",
18-
v: "${v}",
19-
libraries: "${lib}",
20-
${language ? `language: "${language}",` : ''}
21-
${region ? `region: "${region}",` : ''}
22-
${authReferrerPolicy ? `authReferrerPolicy: "${authReferrerPolicy}",` : ''}
23-
});`;
16+
script.innerHTML = `(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=\`https://maps.\${c}apis.com/maps/api/js?\`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));if(m.querySelector("script[nonce]")){a.nonce=m.querySelector("script[nonce]").nonce}else{a.nonce=""};m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({key: "${apiKey}",v: "${v}",libraries: "${lib}",${
17+
language ? `language: "${language}",` : ''
18+
}${region ? `region: "${region}",` : ''}${authReferrerPolicy ? `authReferrerPolicy: "${authReferrerPolicy}",` : ''}});`;
2419

2520
document.head.append(script);
2621
};

tsup.config.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
import { defineConfig } from 'tsup';
1+
import { Options, defineConfig } from 'tsup';
22

3-
export default defineConfig({
4-
entry: ['src/index.ts'],
5-
format: ['esm', 'cjs'],
6-
splitting: false,
7-
sourcemap: false,
8-
clean: true,
9-
minify: true,
10-
dts: true,
11-
legacyOutput: true,
3+
export default defineConfig((options) => {
4+
const commonOptions: Partial<Options> = {
5+
...options,
6+
entry: ['src/index.ts'],
7+
splitting: false,
8+
sourcemap: false,
9+
clean: true,
10+
minify: true,
11+
dts: true,
12+
legacyOutput: true,
13+
};
14+
15+
return [
16+
{
17+
...commonOptions,
18+
format: ['cjs'],
19+
target: 'es5',
20+
},
21+
{
22+
...commonOptions,
23+
format: ['esm'],
24+
target: 'es6',
25+
},
26+
];
1227
});

0 commit comments

Comments
 (0)