File generated on project initialization

The initial code:

/** @typedef {import("@tuya-sat/micro-script").DebuggerConfig} DebuggerConfig */
/** @typedef {import("@tuya-sat/micro-script").WebpackCombineFunction} WebpackCombineFunction */
/** @typedef {import("@tuya-sat/micro-script").CustomDevServer} CustomDevServer */
module.exports = {
/**@type {DebuggerConfig} */
debuggerConfig: {
target: 'xxx', // Proxy protocol+host are required.
username: 'xxxx', // The admin account of the created SaaS.
password: 'xxx', // The password of the admin account.
logSign: true, // Print the request header.
mockPermissions: ['EDIT', 'DELETE'],
},
/**@type {WebpackCombineFunction} */
webpack(config, { isDev, isBuild }) {
config.output.publicPath = isDev ? '/' : './';
return config;
},
/**@type {CustomDevServer} */
devServer(config) {
return config;
},
};

module.exports is made up of debuggerConfig, webpack, and devServer. The following sections detail the three parts.

debuggerConfig

Type

interface debuggerConfig {
target: string;
username: string;
password: string;
csrf?: boolean;
loginApi?: string;
isMainApp?: boolean;
logSign?: boolean;
mockPermissions?: string[];
base?: string;
additionHeaders?: {
[key: string]: any;
};
needProxyApi?: string[];
themeConfig?: {
primaryColor: string;
};
}

target

Set the value to the URL of the SaaS for debugging. The protocol and host must be entered.

username

Set the value to the admin account of the created SaaS.

password

Set the value to the password of the admin account.

csrf

Specifies whether to support csrf, defaulting to true.

loginApi

The URL to the login API, defaulting to /api/login.

isMainApp

Specifies whether this micro application is the main application, defaulting to false.

logSign

Specifies whether to print the request header, defaulting to false.

mockPermission

The mocked permissions.

base (Not common)

The CDN URL to the main application of the SaaS.

additionHeaders

An additional request header, defaulting to terminalId: os.hostname().

needProxyApi

The matching rule for API proxy, defaulting to ["/api", "/open-api", "/custom-api"].

webpack

module.exports = {
/**@type {WebpackCombineFunction} */
webpack(config, { isDev, isBuild }) {
config.output.publicPath = isDev ? '/' : './';
return config;
},
};

Add custom configuration using webpack functions. config is the default Webpack configuration. isDev is for development. isBuild is for production. isDev and isBuild are mutually exclusive. For semantics purposes, these two variables are exposed. The return value is the last Webpack configuration.

devServer

module.exports = {
devServer(config) {
return config;
},
};

Custom configuration for webpack-dev-server. The return value is the last configuration.