2.4.0 • Published 2 years ago

@xyh19/rollup-plugin-glob-import v2.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

🏠 @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!

2.4.0

2 years ago

2.3.1

2 years ago

2.3.0

2 years ago

2.2.5

2 years ago

2.2.4

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago