import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
const settings = require('./src/settings');
const path = require('path');
const Timestamp = new Date().getTime();

export default defineConfig((mode) => {
	const env = loadEnv(mode, process.cwd());
	return {
		publicPath: './',
		outputDir: 'dist',
		assetsDir: 'static',
		runtimeCompiler: true,
		css: {
			requireModuleExtension: true,
			sourceMap: env.VITE_APP_NODE_ENV == 'development' ? true : false,
		},

		name: settings.title,
		resolve: {
			extensions: ['.js', '.vue', '.json'],
			alias: {
				'@': path.resolve(__dirname, './src'),
			},
		},
		// webPreferences: {
		//   nodeIntegration: true,
		//   contextIsolation:false  //  把这一项加上错误就会消失
		// },
		plugins: [vue()],
		output: {
			// 输出重构  打包编译后的 文件名称  【模块名称.版本号.时间戳】
			filename: `js/[name].${Timestamp}.js`,
			chunkFilename: `js/[name].${Timestamp}.js`,
		},
		server: {
			host: '0.0.0.0', //ip地址
			port: 8080, //端口号
			open: false, //启动后是否自动打开浏览器
		},
	};
});
