import {
	defineConfig
} from 'vite'
import uni from '@dcloudio/vite-plugin-uni'

// @yck-web/vite-plugin-template-inset
const htmlPlugin_ciy = () => {
	return {
		name: 'html-transform',
		transform(code, path) {
			if (path.substring(path.length - 4) == '.vue' && path.indexOf('/pages/') > -1) {
				// :background-text-style="meta.theme"
				let pft = '<page-meta :root-background-color="meta.bgcolor" :background-color="meta.bgcolor" :background-color-top="meta.bgcolor" :background-color-bottom="meta.bgcolor" :page-style="meta.style" :root-font-size="meta.fontsize" :page-font-size="meta.fontsize" :enable-pull-down-refresh="meta.pulldown"></page-meta>'; //'<page-meta :background-text-style="meta.theme" :root-background-color="meta.bgcolor" :background-color="meta.bgcolor" :background-color-top="meta.bgcolor" :background-color-bottom="meta.bgcolor" :page-style="meta.style" :root-font-size="meta.fontsize" :page-font-size="meta.fontsize" :enable-pull-down-refresh="meta.pulldown"></page-meta>';
				pft += '<view :class="pageclass">';
				pft += '<ciy-auth ref="auth"></ciy-auth>'; //暂时只做微信生态
				pft += '<ciy-alert ref="alert"></ciy-alert>';
				pft += '<ciy-toast ref="toast"></ciy-toast>';
				pft += '<ciy-popmenu ref="popmenu"></ciy-popmenu>';

				let pfb = '</view>';
				code = code.replace('<template>', '<template>' + pft);
				let idx = code.lastIndexOf('</template>');
				code = code.slice(0, idx) + pfb + code.slice(idx);
				console.log('CiyPlugin:', path);
			}
			return code;
		},
	}
}
export default defineConfig({
	plugins: [htmlPlugin_ciy(), uni()],
	resolve: {
		alias: {
		},
	},
	css: {
		preprocessorOptions: {
			// 设置scss全局变量
			scss: {},
		},
	},
	server: {},
})