@atlassian/soy-loader

中文文档
5.3.14发布于 2026/08/11Apache-2.0CommonJS近 30 天下载 1736

Soy loader for webpack using the Atlassian Soy CLI compiler

原始使用文档
文档目录8 节
  1. Installation
  2. Usage example
  3. Options
  4. Recipes
  5. Using with *.properties webpack loader
  6. Using modularize
  7. Additional links
  8. Minimum requirements

@atlassian/soy-loader

node version webpack peer dependency version npm downloads

Compiles Soy Templates templates with @atlassian/soy-template-plugin-js package and allows to load them with webpack

Installation

You can install the library using NPM:

npm install @atlassian/soy-loader

or by Yarn:

yarn add @atlassian/soy-loader

Usage example

// webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.soy/,
        use: [
          {
            loader: '@atlassian/soy-loader',
            options: {
              // ... see Options below ...
            },
          },
        ],
      },
    ],
  },
};

Options

data <string> (optional)

Example: 'foo:bar,moo:goo'

Data to pass to the soy renderer (soy rendering only) in the form :,:

functions <string> (optional)

Example: '/foo/bar/path'

Locations of custom soy functions, usually a path to a *.jar file.

expose <boolean> (optional)

Default: true

Indicates whether the generated namespace should be exposed to the window or not. If not, the module must be required to call the templates.

modularize <boolean> (optional)

Default: false

Indicates whether to convert template calls and definitions to ES6 module imports and exports. Allows Webpack to track the chain of template calls, but assumes a naming convention that maps namespace strings to file paths. See [#Using-modularize](Using modularize) for details.

customModuleMap Map<string, string | boolean> (optional)

Example: { 'foo.bar.Template': 'foo/baz', 'moo.foo': false }

To be used with the modularize option. An object mapping namespaces to module names when using modularize. Explicit false ignores a module and leaves it as a global reference. Other falsy values fallback to default resolution handling.

modulePathResolver : <Function> (optional)

Example:

function customModulePathResolver(namespace, context) {
  return namespace.replace(/\./g, '/');
}

function customModuleRelativePathResolver(namespace, context) {
  return path.relative(context, namespace.replace(/\./g, '/'));
}

To be used with the modularize option. A function that takes a namespace [string], context [string], and outputs a module path when using modularize. You can read more about the value of context here: https://webpack.js.org/api/loaders/#thiscontext

Returning an explicit false ignores a module and leaves it as a global reference. Return other falsy or undefined values to fallback to default resolution handling.

Recipes

Using with *.properties webpack loader

This package can be used with the @atlassian/i18n-properties-loader when you run your code with webpack dev server:

// webpack.config.js
const myI18nFiles = [
  'foo/i18n/my-translation-file.properties',
  'foo/bar/i18n/my-other-translation-file.properties',
  'bar/i18n/some-translation-file.properties',
];

module.exports = {
  module: {
    rules: [
      {
        test: /\.soy/,
        use: [
          {
            loader: '@atlassian/i18n-properties-loader',
            options: {
              i18nFiles: myI18nFiles,
            },
          },

          {
            loader: '@atlassian/soy-loader',
          },
        ],
      },
    ],
  },
};

Using modularize

Modularize is a specialized case that can be used when your {namespace}s and Soy files are 1-to-1. It converts any external templates references to ES6 module imports (and conversely any defined templates become named exports from this module). This allows Webpack to trace dependencies between Soy files, rather than having to specify this manually.

By default, the camelCase namespace becomes the kebab-case, dot separators become directories, and .soy suffix is appended.

Example: The {namespace a.bCD} namespace is converted to import 'a/b-c-d.soy'; module path.

This can be overridden using the customModuleMap option for one-off exceptions, and/or the modulePathResolver function to change the naming scheme entirely. NOTE: the modules MUST be unique per namespace.

Currently, the AUI-provided namespaces are ignored and left as global variable references, and thus dependencies on AUI can't be tracked. If you want to handle this differently, check out the DEFAULT_MAPPINGS in the modular-soy.js file, and replace each false with a module name.

Minimum requirements

This plugin is compatible with:

  • webpack 4.0+ and 5.0+
  • Node 12+

版本与发布记录

@atlassian/soy-loader 共发布 28 个版本,首次发布于 2019/06/24;过去 12 个月发布了 1 个版本。

版本发布日期距今
5.3.14latest2026/08/112 个月前
5.3.132025/10/131.1 年前
5.3.122025/09/121.2 年前
5.3.112025/08/271.2 年前
5.3.102025/05/291.4 年前
0.0.0-test-release.22024/12/121.9 年前

其他发布通道:alpha → 4.3.0-alpha.0。

关于 @atlassian/soy-loader 的常见问题

@atlassian/soy-loader 是什么?

Soy loader for webpack using the Atlassian Soy CLI compiler

如何安装 @atlassian/soy-loader?

在项目目录运行 npm install @atlassian/soy-loader,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:webpack(^4.0.0 || ^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@atlassian/soy-loader 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/atlassian__soy-loader 是否存在。

@atlassian/soy-loader 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@atlassian/soy-loader 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@atlassian/soy-loader 可以商用吗?

@atlassian/soy-loader 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@atlassian/soy-loader 的下载量有多少?

根据 npm 官方下载统计,@atlassian/soy-loader 在 2026/10/07 – 2026/11/05 这 30 天内被下载 1,736 次,日均约 58 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@atlassian/soy-loader 还在维护吗?

最新版本 5.3.14 发布于 2026/08/11(2 个月前);至今共发布 28 个版本,其中过去 12 个月发布了 1 个;首次发布于 2019/06/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。