Skip to content

Commit

Permalink
feat: support alias config
Browse files Browse the repository at this point in the history
基于 @rollup/plugin-alias 支持路径别名配置项
  • Loading branch information
billfeller committed May 21, 2021
1 parent 1140590 commit 4d6b121
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,26 @@ export default {
}
```

### alias

配置需要替换的别名路径,基于 [@rollup/plugin-alias](https://github.com/rollup/plugins/tree/master/packages/alias#readme)

- Type: `Object`
- Default: `{}`

比如:

```js
import path from 'path';

// dumi 中引入别名路径
export default {
alias: {
entries: [{ find: '@', replacement: path.join(__dirname, 'src') }],
},
};
```

#### inject

配置需要替换成依赖引用的全局变量 Map,基于 [rollup-plugin-inject](https://github.com/rollup/rollup-plugin-inject)
Expand Down
1 change: 1 addition & 0 deletions packages/father-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@babel/preset-typescript": "7.12.1",
"@babel/register": "7.12.1",
"@lerna/project": "^3.21.0",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-babel": "5.2.1",
"@rollup/plugin-commonjs": "16.0.0",
"@rollup/plugin-inject": "4.0.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/father-build/src/getRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import inject, { RollupInjectOptions } from '@rollup/plugin-inject';
import babel, { RollupBabelInputPluginOptions } from '@rollup/plugin-babel';
import alias, { RollupAliasOptions } from '@rollup/plugin-alias';
import postcss from 'rollup-plugin-postcss';
import { terser } from 'rollup-plugin-terser';
import typescript2 from 'rollup-plugin-typescript2';
Expand Down Expand Up @@ -54,6 +55,7 @@ export default function(opts: IGetRollupConfigOpts): RollupOptions[] {
runtimeHelpers: runtimeHelpersOpts,
replace: replaceOpts,
inject: injectOpts,
alias: aliasOpts,
extraExternals = [],
externalsExclude = [],
nodeVersion,
Expand Down Expand Up @@ -147,6 +149,8 @@ export default function(opts: IGetRollupConfigOpts): RollupOptions[] {
function getPlugins(opts = {} as { minCSS: boolean; }) {
const { minCSS } = opts;
return [
// @see https://github.com/umijs/father/issues/356
...(aliasOpts ? [alias(aliasOpts as RollupAliasOptions)] : []),
url(),
svgr(),
postcss({
Expand Down
3 changes: 3 additions & 0 deletions packages/father-build/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export default {
inject: {
type: 'object',
},
alias: {
type: 'object',
},
lessInRollupMode: {
type: 'object'
},
Expand Down
1 change: 1 addition & 0 deletions packages/father-build/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface IBundleOptions {
extractCSS?: boolean;
injectCSS?: boolean | ((varname: string, filename: string) => string);
inject?: Object;
alias?: Object;
autoprefixer?: Object;
include?: string | RegExp;
runtimeHelpers?: boolean;
Expand Down
12 changes: 12 additions & 0 deletions packages/father-build/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,13 @@
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==

"@rollup/plugin-alias@^3.1.2":
version "3.1.2"
resolved "https://mirrors.tencent.com/npm/@rollup%2fplugin-alias/-/plugin-alias-3.1.2.tgz#c585b05be4a7782d269c69d13def56f44e417772"
integrity sha512-wzDnQ6v7CcoRzS0qVwFPrFdYA4Qlr+ookA217Y2Z3DPZE1R8jrFNM3jvGgOf6o6DMjbnQIn5lCIJgHPe1Bt3uw==
dependencies:
slash "^3.0.0"

"@rollup/[email protected]":
version "5.2.1"
resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-5.2.1.tgz#20fc8f8864dc0eaa1c5578408459606808f72924"
Expand Down Expand Up @@ -5618,6 +5625,11 @@ slash@^2.0.0:
resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44"
integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==

slash@^3.0.0:
version "3.0.0"
resolved "http://mirrors.tencent.com/npm/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==

snapdragon-node@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"
Expand Down

0 comments on commit 4d6b121

Please sign in to comment.