Skip to main content
These options control how MorJS compiles your mini-program source. All fields are set at the top level of your mor.config.ts config object (or within each array entry for multi-config exports).

Source and target

sourceType
string
default:"wechat"
The DSL used in your source files. MorJS auto-detects this by looking for .wxml (WeChat) or .axml (Alipay) template files. Only set this explicitly when both types of files exist in the same directory.Accepted values: wechat, alipay
target
string
The platform target for the compiled output. Defaults to the first registered target. Each target has a default output path under dist/.Accepted values: wechat, alipay, baidu, bytedance, qq, kuaishou, taobao, dingding, web
compileMode
string
default:"bundle"
Compilation strategy.
  • bundle — Full webpack bundling with npm package resolution. Produces a self-contained output with no node_modules.
  • transform — Source-only conversion. Dependencies are not bundled; useful for component library authors.
Accepted values: bundle, transform
compileType
string
default:"miniprogram"
The type of artifact to produce. Determines the root entry config file.
ValueEntry file
miniprogramapp.json
pluginplugin.json
subpackagesubpackage.json
componentcomponent.json
Accepted values: miniprogram, plugin, subpackage, component

Paths

srcPath
string
default:"./src"
Root directory of your source files.
srcPaths
string[]
Additional source root directories. Useful when source files are spread across multiple directories.
outputPath
string
Directory where compiled output is written. Defaults to dist/<target> when not set.
ignore
string[]
default:"[]"
Files and directories to exclude from compilation. All outputPath values are added to this list automatically.

Build mode

mode
string
default:"development"
Build mode. Mirrors webpack’s mode option. Affects tree-shaking, optimization, and source map defaults.Accepted values: production, development, none
watch
boolean
default:"false"
Enable file watch mode. MorJS rebuilds affected files when changes are detected.
autoClean
boolean
default:"false"
Delete the output directory before each build.
cache
boolean
Enable the webpack filesystem cache. Defaults to true in development mode and false in production mode.

Minification

minimize
boolean
Enable output minification. Automatically set to true when mode is production.
jsMinimizer
string | boolean
default:"true"
JavaScript minimizer to use when minimize is enabled.Accepted values: terser, esbuild, swc, true (use default), false (disable JS minification)
jsMinimizerOptions
object
Options passed directly to the chosen JS minimizer. The shape depends on which minimizer is selected.
cssMinimizer
string | boolean
default:"esbuild"
CSS minimizer to use when minimize is enabled.Accepted values: esbuild, csso, cssnano, cleancss, parcelcss, false (disable CSS minification)
cssMinimizerOptions
object
Options passed directly to the chosen CSS minimizer.
xmlMinimizer
boolean
Enable template (WXML/AXML) minification using html-terser.
xmlMinimizerOptions
object
Options passed to the XML minimizer.

Source maps

devtool
string | boolean
Source map generation strategy. Accepts any webpack devtool string value (for example, source-map, eval-cheap-source-map), or false to disable source maps entirely.

Aliases and defines

alias
Record<string, any>
default:"{}"
Module path aliases. These are passed to webpack’s resolve.alias option.
alias: {
  '@utils': './src/utils',
  '@components': './src/components'
}
define
Record<string, any>
default:"{}"
Global constants to inject into source code at compile time. Only effective in bundle mode.
define: {
  __VERSION__: JSON.stringify('1.0.0'),
  __DEV__: JSON.stringify(true)
}

File copying

copy
array
Files or directories to copy from source to output. Entries can be plain strings (file path relative to srcPath) or objects:
copy: [
  'static/images',
  {
    from: 'assets/fonts',
    to: 'fonts',
    force: true
  }
]
Object fields:
  • from (string) — Source path relative to srcPath or srcPaths.
  • to (string) — Destination path relative to outputPath.
  • context (string) — Optional base directory override.
  • force (boolean) — Overwrite existing files.
  • toType (string) — 'file' or 'dir'.
  • priority (number) — Copy order priority.
  • globOptions (object) — Glob matching options.
  • filter (function) — Custom filter (filePath: string) => boolean.

Node modules processing

processNodeModules
boolean | object
Whether to cross-compile components inside node_modules. By default, MorJS chooses automatically based on the target platform.Pass true to process all node_modules, or an object for fine-grained control:
processNodeModules: {
  include: [/my-component-lib/],
  exclude: [/exclude-this-lib/]
}
globalObject
string
Override the global object name for the target platform (wx for WeChat, my for Alipay, etc.). Each target sets a sensible default; rarely needs to be overridden.

Runtime injection

autoInjectRuntime
boolean | object
default:"true"
Automatically inject MorJS runtime wrappers at compile time. When true, all injection types are enabled based on platform defaults. When false, no runtime injection occurs.Use an object for granular control:
autoInjectRuntime: {
  app: true,        // wrap App({})
  page: true,       // wrap Page({})
  component: true,  // wrap Component({})
  behavior: true,   // wrap Behavior({})
  mixin: true,      // wrap Mixin({}) (Alipay source only)
  api: 'enhanced'   // global object replacement strategy
}
api accepted values: enhanced (replace global object + inject mor API shim), lite (simple global rename), minimal (replace function calls only), false (disable).

TypeScript compiler options

compilerOptions
object
default:"{}"
TypeScript compilation settings. These mirror standard tsconfig.json options.

Conditional compilation

conditionalCompile
object
default:"{}"
Configure compile-time conditional code inclusion.

Custom entries

customEntries
object
Override or extend the entry configuration. Useful when your entry config file is in a non-standard location, or when you need to compile extra pages or components that have no reference in app.json.
customEntries: {
  'app.json': './custom-app.json',
  pages: ['extra/page/index'],
  components: ['shared/button/index']
}

Phantom dependency detection

phantomDependency
boolean | object
default:"false"
Detect imports of packages that are not declared in package.json. Pass true to enable with default settings, or an object for configuration:
phantomDependency: {
  mode: 'warn',     // 'warn' | 'error'
  exclude: ['lodash', 'moment']  // packages to allow without declaration
}
  • mode: 'warn' — Log a warning for each phantom dependency.
  • mode: 'error' — Throw an error and fail the build.

Module sharing (subpackage federation)

shared
Array<string | Record<string, string>>
default:"[]"
Declare node_modules packages to expose for consumption by other configs in a multi-repo subpackage setup.
shared: ['react', '@my-org/common-utils']
consumes
Array<string | Record<string, string>>
default:"[]"
Declare node_modules packages to consume from a shared host instead of bundling locally.
consumes: ['react', '@my-org/common-utils']

App JSON script generation

generateAppJSONScript
boolean
default:"true"
Generate a mor.p.js script file used to update app.json content during integration. Disable this if you manage integration separately.

Bundle analysis

analyzer
boolean | object
Enable bundle analysis with webpack-bundle-analyzer. Pass true to use defaults, or an object to configure:
analyzer: {
  analyzerMode: 'server',    // 'server' | 'static' | 'json' | 'disabled'
  analyzerHost: '127.0.0.1',
  analyzerPort: 8888,
  reportFilename: 'report.html',
  defaultSizes: 'parsed',    // 'stat' | 'parsed' | 'gzip'
  openAnalyzer: true,
  generateStatsFile: false,
  statsFilename: 'stats.json',
  logLevel: 'info'           // 'info' | 'warn' | 'error' | 'silent'
}

Experimental features

experiments
object
Opt-in experimental features. These may change between minor versions.

webpack passthrough

externals
any
Passed directly to webpack’s externals configuration. Use to exclude specific packages from the bundle.
externalsType
string
Sets the default external type. Defaults vary by target; for web targets you may need to set this to 'window'.

Build docs developers (and LLMs) love