mustafadalga / remove-attr

Vite Plugin - Remove Attributes
https://www.npmjs.com/package/remove-attr
MIT License
2 stars 2 forks source link

Plugin breaks sourcemaps #1

Closed philipp-tailor closed 1 month ago

philipp-tailor commented 6 months ago

For context: I'm talking about a Vue app built with Vite 5.0.12, with the following plugin configuration:

// vite.config.js
export default defineConfig(async ({command, mode}) => {
    const config = {
            // ... my other config
    }

    if (command === 'build' && mode === 'production') {
        const removeAttr = (await import('remove-attr')).default
        config.plugins.push(
            removeAttr({
                extensions: ['vue'],
                attributes: ['data-test'],
            })
        )
    }

    return config
})

When building, I'm getting the following error message - seemingly repeated for every single affected .vue file:

(remove-attributes plugin) Sourcemap is likely to be incorrect: a plugin (remove-attributes) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help

The sourcemaps of all files, even JS files which aren't even affected by the plugin look as follows:

{"version":3,"file":"myFile.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}

When I uncomment remove-attr, valid sourcemaps are being generated.

Oleksii14 commented 4 months ago

Same here. I found this commit in the Vuetify repo that fixed the same issue there. I think we need to add something like that in this file:

return { code: output, map: null };
Oleksii14 commented 2 months ago

Workaround

import removeAttr from 'remove-attr';

const removeAttrPlugin = removeAttr({
  extensions: ['vue'],
  attributes: ['data-testid'],
});

export default {
  ...removeAttrPlugin,
  transform(code, id) {
    const result = removeAttrPlugin.transform(code, id);
    return {
      code: result,
      map: null,
    };
  },
};

And vite.config

import removeAttr from './vite-remove-attr-plugin';

export default {
  ...,
  plugins: [removeAttr]
}
mustafadalga commented 1 month ago

@philipp-tailor I checked with vite@5.0.12 and vue@3.4.29 but I could not see same error. Can you provide reproducible example