Fork of rollup-plugin-hypothetical.
Generate code for imported modules, specifying paths as strings or regexes.
- Supports regex paths
- Supports returning generator functions instead of strings for paths
- Removes most other functionality for simplicity
Only has one option.
Map(path<string | RegExp>, code_generator<string | Function>)
// vite.config.js:
// ...
plugins: [
code_generator({
paths: new Map([
[
'@constants', // A string path will exactly match a particular import path
`
export default {
NumberOfLlamas: 6,
}
`
],
[
/^@components\//, // A regex path can be used to match any matching path
id => { // Instead of a string, your code can be output by a function,
const name = id.match(/([^/]+)$/)[1]
return `
import ${name} from '/src/components/${name}.jsx'
export default ${name}
`
},
],
]),
}),
],
// ...