Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(dev-server): single-threaded dev-server for debugging
Allow the dev server to run on the same process so it's easier to debug and step through http requests and responses. Added for the on-demand dev mode prerendering and dev node module feature.
- Loading branch information
1 parent
52c3485
commit cf335e3
Showing
34 changed files
with
996 additions
and
859 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { Plugin } from 'rollup'; | ||
import type { BuildOptions } from '../../utils/options'; | ||
import fs from 'fs-extra'; | ||
import { join } from 'path'; | ||
|
||
export function contentTypesPlugin(opts: BuildOptions): Plugin { | ||
return { | ||
name: 'contentTypesPlugin', | ||
resolveId(id) { | ||
if (id.endsWith('content-types-db.json')) { | ||
return id; | ||
} | ||
return null; | ||
}, | ||
load(id) { | ||
if (id.endsWith('content-types-db.json')) { | ||
return createContentTypeData(opts); | ||
} | ||
return null; | ||
}, | ||
}; | ||
} | ||
|
||
async function createContentTypeData(opts: BuildOptions) { | ||
// create a focused content-type lookup object from | ||
// the mime db json file | ||
const mimeDbSrcPath = join(opts.nodeModulesDir, 'mime-db', 'db.json'); | ||
const mimeDbJson = await fs.readJson(mimeDbSrcPath); | ||
|
||
const extData: { ext: string; mimeType: string }[] = []; | ||
|
||
Object.keys(mimeDbJson).forEach(mimeType => { | ||
const mimeTypeData = mimeDbJson[mimeType]; | ||
if (Array.isArray(mimeTypeData.extensions)) { | ||
mimeTypeData.extensions.forEach(ext => { | ||
extData.push({ | ||
ext, | ||
mimeType, | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
const exts = {}; | ||
extData | ||
.sort((a, b) => { | ||
if (a.ext < b.ext) return -1; | ||
if (a.ext > b.ext) return 1; | ||
return 0; | ||
}) | ||
.forEach(x => (exts[x.ext] = x.mimeType)); | ||
|
||
return `export default ${JSON.stringify(exts)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.