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

[ice-pkg 插件开发] modifyUserConfig 不符合预期 #626

Open
fyangstudio opened this issue Dec 22, 2023 · 2 comments
Open

[ice-pkg 插件开发] modifyUserConfig 不符合预期 #626

fyangstudio opened this issue Dec 22, 2023 · 2 comments

Comments

@fyangstudio
Copy link
Contributor

通过 modifyUserConfig 修改 用户配置 ,和直接配置后的 构建产物不同。

方式一 直接配置:

// build.config.mts

import { defineConfig } from "@ice/pkg";

// https://pkg.ice.work/reference/config/
export default defineConfig({
  transform: {
    formats: ["es2017"],
  },
  bundle: {
    polyfill: false,
    formats: ["es2017"],
  },
});

方式二 通过插件修改配置:

// build.config.mts

import { defineConfig } from "@ice/pkg";

// https://pkg.ice.work/reference/config/
export default defineConfig({
  plugins: ["./plugin.mjs"],
});
// ./plugin.mjs
/**
 * @type {import('@ice/pkg').Plugin}
 */
const plugin = (api, options) => {
  const { modifyUserConfig } = api;
  modifyUserConfig("transform", {
    formats: ["es2017"],
  });
  modifyUserConfig("bundle", {
    polyfill: false,
    formats: ["es2017"],
  });
};

export default plugin;

方式一和方式二 构建产物不同,方式二 多构建了 esm 目录产物

@luhc228
Copy link
Member

luhc228 commented Dec 24, 2023

(userConfig.transform?.formats || ['esm', 'es2017']).forEach((format) => {

目前的逻辑是,一个 transform.format 对应一个 task。

上面是内置插件会在最前面运行,注册 task 的逻辑先执行,并且依赖 transform.formats。自定义插件通过 modifyUserConfig 没办法修改已注册的 task

@luhc228
Copy link
Member

luhc228 commented Dec 24, 2023

我认为这个后面要重构掉,具体的方案要讨论下。

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

No branches or pull requests

2 participants