@vdustr/rollup-plugin-rename-extensions
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

This is forked from @betit/rollup-plugin-rename-extensions with additional option match.

Rename Extensions Plugin

Rollup plugin to take modules from RollUp and rename their file extensions. Useful for when using preserveModules. The plugin will also parse all modules code and rewrite imports/exports to match the new file name.

Installation

npm i --save-dev @vdustr/rollup-plugin-rename-extensions

Usage

As an example, heres how we can convert .ts .vue to .js and .vue.js respectively.

import renameExtensions from '@vdustr/rollup-plugin-rename-extensions';

// Rollup Configuration
export default {
    input: './src/index.js',
    preserveModules: true,
    /* ... */
    plugins: [
        // After transforms...
        renameExtensions({
            include: ['**/*.ts', '**/*.vue'],
            match: "\0tslib.js",
            mappings: {
                '.vue': '.vue.js',
                '.ts': '.js',
            },
        })
    ],
},

Options

export interface IRenameExtensionsOptions {
  /**
   * Files to include for potential renames.
   * Also denotes files of which may import a renamed module in
   * order to update their imports.
   */
  include?: Array<string | RegExp> | string | RegExp | null;

  /**
   * Files to explicitly exclude
   */
  exclude?: Array<string | RegExp> | string | RegExp | null;

  /**
   * Strictly equaled string or regular expression to match.
   * The `exclude` option doesn't effect this option.
   * It's for virtual bundles mainly. For example: "\0tslib.js"
   */
  match?: Array<string | RegExp> | string | RegExp | null;

  /**
   * Generate source maps for the transformations.
   */
  sourceMap?: boolean;

  /**
   * Babel plugins to use for parsing. Defaults to:
   * `dynamicImport`, `classProperties`, `objectRestSpread`
   *
   * For a full list visit https://babeljs.io/docs/en/babel-parser#plugins
   */
  parserPlugins?: ParserPlugin[];

  /**
   * Object describing the transformations to use.
   * IE. Input Extension => Output Extensions.
   * Extensions should include the dot for both input and output.
   */
  mappings: Record<string, string>;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @vdustr/rollup-plugin-rename-extensions

Weekly Downloads

6

Version

0.1.1

License

MIT

Unpacked Size

22.7 kB

Total Files

6

Last publish

Collaborators

  • vdustr