@xyh19/rollup-plugin-glob-import
v2.4.0
Published
A rollup-plugin to use glob-star.
Downloads
7
Maintainers
Readme
🏠 @xyh19/rollup-plugin-glob-import
install
npm install -D @xyh19/rollup-plugin-glob-import
# or
yarn add -D @xyh19/rollup-plugin-glob-import
Getting Started
Create a rollup.config.js
configuration file and import the plugin:
// rollup.config.js
import globImport from '@xyh19/rollup-plugin-glob-import'
import path from 'path'
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs',
},
plugins: [
globImport({
globConfigs: [
{
loader: 'default',
glob: 'src/components/*',
aliases: '~components',
dynamicImport: false,
moduleIdRenamer: (filename) => path.parse(filename).name,
moduleKeyRenamer: (filename) => path.parse(filename).name,
},
{
loader: 'vue-routes',
glob: 'src/page/**/*.vue',
aliases: '~routes',
moduleIdRenamer: (filename) => path.parse(filename).name,
moduleKeyRenamer: (filename) => path.parse(filename).name,
},
],
}),
],
}
Import virtual module:
// src/components/a.js
export default 'components-a';
// src/components/b.js
export default 'components-b';
// src/index.js
import * as components from '~components';
console.log(components) // { a: 'components-a', b: 'components-b'}
Options
globConfigs
Type: GlobConfig | GlobConfig[]
glob-import configs.
exclude
Type: string | string[]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore.
defaultLoader
Type: 'import' | 'default' | 'named' | 'namedModule' | 'mixed' | 'vue-routes' | 'react-routes' | Loader
A function generator for module export.
GlobConfig
aliases
Type: string | string[]
Default: null
Provide the virtual ID of the imported module.
glob
Type: string
Glob expression to import.
exclude
Type: string | string[]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore.
transform
Type: TransformHook
Show your support
Give a ⭐️ if this project helped you!