Skip to content

Commit

Permalink
fix: optimize umd bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Jul 10, 2022
1 parent a1b58b1 commit 88ee554
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 45 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"svelte": "^3.49.0",
"svelte-preprocess": "^4.10.7",
"svelte2tsx": "^0.5.11",
"tsdv": "^0.4.0",
"tsdv": "^0.5.0",
"typescript": "^4.7.4",
"vite": "^2.9.12"
"vite": "^2.9.13"
},
"packageManager": "[email protected]",
"bundlewatch": {
Expand Down
21 changes: 12 additions & 9 deletions packages/bytemd/tsdv.config.mjs → packages/bytemd/tsdv.config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// @ts-check
import { defineConfig } from 'tsdv'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { alias, sveltePreprocessor } from '../../scripts/build.mjs'
import { getAlias, sveltePreprocessor } from '../../scripts/build.mjs'

// nullish coalescing in es2020
export default defineConfig({
target: 'es2019',
tsc: false,
vite: {
resolve: { alias },
plugins: [
svelte({
preprocess: [sveltePreprocessor],
}),
],
vite({ format }) {
return {
resolve: {
alias: getAlias(format),
},
plugins: [
svelte({
preprocess: [sveltePreprocessor],
}),
],
}
},
test: {
globals: true,
Expand Down
10 changes: 7 additions & 3 deletions packages/plugin-gfm/tsdv.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { defineConfig } from 'tsdv'
import { alias } from '../../scripts/build.mjs'
import { getAlias } from '../../scripts/build.mjs'

export default defineConfig({
target: 'es2019',
tsc: false,
vite: {
resolve: { alias },
vite({ format }) {
return {
resolve: {
alias: getAlias(format),
},
}
},
})
48 changes: 22 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ export const sveltePreprocessor = sveltePreprocess({
],
})

const pkgName = 'decode-named-character-reference'
// do not resolve `browser` field to make CJS bundle work at SSR
// https://github.com/vitejs/vite/issues/4405
export function getAlias(format) {
const pkgName = 'decode-named-character-reference'

export const alias = {
// do not resolve `browser` field to make it work at SSR
// https://github.com/vitejs/vite/issues/4405
[pkgName]: resolve.sync(pkgName),
if (format === 'cjs')
return {
[pkgName]: resolve.sync(pkgName),
}
}

0 comments on commit 88ee554

Please sign in to comment.