fix(build): handle .mjs/.mts files as data / path loaders (#3058)

pull/3060/head
Divyansh Singh 9 months ago committed by GitHub
parent 1a461c073d
commit 7991180080
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,7 @@
# Static Data
<script setup lang="ts">
import { data } from './basic.data.js'
import { data } from './basic.data.mjs'
import { data as contentData } from './contentLoader.data.js'
</script>

@ -162,19 +162,21 @@ export async function resolveDynamicRoutes(
for (const route of routes) {
// locate corresponding route paths file
const fullPath = normalizePath(path.resolve(srcDir, route))
const jsPathsFile = fullPath.replace(/\.md$/, '.paths.js')
let pathsFile = jsPathsFile
if (!fs.existsSync(jsPathsFile)) {
pathsFile = fullPath.replace(/\.md$/, '.paths.ts')
if (!fs.existsSync(pathsFile)) {
console.warn(
c.yellow(
`Missing paths file for dynamic route ${route}: ` +
`a corresponding ${jsPathsFile} or ${pathsFile} is needed.`
)
const paths = ['js', 'ts', 'mjs', 'mts'].map((ext) =>
fullPath.replace(/\.md$/, `.paths.${ext}`)
)
const pathsFile = paths.find((p) => fs.existsSync(p))
if (pathsFile == null) {
console.warn(
c.yellow(
`Missing paths file for dynamic route ${route}: ` +
`a corresponding ${paths[0]} (or .ts/.mjs/.mts) file is needed.`
)
continue
}
)
continue
}
// load the paths loader module

@ -8,7 +8,7 @@ import path, { dirname, resolve } from 'path'
import { isMatch } from 'micromatch'
import glob from 'fast-glob'
const loaderMatch = /\.data\.(j|t)s($|\?)/
const loaderMatch = /\.data\.m?(j|t)s($|\?)/
let server: ViteDevServer

Loading…
Cancel
Save