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
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;};}
Set the value to the URL of the SaaS for debugging. The protocol and host must be entered.
Set the value to the admin account of the created SaaS.
Set the value to the password of the admin account.
Specifies whether to support csrf
, defaulting to true
.
The URL to the login API, defaulting to /api/login
.
Specifies whether this micro application is the main application, defaulting to false
.
Specifies whether to print the request header, defaulting to false
.
The mocked permissions.
The CDN URL to the main application of the SaaS.
An additional request header, defaulting to terminalId: os.hostname()
.
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.