Open
Description
The vite plugin breaks debugging as it appears babel is forcing sourceMaps to not generate and breaking everything in dev. As a proof of concept I hard edited ./node_modules/@suid/vite-plugin/index.mjs
in my project to replace the transform method with this:
function transform(code, options, id) {
const ast = parse(code, options.parserOptions);
traverse(ast, {
enter(path) {
const { node } = path;
const optimize = types.isImportDeclaration(node) && options.optimizeImports.paths.some((v) => v === node.source.value);
if (!optimize) return;
const imports = node.specifiers.map((spec) => {
if (types.isImportSpecifier(spec) && types.isIdentifier(spec.imported) && types.isIdentifier(spec.local)) {
return getOptimizedImportPath(
node.source.value,
spec.imported.name,
spec.local.name
);
}
}).filter((v) => !!v);
path.replaceWithMultiple(
imports.map(
(item) => types.importDeclaration(
typeof item.specifier === "string" ? [types.importDefaultSpecifier(types.identifier(item.specifier))] : [
...Object.entries(item.specifier).map(
([alias, specifier]) => types.importSpecifier(
types.identifier(specifier),
types.identifier(alias)
)
)
],
types.stringLiteral(item.path)
)
)
);
}
});
return generate(ast, {
sourceMaps: true,
sourceFileName: id
});
}
The changes being to add id
to the transform method's parameters for later and then passing the id to sourceFileName
to the generate call at the end along with sourceMaps: true
and then updated the call to transform in the suidPlugin return:
return {
// everything else
transform(code, id) {
const transformIconImportsOptions = options.optimizeImports || {};
if (transformIconImportsOptions.enabled && transformIconImportsOptions.paths?.some((p) => code.includes(p))) {
return transform(code, options, id);
}
}
};
and just like that my step debugging was fixed.
Metadata
Metadata
Assignees
Labels
No labels