Skip to content

Commit

Permalink
feat: avoid loading babel config by default
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Sep 29, 2023
1 parent 08ea2a9 commit 717c099
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-trains-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": major
---

No longer load babel config by default unless configured.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ app.listen(3000);
### options.babelConfig
You can manually override Marko's Babel configuration by passing a `babelConfig` object to the `@marko/vite` plugin. By default Babel's regular [config file resolution](https://babeljs.io/docs/en/config-files) will be used.
You can manually override Marko's Babel configuration by passing a `babelConfig` object to the `@marko/vite` plugin. If no babel configuration is specified, babel related config files will not be considered.
```javascript
marko({
Expand Down
78 changes: 46 additions & 32 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ const resolveOpts = { skipSelf: true };
const cache = new Map<unknown, unknown>();
const thisFile =
typeof __filename === "string" ? __filename : fileURLToPath(import.meta.url);
const babelCaller = {
name: "@marko/vite",
supportsStaticESM: true,
supportsDynamicImport: true,
supportsTopLevelAwait: true,
supportsExportNamespaceFrom: true,
};

export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
let compiler: typeof Compiler;
Expand All @@ -108,26 +115,24 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
let domConfig: Compiler.Config;
let hydrateConfig: Compiler.Config;

const resolveViteVirtualDep: Compiler.Config["resolveVirtualDependency"] = (
from,
dep
) => {
const query = `${virtualFileQuery}&id=${encodeURIComponent(
normalizePath(dep.virtualPath)
)}`;
const normalizedFrom = normalizePath(from);
const id = normalizePath(normalizedFrom) + query;

if (devServer) {
const prev = virtualFiles.get(id);
if (isDeferredPromise(prev)) {
prev.resolve(dep);
const resolveVirtualDependency: Compiler.Config["resolveVirtualDependency"] =
(from, dep) => {
const query = `${virtualFileQuery}&id=${encodeURIComponent(
normalizePath(dep.virtualPath)
)}`;
const normalizedFrom = normalizePath(from);
const id = normalizePath(normalizedFrom) + query;

if (devServer) {
const prev = virtualFiles.get(id);
if (isDeferredPromise(prev)) {
prev.resolve(dep);

Check warning on line 129 in src/index.ts

View check run for this annotation

Codecov / codecov/patch

src/index.ts#L129

Added line #L129 was not covered by tests
}
}
}

virtualFiles.set(id, dep);
return `./${path.posix.basename(normalizedFrom) + query}`;
};
virtualFiles.set(id, dep);
return `./${path.posix.basename(normalizedFrom) + query}`;
};

let root: string;
let devEntryFile: string;
Expand Down Expand Up @@ -163,34 +168,43 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
runtimeId,
sourceMaps: true,
writeVersionComment: false,
babelConfig: {
...opts.babelConfig,
caller: {
name: "@marko/vite",
supportsStaticESM: true,
supportsDynamicImport: true,
supportsTopLevelAwait: true,
supportsExportNamespaceFrom: true,
...opts.babelConfig?.caller,
},
},
babelConfig: opts.babelConfig
? {
...opts.babelConfig,
caller: opts.babelConfig.caller
? {
name: "@marko/vite",
supportsStaticESM: true,
supportsDynamicImport: true,
supportsTopLevelAwait: true,
supportsExportNamespaceFrom: true,
...opts.babelConfig.caller,
}
: babelCaller,
}
: {
babelrc: false,
configFile: false,
browserslistConfigFile: false,
caller: babelCaller,
},
};

ssrConfig = {
...baseConfig,
resolveVirtualDependency: resolveViteVirtualDep,
resolveVirtualDependency,
output: "html",
};

domConfig = {
...baseConfig,
resolveVirtualDependency: resolveViteVirtualDep,
resolveVirtualDependency,
output: "dom",
};

hydrateConfig = {
...baseConfig,
resolveVirtualDependency: resolveViteVirtualDep,
resolveVirtualDependency,
output: "hydrate",
};

Expand Down

0 comments on commit 717c099

Please sign in to comment.