Skip to content

Commit

Permalink
fix: populate optimizeDeps options in build mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Mar 8, 2022
1 parent b0f2975 commit 7f7eb56
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,56 +152,55 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
});
}

if (!isBuild) {
const lookup = compiler.taglib.buildLookup(root) as any;
const domRuntimeDeps = compiler.getRuntimeEntryFiles(
"dom",
opts.translator
);
const htmlRuntimeDeps = compiler.getRuntimeEntryFiles(
"html",
opts.translator
);
const taglibDeps: string[] = [];

for (const name in lookup.taglibsById) {
const taglib = lookup.taglibsById[name];
if (/[\\/]node_modules[\\/](?!@marko[\\/])/.test(taglib.dirname)) {
for (const tagName in taglib.tags) {
const tag = taglib.tags[tagName];
const entry = tag.template || tag.renderer;

if (entry) {
taglibDeps.push(
entry.replace(/^.*?[\\/]node_modules[\\/]/, "")
);
}
const lookup = compiler.taglib.buildLookup(root) as any;
const taglibDeps: string[] = [];

for (const name in lookup.taglibsById) {
const taglib = lookup.taglibsById[name];
if (/[\\/]node_modules[\\/](?!@marko[\\/])/.test(taglib.dirname)) {
for (const tagName in taglib.tags) {
const tag = taglib.tags[tagName];
const entry = tag.template || tag.renderer;

if (entry) {
taglibDeps.push(
entry.replace(/^.*?[\\/]node_modules[\\/]/, "")
);
}
}
}
}

const domDeps = Array.from(
new Set(domRuntimeDeps.concat(taglibDeps))
);
const serverDeps = Array.from(
new Set(htmlRuntimeDeps.concat(taglibDeps))
);
const domDeps = Array.from(
new Set(
compiler
.getRuntimeEntryFiles("dom", opts.translator)
.concat(taglibDeps)
)
);

const optimizeDeps = (config.optimizeDeps ??= {});
optimizeDeps.include ??= [];
optimizeDeps.include = optimizeDeps.include.concat(
domDeps.filter((dep) => path.extname(dep) !== markoExt)
);
const optimizeDeps = (config.optimizeDeps ??= {});
optimizeDeps.include ??= [];
optimizeDeps.include = optimizeDeps.include.concat(
domDeps.filter((dep) => path.extname(dep) !== markoExt)
);

optimizeDeps.exclude ??= [];
optimizeDeps.exclude = optimizeDeps.exclude.concat(
domDeps.filter((dep) => path.extname(dep) === markoExt)
);
optimizeDeps.exclude ??= [];
optimizeDeps.exclude = optimizeDeps.exclude.concat(
domDeps.filter((dep) => path.extname(dep) === markoExt)
);

if (!isBuild) {
const serverDeps = Array.from(
new Set(
compiler
.getRuntimeEntryFiles("html", opts.translator)
.concat(taglibDeps)
)
);
const ssr = ((config as any).ssr ??= {});
ssr.external ??= [];
ssr.external = ssr.external.concat(serverDeps);

// Vite cannot handle commonjs modules, which many Marko component libraries
// use in conjunction with the `.marko` files. To support this
// we tell Vite to ignore all `.marko` files in node_modules for the server.
Expand Down

0 comments on commit 7f7eb56

Please sign in to comment.