重命名扩展插件
从 RollUp 取出模块并重命名其文件扩展名的滚动插件 。 用于使用时 preserveModules。插件也将解析
所有模块代码和重写导入/导出以匹配新文件名.
安装
npm i --save-dev @betit/rollup-plugin-rename-extensions
使用量
例如,我们如何转换 .ts .vue 改为 .js 财务报告和审定财务报表 .vue.js 页:1.
import renameExtensions from '@betit/rollup-plugin-rename-extensions';
// Rollup Configuration
export default {
input: './src/index.js',
preserveModules: true,
/* ... */
plugins: [
// After transforms...
renameExtensions({
include: ['**/*.ts', '**/*.vue'],
mappings: {
'.vue': '.vue.js',
'.ts': '.js',
},
})
],
},
选项
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;
/**
* 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>;
}