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 # Static Data
<script setup lang="ts"> <script setup lang="ts">
import { data } from './basic.data.js' import { data } from './basic.data.mjs'
import { data as contentData } from './contentLoader.data.js' import { data as contentData } from './contentLoader.data.js'
</script> </script>

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

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

Loading…
Cancel
Save