rollup-plugin-includepaths rollup插件管理

本文介绍如何使用rollup-plugin-includepaths插件来管理rollup中的相对导入路径。通过设置配置,你可以从指定的源路径中查找文件,并支持自定义模块路径,以优化打包过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

rollup-plugin-includepaths
从npm中查看使用方式
Let you use relative paths in your import directives, like this:

// from src/lib/one/foo.js
import { Foo } from ‘one/foo’;

// from src/other/two/bar.js
import { Bar } from ‘two/bar’;

Setup
In your rollup configuration file:

import includePaths from ‘rollup-plugin-includepaths’;

let includePathOptions = {
include: {},
paths: [‘src/lib’, ‘src/other’],
external: [],
extensions: [’.js’, ‘.json’, ‘.html’]
};

export default {
entry: ‘./app.js’,
format: ‘cjs’,
dest: ‘public/app.min.js’,
plugins: [ includePaths(includePathOptions) ],
};

Options:
paths = [’’]
An array of source paths in your project where the plugin should look for files

Example: [‘src/lib’, ‘src/foo’]

By default, resolve files from working dir

include
A map of module=>path/to/file.js with custom module paths. Used to override the search with a static path (like Browserify does with the “browser” config).

Use this option if you want to skip the file resolution and directly resolve a module name to a given path.

Example:

include: {
// Import example: import angular from ‘angular’;
‘angular’: ‘bower_components/angular/angular.js’
}
external
An array of module names that should be excluded from the bundle (external modules).

By default, all the node built-in modules will be marked as external.

To include the built-ins, you can use the builtins plugin and set this config to an empty array.

Example:

// will not include the module ‘angular’ in the final bundle
external: [‘angular’]
extensions
An array of file extensions to look for in the project.

Default: [’.js’, ‘.json’]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值