别名或替换外部模块不起作用
Aliasing or replacing external modules doesn't work
我有以下汇总配置:
import alias from '@rollup/plugin-alias';
import replacement from 'rollup-plugin-module-replacement';
/* ... */
export default {
input: 'src/index.ts',
output: {
file: 'lib/index.js',
format: 'amd',
exports: 'named',
intro: 'var global = window;',
name: this.options.name,
},
external: ['axios'],
plugins: [
// both don't work as expected with external declared above
alias({
entries: [
{ find: 'axios', replacement: 'cdn/axios' },
],
}),
replacement({
entries: [
{ find: 'axios', replacement: 'cdn/axios' },
],
}),
nodeResolve(/* ... */),
commonjs(/* ... */),
typescript(/* ... */),
],
};
这会产生以下代码:
define(['exports', 'axios'], function (exports, axios) { 'use strict'; // ...
但我期待:
define(['exports', 'cdn/axios'], function (exports, axios) { 'use strict'; // ...
有没有办法重命名上层范围定义中的那些模块?
谢谢。
我刚刚使用了 output.paths 属性,它可以正常工作。
我有以下汇总配置:
import alias from '@rollup/plugin-alias';
import replacement from 'rollup-plugin-module-replacement';
/* ... */
export default {
input: 'src/index.ts',
output: {
file: 'lib/index.js',
format: 'amd',
exports: 'named',
intro: 'var global = window;',
name: this.options.name,
},
external: ['axios'],
plugins: [
// both don't work as expected with external declared above
alias({
entries: [
{ find: 'axios', replacement: 'cdn/axios' },
],
}),
replacement({
entries: [
{ find: 'axios', replacement: 'cdn/axios' },
],
}),
nodeResolve(/* ... */),
commonjs(/* ... */),
typescript(/* ... */),
],
};
这会产生以下代码:
define(['exports', 'axios'], function (exports, axios) { 'use strict'; // ...
但我期待:
define(['exports', 'cdn/axios'], function (exports, axios) { 'use strict'; // ...
有没有办法重命名上层范围定义中的那些模块?
谢谢。
我刚刚使用了 output.paths 属性,它可以正常工作。