vite.config.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { defineConfig } from 'vite';
  2. import obfuscatorPlugin from 'vite-plugin-javascript-obfuscator';
  3. import { VitePluginNode } from 'vite-plugin-node';
  4. export default defineConfig({
  5. server:{
  6. port:61337
  7. },
  8. plugins: [
  9. VitePluginNode({
  10. adapter:"express",
  11. appPath:"./server.js",
  12. exportName:"EduTextbookServer",
  13. // initAppOnBoot:false,
  14. }),
  15. obfuscatorPlugin({
  16. include: ["**/*.js"],
  17. exclude: [/node_modules/],
  18. apply: "build",
  19. debugger: true,
  20. options: {
  21. debugProtection:false,
  22. debugProtectionInterval:0,
  23. // ... [See more options](https://github.com/javascript-obfuscator/javascript-obfuscator)
  24. compact: true,
  25. controlFlowFlattening: false,
  26. controlFlowFlatteningThreshold: 0.5,
  27. deadCodeInjection: false,
  28. deadCodeInjectionThreshold: 0.2,
  29. disableConsoleOutput: false, // 禁用日志输出,调试时关闭
  30. identifierNamesGenerator: 'hexadecimal',
  31. log: true,
  32. renameGlobals: false,
  33. rotateStringArray: true,
  34. selfDefending: false,
  35. stringArray: true,
  36. stringArrayEncoding: ['base64'],
  37. stringArrayThreshold: 0.5,
  38. transformObjectKeys: false,
  39. unicodeEscapeSequence: false
  40. },
  41. }),
  42. ],
  43. build: {
  44. lib: {
  45. entry: 'server.js', // 入口文件
  46. name: 'edu-textbook-server',
  47. fileName: (format) => `edu-textbook-server.${format}.js`
  48. },
  49. rollupOptions: {
  50. input: 'server.js', // 你的入口文件
  51. output: {
  52. dir: 'dist/server',
  53. format: 'cjs'
  54. }
  55. }
  56. }
  57. });