Rsbuild v0.2 发布

December 11, 2023

Rsbuild v0.2 版本包含一些 API 的不兼容更新,请参考当前文档进行升级。

Targets

我们将 createRsbuild 方法的 target 移动至 rsbuild 配置对象中,这个改动使用户可以在 Rsbuild 配置文件中配置 targets。

  • before:
const rsbuild = await createRsbuild({
  target: ['web', 'node'],
});
  • after:
// rsbuild.config.ts
export default {
  output: {
    targets: ['web', 'node'],
  },
};

仅影响 JavaScript API。使用 Rsbuild CLI 的用户不需要做任何改变。

Entry

删除已弃用的 source.entries 配置。

自 Rsbuild v0.1.0 起,source.entries 已更名为 source.entry,我们在 Rsbuild v0.2.0中删除了source.entries` 配置。

  • before:
// rsbuild.config.ts
export default {
  source: {
    entries: {},
  },
};
  • after:
// rsbuild.config.ts
export default {
  source: {
    entry: {},
  },
};

Write to Disk

dev.writeToDisk 的默认值变更为 false.

原因:

  • 减少文件系统开销,提升开发服务器性能。
  • 避免触发 UnoCSS 和其他工具的监听器。参考:#654
  • 使默认行为与 webpack-dev-middleware 及其他社区开发服务器保持一致。

用户可以手动开启写入磁盘:

export default {
  dev: {
    writeToDisk: true,
  },
};

Babel 插件

@rsbuild/plugin-babel 将所有的 babel-loader 选项移动到 babelLoaderOptions:

  • before:
pluginBabel({
  plugins: [],
  presets: [],
});
  • after:
pluginBabel([
  babelLoaderOptions: {
    plugins: [],
    presets: [],
  }
]);

这种改变使我们能为 pluginBabel 添加更多选项,如 includeexclude

Source Map

output.disableSourceMap 已经更名为 output.sourceMap.

  • before:
export default {
  output: {
    disableSourceMap: {
      js: true,
      css: true,
    },
  },
};
  • after:
export default {
  output: {
    sourceMap: {
      js: false,
      css: false,
    },
  },
};

source map 的默认值已更新,以提升构建性能。

  • 之前:在开发阶段生成 JS / CSS 的 source map,在生产阶段生成 JS 的 source map。
  • 之后:在开发阶段生成 JS 的 source map,在生产阶段不生成 source map。

Inject Styles

output.disableCssExtract 更名为 output.injectStyles 以更加直观:

  • before:
export default {
  output: {
    disableCssExtract: true,
  },
};
  • after:
export default {
  output: {
    injectStyles: true,
  },
};