You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
1.5 KiB

import { defineConfig, loadEnv } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import path from 'path';
import { updateJsonFileField } from './tools/json-editor.js';
import { generatePackageJsonPlugin } from './tools/generate-package-plugin.js';
// https://vitejs.dev/config/
/**
* @param {String} mode development/production
*/
export default defineConfig(({ mode = 'development' }) =>{
const env = loadEnv(mode, './envs');
console.log('current mode:', mode);
const plugins = [ uni() ];
if (process.env.UNI_PLATFORM === 'mp-toutiao'){
// 根据配置文件配置 appid
const manifestPath = path.resolve(__dirname, 'src/manifest.json');
updateJsonFileField(manifestPath, ['mp-toutiao', 'appid'], env.VITE_TOUTIAO_APPID);
// 配置行业sdk
plugins.push(generatePackageJsonPlugin(process.env.UNI_OUTPUT_DIR, { industrySDK: true }));
}
return {
plugins,
define: {
// 抖音小程序不支持该参数 __VUE_OPTIONS_API__
// 会导致 [TMA] TypeError: this.$vm.$callCreatedHook is not a function
// "__VUE_OPTIONS_API__": false,
__API__: JSON.stringify(env.VITE_API_BASE),
},
// 修复控制台出现 Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0 的问题
css: {
preprocessorOptions: {
scss: {
silenceDeprecations: ['legacy-js-api']
}
}
}
}
})