Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: support multiple output with different umdNames #579

Closed
ZhangTaibin opened this issue Dec 19, 2024 · 2 comments
Closed

[Feature]: support multiple output with different umdNames #579

ZhangTaibin opened this issue Dec 19, 2024 · 2 comments

Comments

@ZhangTaibin
Copy link

What problem does this feature solve?

I get multiple output through this options:

import { defineConfig } from '@rslib/core';

export default defineConfig({
  source: {
    entry: {
      "component-1": "./src/component-1/index.js",
      "component-2": "./src/component-2/index.js",
    }
  },

  lib: [
    {
      format: 'umd',
      umdName: 'MyLibrary',
    },
  ],

  output: {
    target: 'web',
    filename: {
      js: '[name]/index.[contenthash:8].js',
    }
  },
});

It will get dist/component-1/index.jsdist/component-2/index.js . But they use a same umdName MyLibrary.

I hope Rslib can support buding multiple output with different umdNames.

Like outputs dist/component-1/index.js with umdName component__1 and dist/component-2/index.js with umdName component__2

Thanks.

What does the proposed API look like?

lib.umdName can support function to map the entry so that i can tell which output use what name:

import { defineConfig } from '@rslib/core';

export default defineConfig({
  source: {
    entry: {
      "component-1": "./src/component-1/index.js",
      "component-2": "./src/component-2/index.js",
    }
  },

  lib: [
    {
      format: 'umd',
      umdName({ entryName }) {
        const maps = {
          "component-1": "component__1",
          "component-2": "component__2",
        }
        return maps[entryName]
      }
    },
  ],
});

or

support array config so that i can decide the output. Like this Rollup options:

import { defineConfig } from 'rollup'

export default defineConfig([
    {
        input: 'src/component-1/index.js',
        output: [
            {
                name: 'component__1',
                file: 'dist/component-1/index.js',
                format: 'umd',
            },
        ],
    },
    {
        input: 'src/component-2/index.js',
        output: [
            {
                name: 'component__2',
                file: 'dist/component-2/index.js',
                format: 'umd',
            },

        ],
    },
])
@Timeless0911
Copy link
Contributor

You can write arrays in lib config.

import { defineConfig } from '@rslib/core';

export default defineConfig({
  lib: [
    {
      format: 'umd',
      umdName: 'MyLibrary1',
      source: {
        entry: {
          'component-1': './src/component-1/index.js',
        },
      },
    },
    {
      format: 'umd',
      umdName: 'MyLibrary2',
      source: {
        entry: {
          'component-2': './src/component-2/index.js',
        },
      },
    },
  ],

  output: {
    target: 'web',
    filename: {
      js: '[name]/index.[contenthash:8].js',
    },
  },
});

@ZhangTaibin
Copy link
Author

It's done. Thanks.

It was my fault, I didn't notice that the entry is also configurable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants