Skip to content

Commit

Permalink
fix(optimizer): properly externalize unknown types
Browse files Browse the repository at this point in the history
fix #1793
  • Loading branch information
yyx990803 committed Jan 29, 2021
1 parent ff6149c commit c3b81a8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ function esbuildScanPlugin(
}
)

const parseableTypes = /\.(j|t)sx?$|\.mjs$/

// catch all
build.onResolve(
{
Expand All @@ -276,8 +278,7 @@ function esbuildScanPlugin(
// use vite resolver to support urls and omitted extensions
const resolved = await resolve(id, importer)
if (resolved && resolved !== id) {
// in case user has configured to externalize additional assets
if (config.assetsInclude(id)) {
if (!parseableTypes.test(resolved)) {
return { path: id, external: true }
}
return {
Expand All @@ -294,7 +295,7 @@ function esbuildScanPlugin(
// for jsx/tsx, we need to access the content and check for
// presence of import.meta.glob, since it results in import relationships
// but isn't crawled by esbuild.
build.onLoad({ filter: /\.(j|t)sx?$|\.mjs$/ }, ({ path: id }) => {
build.onLoad({ filter: parseableTypes }, ({ path: id }) => {
let ext = path.extname(id).slice(1)
if (ext === 'mjs') ext = 'js'
const contents = fs.readFileSync(id, 'utf-8')
Expand Down

0 comments on commit c3b81a8

Please sign in to comment.