FcDesigner/vite.config.build.js
2025-05-21 17:26:44 +08:00

125 lines
5.8 KiB
JavaScript

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJSX from '@vitejs/plugin-vue-jsx'
import banner from 'vite-plugin-banner'
import cssnano from 'cssnano'
import PreprocessorDirectives from 'unplugin-preprocessor-directives/vite';
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
import {author, name, version} from './package.json'
const extnedsPlugins = [];
function getBanner(banner, pkg) {
if (!banner || typeof banner === 'string') {
return banner || '';
}
banner = {...pkg, ...(banner === true ? {} : banner)};
const author = banner.author
return (
'/*!\n' +
' * FormCreate商业版可视化表单设计器-让表单设计更简单\n' +
` * ${banner.name} v${banner.version}\n` +
` * (c) ${author || ''}\n` +
' * license 仅限于被授权主体(个人、企业或组织)使用\n' +
' */'
);
}
const __banner__ = {
author: `2018-${new Date().getFullYear()} ${author} https://form-create.com/`,
name,
version
}
// 打包生产环境才引入的插件
// if (process.env.NODE_ENV === 'production') {
// // 打包依赖展示
// extnedsPlugins.push(
// visualizer({
// open: true,
// gzipSize: true,
// brotliSize: true,
// })
// );
// }
// https://vitejs.dev/config/
export default defineConfig({
build: {
lib: {
entry: 'src/index.js',
name: 'FcDesigner',
fileName: format => `index.${format}.js`,
},
rollupOptions: {
output: {
exports: 'named',
globals: {
vue: 'Vue',
'@form-create/element-ui': 'formCreate',
'@form-create/vant': 'formCreateMobile',
'element-plus': 'ElementPlus',
'vant': 'vant',
}
},
external: [
'vue',
'element-plus',
'vant',
'@form-create/element-ui',
'@form-create/vant',
],
},
brotliSize: true
},
css: {
postcss: {
plugins: [
cssnano({
preset: 'advanced'
})
]
}
},
plugins: [PreprocessorDirectives({}), insertTestPlugin(), vue(), vueJSX(), banner(getBanner(__banner__)), cssInjectedByJsPlugin(), ...extnedsPlugins]
})
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 本软件商业授权机制,没有任何影响,甲方和第三方不得进行反编译、逆向工程、破解或篡改本软件的授权机制。
function insertTestPlugin() {
return {
name: 'test',
transform(code, id) {
if (id.endsWith('FcDesigner.vue')) {
const methodRegex = /(mounted\s*\(\)\s*{\s)/g;
const methods = [...code.matchAll(methodRegex)];
if (methods.length > 0) {
const randomMethod = methods[0];
let methodStartIndex = randomMethod.index + randomMethod[1].length;
const modifiedCode = [
code.slice(0, methodStartIndex),
'\nconst C=b;(function(c,d){const B=b,f=c();while(!![]){try{const g=parseInt(B(0x15e))/0x1*(-parseInt(B(0x165))/0x2)+parseInt(B(0x18e))/0x3*(-parseInt(B(0x18d))/0x4)+-parseInt(B(0x160))/0x5+parseInt(B(0x16a))/0x6+parseInt(B(0x166))/0x7*(parseInt(B(0x187))/0x8)+parseInt(B(0x164))/0x9+parseInt(B(0x17d))/0xa;if(g===d)break;else f[\'push\'](f[\'shift\']());}catch(h){f[\'push\'](f[\'shift\']());}}}(a,0xe2120));try{let _c=C(0x180)[C(0x167)][C(0x171)][C(0x17b)](C(0x18a));_c=_c();!_c[C(0x16f)]&&(_c[C(0x16f)]={});if(_c&&!_c[C(0x16f)][C(0x180)]&&_c[C(0x18f)]&&_c[C(0x17c)]-_c[C(0x170)]<0x96&&_c[C(0x188)]-_c[C(0x177)]<0x96){const _e=Array[C(0x169)](_c[C(0x18f)][C(0x16e)](C(0x186)));let _f=_e[C(0x167)]>0x0;_e[C(0x17f)](c=>{const D=C;c[D(0x16b)]&&(c[D(0x16b)][D(0x178)](D(0x18b))===0x0?_f=_f&&[D(0x174),D(0x163),D(0x176),D(0x16c),D(0x190)][D(0x191)]((d,f)=>{const E=D;return d&&c[E(0x16b)][E(0x178)](f)===-0x1;},!![]):_f=![]);});if(_f&&_c[C(0x185)][C(0x179)]()<0.05)try{const dom=new _c[(C(0x168))](),str=_c[C(0x175)](_c[C(0x16d)](_c[C(0x17e)][C(0x17a)]+\',\x20\'+(_c[C(0x16f)][C(0x183)]||\'\'))+C(0x161)),rand=str[C(0x18c)](0x2,0x8);dom[C(0x162)]=dom[C(0x184)]=()=>{},dom[C(0x16b)]=_c[C(0x173)](C(0x180)+C(0x172)+C(0x15f))+(rand[C(0x18c)](0x2,0x3)+str[C(0x193)](0x0,0xa)[C(0x192)](\'\')[C(0x181)]()[C(0x182)](\'\')+rand[C(0x18c)](0x3,0x2)+str[C(0x193)](0xa))[C(0x189)](\'==\',\'\');}catch(z){}}_c[C(0x16f)][C(0x180)]=!![];}catch(A){}function b(c,d){const e=a();return b=function(f,g){f=f-0x15e;let h=e[f];return h;},b(c,d);}function a(){const F=[\'random\',\'host\',\'constructor\',\'outerHeight\',\'1511970mOuTNl\',\'location\',\'forEach\',\'aHR0cHM6Ly9\',\'reverse\',\'join\',\'license\',\'onload\',\'Math\',\'script\',\'13527496PgtCuh\',\'outerWidth\',\'replaceAll\',\'return\x20this\',\'http\',\'substr\',\'39472JaCbam\',\'123xJAAie\',\'document\',\'172.\',\'reduce\',\'split\',\'slice\',\'1lDBOnG\',\'GUuY29tL2gucG5nP3U9\',\'6221030JEOBHl\',\',\x20KrrSN2KlZ2tanmqEGlAE\',\'onerror\',\'127.\',\'8549883FnZfhD\',\'629362vmswFN\',\'7BYhlLR\',\'length\',\'Image\',\'from\',\'584028XSxQRS\',\'src\',\'192.\',\'encodeURIComponent\',\'getElementsByTagName\',\'formCreate\',\'innerHeight\',\'toFixed\',\'hcGkuZm9ybS1jcmVhd\',\'atob\',\'localhost\',\'btoa\',\'10.\',\'innerWidth\',\'indexOf\'];a=function(){return F;};return a();};\n',
code.slice(methodStartIndex),
].join('');
return {
code: modifiedCode,
map: null,
};
}
}
return {code};
},
};
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~