2026-08-24 10:07:16 +00:00
|
|
|
import { defineConfig } from 'vite';
|
|
|
|
|
import react from '@vitejs/plugin-react';
|
|
|
|
|
import fs from 'node:fs';
|
|
|
|
|
|
2026-08-28 06:47:06 +00:00
|
|
|
export default defineConfig(({mode}) => ({
|
2026-08-28 06:59:08 +00:00
|
|
|
plugins: [
|
|
|
|
|
react(),
|
2026-08-28 07:06:59 +00:00
|
|
|
{
|
|
|
|
|
name: 'add-nonce-back',
|
|
|
|
|
transformIndexHtml(html) {
|
|
|
|
|
const nonce = '**MY_PRETTY_CSP_NONCE**';
|
|
|
|
|
return html.replace(
|
|
|
|
|
/<script\s+type="module"\s+crossorigin\s+src="\/autocart\.js"\s*>/,
|
|
|
|
|
(match) => {
|
|
|
|
|
return `<script type="module" crossorigin nonce="${nonce}" src="/autocart.js">`;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-08-28 06:59:08 +00:00
|
|
|
mode === 'production' && {
|
|
|
|
|
name: 'copy-html-root',
|
|
|
|
|
closeBundle() {
|
2026-08-28 07:06:59 +00:00
|
|
|
fs.copyFileSync('dist/src/template.html', 'auto_cart.html');
|
|
|
|
|
fs.copyFileSync('dist/autocart.js', 'autocart.js');
|
2026-08-28 06:59:08 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
2026-08-28 06:47:06 +00:00
|
|
|
...(mode != 'production' && {
|
|
|
|
|
server: {
|
|
|
|
|
host: 'local.hvatilo.ru',
|
|
|
|
|
port: 9876,
|
|
|
|
|
https: {
|
|
|
|
|
cert: fs.readFileSync('local.hvatilo.ru.pem'),
|
|
|
|
|
key: fs.readFileSync('local.hvatilo.ru-key.pem'),
|
|
|
|
|
},
|
|
|
|
|
open: '/src/template.html',
|
|
|
|
|
}
|
|
|
|
|
}),
|
2026-08-24 10:07:16 +00:00
|
|
|
input: {
|
|
|
|
|
main: './src/template.html',
|
|
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
outDir: 'dist',
|
2026-08-28 06:59:08 +00:00
|
|
|
rolldownOptions: {
|
|
|
|
|
output: {
|
|
|
|
|
entryFileNames: 'autocart.js',
|
|
|
|
|
chunkFileNames: 'chunk.js',
|
|
|
|
|
assetFileNames: 'plugin.css',
|
|
|
|
|
},
|
|
|
|
|
}
|
2026-08-24 10:07:16 +00:00
|
|
|
},
|
2026-08-28 06:47:06 +00:00
|
|
|
}));
|