Skip to content

Commit

Permalink
fix: do not polyfill import.meta.url
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Dec 9, 2021
1 parent 43e901c commit c878559
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { defineConfig } from 'vite'
import prefresh from '@prefresh/vite'
import { createConfig } from '../scripts/utils'

const config = createConfig('preact', false, true)
export default defineConfig({
...createConfig('preact', false, true),
// @ts-expect-error
plugins: [prefresh()],
...config,
plugins: [...(config.plugins || []), prefresh()],
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"element-in-view": "^0.1.0",
"htm": "^3.0.4",
"magic-string": "^0.25.7",
"marked": "^2.0.0",
"preact": "^10.5.12",
"prismjs": "^1.23.0"
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

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

24 changes: 23 additions & 1 deletion scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { rollup } from 'rollup'
import dts from 'rollup-plugin-dts'
import tsResolve from '@egoist/rollup-plugin-ts-resolve'
import { UserConfig } from 'vite'
import MagicString from 'magic-string'

const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'))

Expand Down Expand Up @@ -33,11 +34,32 @@ export const createConfig = (
PRISM_VERSION: JSON.stringify(require('prismjs/package').version),
PRISM_LANGUAGES: JSON.stringify(getPrismLanguages()),
},
// plugins: [
// {
// name: 'import_meta_url',
// enforce: 'post',
// renderChunk(code) {
// const index = code.indexOf('import_meta_url')

// if (index === -1) return
// const s = new MagicString(code)
// s.overwrite(
// index,
// index + 'import_meta_url'.length,
// 'import.meta.url'
// )
// return {
// code: s.toString(),
// map: s.generateMap({ hires: true }),
// }
// },
// },
// ],
build: {
emptyOutDir: false,
minify,
sourcemap: true,

target: 'esnext',
rollupOptions: {
preserveEntrySignatures: 'strict',
input: isWebsite
Expand Down
1 change: 1 addition & 0 deletions src/markdown-component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const MD_PROPS_KEY = `MD_C_PROPS`

// prevent vite from shimming import.meta.url
let docupUrl = import.meta.url
if (import.meta.env.DEV) {
// During dev it's not bundled
Expand Down
2 changes: 2 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ interface Window {
MD_C_PROPS: any
_MD_COMPONENTS: Record<string, any>
}

declare const import_meta_url: string

1 comment on commit c878559

@vercel
Copy link

@vercel vercel bot commented on c878559 Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.