Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow @rollup/plugin-virtual to be a function that takes a module ID #1721

Open
qzsiniong opened this issue May 23, 2024 · 0 comments · May be fixed by #1722
Open

Allow @rollup/plugin-virtual to be a function that takes a module ID #1721

qzsiniong opened this issue May 23, 2024 · 0 comments · May be fixed by #1722

Comments

@qzsiniong
Copy link

  • Rollup Plugin Name: @rollup/plugin-virtual
  • Rollup Plugin Version: v3.0.2

Feature Use Case

Just like https://github.com/rollup/plugins/blob/master/packages/replace/CHANGELOG.md#120

// src/views/users/index.vue
import { routeName } from 'virtual:routeName';

// the routeName is base on current file, like src/views/users/index.vue ==> users/index

Feature Proposal

import virtual from '@rollup/plugin-virtual';

export default {
  input: 'src/entry.js',
  // ...
  plugins: [
    virtual({
      'virtual:routeName': (importer) => {
        const routeRoot = process.cwd() + '/src/views/';
        const routeName = importer.replace(routeRoot, '').replace(/\.\w+$/, '');

        return `export const routeName = '${routeName}'`;
      },
    }),
  ],
};
@qzsiniong qzsiniong linked a pull request May 23, 2024 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant