chore: address deprecated Vite warnings
This commit is contained in:
parent
f374f8db38
commit
d3a5569290
|
|
@ -14,8 +14,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fs, { existsSync } from 'fs';
|
import * as fs from 'fs';
|
||||||
import path from 'path';
|
import * as path from 'path';
|
||||||
import type { Plugin, UserConfig } from 'vite';
|
import type { Plugin, UserConfig } from 'vite';
|
||||||
|
|
||||||
export function bundle(): Plugin {
|
export function bundle(): Plugin {
|
||||||
|
|
@ -26,7 +26,7 @@ export function bundle(): Plugin {
|
||||||
config = c;
|
config = c;
|
||||||
},
|
},
|
||||||
transformIndexHtml: {
|
transformIndexHtml: {
|
||||||
transform(html, ctx) {
|
handler(html, ctx) {
|
||||||
if (!ctx || !ctx.bundle)
|
if (!ctx || !ctx.bundle)
|
||||||
return html;
|
return html;
|
||||||
html = html.replace(/(?=<!--)([\s\S]*?)-->/, '');
|
html = html.replace(/(?=<!--)([\s\S]*?)-->/, '');
|
||||||
|
|
@ -42,7 +42,7 @@ export function bundle(): Plugin {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
closeBundle: () => {
|
closeBundle: () => {
|
||||||
if (existsSync(path.join(config.build!.outDir!, 'index.html'))) {
|
if (fs.existsSync(path.join(config.build!.outDir!, 'index.html'))) {
|
||||||
const targetDir = path.join(__dirname, '..', 'playwright-core', 'lib', 'vite', 'htmlReport');
|
const targetDir = path.join(__dirname, '..', 'playwright-core', 'lib', 'vite', 'htmlReport');
|
||||||
fs.mkdirSync(targetDir, { recursive: true });
|
fs.mkdirSync(targetDir, { recursive: true });
|
||||||
fs.copyFileSync(
|
fs.copyFileSync(
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
"name": "html-reporter",
|
"name": "html-reporter",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build && tsc",
|
"build": "vite build && tsc",
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleResolution": "node"
|
"moduleResolution": "node"
|
||||||
},
|
},
|
||||||
"include": ["vite.config.ts"]
|
"include": ["vite.config.ts", "bundle.ts"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
"name": "recorder",
|
"name": "recorder",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build && tsc",
|
"build": "vite build && tsc",
|
||||||
|
|
|
||||||
|
|
@ -14,23 +14,18 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
import type { Plugin } from 'vite';
|
||||||
* @returns {import('vite').Plugin}
|
|
||||||
*/
|
export function bundle(): Plugin {
|
||||||
export function bundle() {
|
|
||||||
let config;
|
|
||||||
return {
|
return {
|
||||||
name: 'playwright-bundle',
|
name: 'playwright-bundle',
|
||||||
config(c) {
|
|
||||||
config = c;
|
|
||||||
},
|
|
||||||
transformIndexHtml: {
|
transformIndexHtml: {
|
||||||
transform(html, ctx) {
|
handler(html, ctx) {
|
||||||
if (!ctx || !ctx.bundle)
|
if (!ctx || !ctx.bundle)
|
||||||
return html;
|
return html;
|
||||||
// Workaround vite issue that we cannot exclude some scripts from preprocessing.
|
// Workaround vite issue that we cannot exclude some scripts from preprocessing.
|
||||||
return html.replace(/(?=<!--)([\s\S]*?)-->/, '').replace('<!-- <script src="stall.js"></script> -->', '<script src="stall.js"></script>');
|
return html.replace(/(?=<!--)([\s\S]*?)-->/, '').replace('<!-- <script src="stall.js"></script> -->', '<script src="stall.js"></script>');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
"name": "trace-viewer",
|
"name": "trace-viewer",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build && tsc",
|
"build": "vite build && tsc",
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleResolution": "node"
|
"moduleResolution": "node"
|
||||||
},
|
},
|
||||||
"include": ["vite.config.ts"]
|
"include": ["vite.config.ts", "bundle.ts"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
// @ts-ignore
|
|
||||||
import { bundle } from './bundle';
|
import { bundle } from './bundle';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
// @ts-ignore
|
|
||||||
import { bundle } from './bundle';
|
import { bundle } from './bundle';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue