web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
10.03k stars 573 forks source link

[Feature]: module-import Support setting aliases #8326

Open lzxb opened 2 weeks ago

lzxb commented 2 weeks ago

What problem does this feature solve?

I am designing an ESM (ECMAScript Module) module linking with the intention of exporting multiple packages within a single file to reduce HTTP requests. When importing, aliases will be specified.

What does the proposed API of configuration look like?

Consolidate export files.

ssr-base/vue.ts

import * as vue from 'vue';
import * as vueClassSetup from 'vue-class-setup';

export { vue, vueClassSetup }

rspack.config.js


module.exports = {
  externalsType: 'module-import',
  externals: {
   vue: ['ssr-base/vue', 'vue'],
  'vue-class-setup': ['ssr-base/vue', 'vueClassSetup']
  }
};
moonsky-all commented 2 weeks ago

我遇到过一个相似的问题,直接定义一个vue别名解决了,不知道是不是你说的意思

// rsbuild.config.js
export default defineConfig({
  // ..
  source: {
    alias: {
      '@': resolve('src'),
      'vue': resolve('node_modules/vue/dist/vue.runtime.esm-bundler.js'),
    },
  },
  // ..
});
lzxb commented 2 weeks ago

Thank you for your reply. You were referring to an alias, but I was referring to external expansion