@canva/app-scripts

中文文档
1.2.0发布于 2026/11/09SEE LICENSE IN LICENSE.mdTypeScriptESM + CJS近 30 天下载 4.1万

Build scripts and bundler configuration for Canva Apps

原始使用文档
文档目录19 节
  1. Installation
  2. Configuration
  3. Basic Configuration
  4. Bundler Selection
  5. Customizing the Bundler
  6. Backend
  7. Dev Server
  8. Translations
  9. Environment Variables
  10. Configuration precedence
  11. Design Philosophy
  12. CLI Commands
  13. dev
  14. build
  15. extract-translations
  16. Global CLI options
  17. Changelog
  18. Contributing
  19. License

@canva/app-scripts

Build scripts for Canva Apps.

@canva/app-scripts is designed to be used through the Canva CLI: canva apps start and canva apps build are the recommended way to run and build your app. Prefer working with the package directly? Its own CLI commands and programmatic API are there for you too.

Installation

npm install -D @canva/app-scripts

Have a Canva App that isn't using @canva/app-scripts yet? You probably have a webpack.config.ts and a scripts/start/ runner at its root - see the migration guide to make the switch.

Configuration

Create an optional canva-app.config.ts file in your project root to override defaults (.js, .mjs, .cjs, .mts, and .cts are also supported; TypeScript is recommended):

Basic Configuration

import { defineConfig } from "@canva/app-scripts";

export default defineConfig({
  entry: "./src/index.tsx",
});

Bundler Selection

By default, @canva/app-scripts uses Rsbuild as the bundler. You can explicitly select a bundler:

import { defineConfig } from "@canva/app-scripts";

export default defineConfig({
  bundler: "rsbuild", // Default, can be omitted
  entry: "./src/index.tsx",
});

Bundler support:

  • rsbuild - Default bundler
  • webpack - Supported alternative

Customizing the Bundler

Use the config function to customize the underlying bundler configuration. The callback is typed per bundler, so bundler and config travel together, and the configuration types are sourced from the respective bundler's own package (@rsbuild/core, webpack).

Rsbuild (default)

import { defineConfig } from "@canva/app-scripts";
import type { RsbuildContext } from "@canva/app-scripts";
import type { RsbuildConfig } from "@rsbuild/core";

export default defineConfig({
  config: (rsbuildConfig: RsbuildConfig, { mode }: RsbuildContext) => {
    // Disable source maps for production builds
    if (mode === "production") {
      rsbuildConfig.output = { ...rsbuildConfig.output, sourceMap: false };
    }
    return rsbuildConfig;
  },
});

webpack

import { defineConfig } from "@canva/app-scripts";
import type { WebpackContext } from "@canva/app-scripts";
import type { Configuration } from "webpack";
import path from "path";

export default defineConfig({
  bundler: "webpack",
  config: (webpackConfig: Configuration, { mode }: WebpackContext) => {
    // Add SVG loader - import SVGs as React components
    webpackConfig.module?.rules?.push({
      test: /\.svg$/,
      issuer: /\.[jt]sx?$/,
      use: [
        {
          loader: "@svgr/webpack",
          options: {
            svgoConfig: {
              plugins: [{ name: "removeViewBox", active: false }],
            },
          },
        },
      ],
    });

    // Add path aliases for cleaner imports
    webpackConfig.resolve = {
      ...webpackConfig.resolve,
      alias: {
        ...webpackConfig.resolve?.alias,
        "@components": path.resolve(__dirname, "src/components"),
        "@assets": path.resolve(__dirname, "src/assets"),
      },
    };

    // Enhanced source maps for development
    if (mode === "development") {
      webpackConfig.devtool = "eval-source-map";
    }

    return webpackConfig;
  },
});

Note: Custom loaders like @svgr/webpack must be installed separately:

npm install --save-dev @svgr/webpack

The config function receives:

  • The base bundler configuration (RsbuildConfig from @rsbuild/core, or Configuration from webpack)
  • context - Build context with mode ("development" or "production")

Backend

If your app has a backend, set backend to run it alongside the dev server. It runs under nodemon with TypeScript support, and a backend crash tears the dev server down. Any backend config (even {}) enables it.

import { defineConfig } from "@canva/app-scripts";

export default defineConfig({
  entry: "./src/index.tsx",
  backend: true, // runs backend/server.ts
});

Pass an object to override the defaults:

OptionDescriptionDefault
entryBackend entry, relative to the project root.backend/server.ts
portPort the backend listens on. Falls back to CANVA_BACKEND_PORT.3001
hostBackend host the built app calls. Falls back to CANVA_BACKEND_HOST.—
tunnelExpose the backend through a public HTTPS tunnel. Overridden by --tunnel.false
export default defineConfig({
  backend: { entry: "./api/main.ts", port: 3100 },
});

Dev Server

Optional dev-server options. CLI flags and environment variables override these at run time.

OptionDescriptionDefault
portFrontend dev-server port. Overridden by --override-frontend-port.8080
httpsServe the frontend over HTTPS. Overridden by --use-https.false
export default defineConfig({
  devServer: { port: 9000, https: true },
});

Translations

Optional configuration for extract-translations.

OptionDescriptionDefault
outputDirDirectory to write extracted messages into.dist
outputFileOutput filename (no directory segments).messages_en.json
patternGlob for source files to scan.src/**/*.{ts,tsx}
export default defineConfig({
  extractTranslations: { outputDir: "i18n", pattern: "app/**/*.tsx" },
});

Environment Variables

These environment variables are supported but optional. Most can also be configured in canva-app.config.ts (recommended); some remain env-only.

VariableDescriptionWhen needed
CANVA_FRONTEND_PORTDev server port (default 8080). Overrides devServer.port.Optional — prefer devServer.port
CANVA_BACKEND_PORTBackend server port (default 3001). Overrides backend.port.Optional — prefer backend.port
CANVA_BACKEND_HOSTBackend URL the built app calls. Overrides backend.host.Optional — prefer backend.host
CANVA_HMR_ENABLEDEnable Hot Module Replacement (true/false).Optional
CANVA_APP_ORIGINApp origin URL.Required for HMR
CANVA_APP_IDCanva app ID.Required when running a backend
NGROK_AUTHTOKENngrok authtoken.Required when using --tunnel

Configuration precedence

When an option can be set in more than one place, highest priority wins: CLI flag > environment variable > canva-app.config.ts > package default. Not every option exists in every channel; the CLI prints a Warn: when an env var shadows a config value.

Design Philosophy

The public defineConfig() API is intentionally minimal:

  • entry, rootDir, and outputDir - Essential app configuration
  • bundler - Select the build tool (Rsbuild by default, webpack also supported)
  • devServer - Dev-server options (port, HTTPS)
  • backend - Run a backend alongside the dev server
  • extractTranslations - i18n extraction options
  • config - Escape hatch for full bundler customization

Every option is overridable at run time via CLI flags and environment variables, so the config file holds what's stable to the project while the invocation controls the rest.

CLI Commands

The package provides a canva-app-scripts CLI with the following commands. The Canva CLI's canva apps start and canva apps build are the recommended way to run these; use canva-app-scripts directly if you'd rather not go through the Canva CLI.

dev

Start the development server. Serves the app from src/index.tsx.

npx canva-app-scripts dev

If a backend is configured (or --backend-entry is passed), the backend entry is run alongside the dev server under nodemon, with SSL certificate paths passed through to its environment. A backend crash tears the whole dev server down. See Backend for the config options.

npx canva-app-scripts dev --entry ./src/app.tsx
npx canva-app-scripts dev --backend-entry ./backend/server.ts

build

Build the app for production. Outputs to dist/ by default.

npx canva-app-scripts build
npx canva-app-scripts build --entry ./src/app.tsx --output-dir ./build

extract-translations

Extract i18n messages from your source files into dist/messages_en.json.

npx canva-app-scripts extract-translations
npx canva-app-scripts extract-translations --output-dir ./i18n --pattern "src/**/*.{ts,tsx}"
npx canva-app-scripts extract-translations --output-file messages.json

Global CLI options

  • --entry - Entry file for the app (overrides entry from the config; on dev and build)
  • --tunnel - Expose the backend through a public HTTPS tunnel (alias: --ngrok)
  • --use-https - Start local development server on HTTPS
  • --override-frontend-port - Override the frontend port
  • --backend-entry - Path to the backend entry script (overrides backend.entry from the config)

Changelog

See the CHANGELOG.md file.

Contributing

We're actively developing this package but are not currently accepting third-party contributions. If you'd like to request any changes or additions to the package, submit a feature request via the Canva Developers Community.

License

See the LICENSE.md file.

版本与发布记录

@canva/app-scripts 共发布 10 个版本,首次发布于 2026/07/08;过去 12 个月发布了 10 个版本。

版本发布日期距今
1.2.0latest2026/11/09今天
1.1.22026/10/011 个月前
1.1.12026/09/012 个月前
1.1.02026/08/202 个月前
1.0.02026/08/122 个月前
0.0.0-beta.52026/08/112 个月前

关于 @canva/app-scripts 的常见问题

@canva/app-scripts 是什么?

Build scripts and bundler configuration for Canva Apps

如何安装 @canva/app-scripts?

在项目目录运行 npm install @canva/app-scripts,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 canva-app-scripts,可以用 npx canva-app-scripts 直接运行。

@canva/app-scripts 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@canva/app-scripts 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@canva/app-scripts 需要什么版本的 Node.js?

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

@canva/app-scripts 可以商用吗?

@canva/app-scripts 使用 SEE LICENSE IN LICENSE.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@canva/app-scripts 的下载量有多少?

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

@canva/app-scripts 还在维护吗?

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