@vkontakte/create-vk-mini-app
Advanced tools
Comparing version 2.0.3 to 2.0.4
{ | ||
"name": "@vkontakte/create-vk-mini-app", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "VK Mini Apps Boilerplate", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/VKCOM/create-vk-mini-app", |
@@ -32,4 +32,5 @@ { | ||
"eslint-plugin-react-refresh": "^0.4.5", | ||
"node-html-parser": "^6.1.12", | ||
"vite": "^5.0.8" | ||
} | ||
} |
import { defineConfig, transformWithEsbuild } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import { parse } from 'node-html-parser'; | ||
@@ -30,18 +31,76 @@ function handleModuleDirectivesPlugin() { | ||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react(), threatJsFilesAsJsx(), handleModuleDirectivesPlugin()], | ||
function odrPlugin() { | ||
return { | ||
name: 'odr-plugin', | ||
transformIndexHtml(html) { | ||
const tags = ['audio', 'video', 'img', 'link', 'script']; | ||
const dom = parse(html); | ||
optimizeDeps: { | ||
force: true, | ||
esbuildOptions: { | ||
loader: { | ||
'.js': 'jsx', | ||
const htmlElementHandlers = { | ||
removeCrossorigin: (element) => { | ||
element.removeAttribute('crossorigin'); | ||
}, | ||
changeSrc: (element) => { | ||
let value = element.getAttribute('src'); | ||
if (String(value).startsWith('/')) { | ||
value && element.setAttribute('src', '.' + value); | ||
} | ||
value = element.getAttribute('href'); | ||
if (String(value).startsWith('/')) { | ||
value && element.setAttribute('href', '.' + value); | ||
} | ||
}, | ||
removeScriptType: (element) => { | ||
element.removeAttribute('type'); | ||
}, | ||
changeScriptLoadToDefer: (element) => { | ||
element.setAttribute('defer', 'defer'); | ||
}, | ||
}; | ||
tags.forEach((tag) => { | ||
dom.getElementsByTagName(tag).forEach((element) => { | ||
htmlElementHandlers.changeSrc(element); | ||
htmlElementHandlers.removeCrossorigin(element); | ||
if (element.tagName === 'script'.toUpperCase()) { | ||
htmlElementHandlers.removeScriptType(element); | ||
htmlElementHandlers.changeScriptLoadToDefer(element); | ||
} | ||
}); | ||
}); | ||
return dom.toString(); | ||
}, | ||
}; | ||
} | ||
export default ({ mode }) => { | ||
return defineConfig({ | ||
plugins: [ | ||
react(), | ||
threatJsFilesAsJsx(), | ||
handleModuleDirectivesPlugin(), | ||
mode === 'production' && odrPlugin(), | ||
], | ||
optimizeDeps: { | ||
force: true, | ||
esbuildOptions: { | ||
loader: { | ||
'.js': 'jsx', | ||
}, | ||
}, | ||
}, | ||
}, | ||
build: { | ||
outDir: 'build', | ||
}, | ||
}); | ||
build: { | ||
outDir: 'build', | ||
}, | ||
}); | ||
}; |
@@ -31,4 +31,5 @@ { | ||
"eslint-plugin-react-refresh": "^0.4.5", | ||
"node-html-parser": "^6.1.12", | ||
"vite": "^5.0.8" | ||
} | ||
} |
import { defineConfig, transformWithEsbuild } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import { parse } from 'node-html-parser'; | ||
@@ -30,18 +31,76 @@ function handleModuleDirectivesPlugin() { | ||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react(), threatJsFilesAsJsx(), handleModuleDirectivesPlugin()], | ||
function odrPlugin() { | ||
return { | ||
name: 'odr-plugin', | ||
transformIndexHtml(html) { | ||
const tags = ['audio', 'video', 'img', 'link', 'script']; | ||
const dom = parse(html); | ||
optimizeDeps: { | ||
force: true, | ||
esbuildOptions: { | ||
loader: { | ||
'.js': 'jsx', | ||
const htmlElementHandlers = { | ||
removeCrossorigin: (element) => { | ||
element.removeAttribute('crossorigin'); | ||
}, | ||
changeSrc: (element) => { | ||
let value = element.getAttribute('src'); | ||
if (String(value).startsWith('/')) { | ||
value && element.setAttribute('src', '.' + value); | ||
} | ||
value = element.getAttribute('href'); | ||
if (String(value).startsWith('/')) { | ||
value && element.setAttribute('href', '.' + value); | ||
} | ||
}, | ||
removeScriptType: (element) => { | ||
element.removeAttribute('type'); | ||
}, | ||
changeScriptLoadToDefer: (element) => { | ||
element.setAttribute('defer', 'defer'); | ||
}, | ||
}; | ||
tags.forEach((tag) => { | ||
dom.getElementsByTagName(tag).forEach((element) => { | ||
htmlElementHandlers.changeSrc(element); | ||
htmlElementHandlers.removeCrossorigin(element); | ||
if (element.tagName === 'script'.toUpperCase()) { | ||
htmlElementHandlers.removeScriptType(element); | ||
htmlElementHandlers.changeScriptLoadToDefer(element); | ||
} | ||
}); | ||
}); | ||
return dom.toString(); | ||
}, | ||
}; | ||
} | ||
export default ({ mode }) => { | ||
return defineConfig({ | ||
plugins: [ | ||
react(), | ||
threatJsFilesAsJsx(), | ||
handleModuleDirectivesPlugin(), | ||
mode === 'production' && odrPlugin(), | ||
], | ||
optimizeDeps: { | ||
force: true, | ||
esbuildOptions: { | ||
loader: { | ||
'.js': 'jsx', | ||
}, | ||
}, | ||
}, | ||
}, | ||
build: { | ||
outDir: 'build', | ||
}, | ||
}); | ||
build: { | ||
outDir: 'build', | ||
}, | ||
}); | ||
}; |
@@ -34,2 +34,3 @@ { | ||
"eslint-plugin-react-refresh": "^0.4.5", | ||
"node-html-parser": "^6.1.12", | ||
"typescript": "^5.2.2", | ||
@@ -36,0 +37,0 @@ "vite": "^5.0.8" |
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import { HTMLElement, parse } from 'node-html-parser'; | ||
@@ -16,9 +17,69 @@ function handleModuleDirectivesPlugin() { | ||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react(), handleModuleDirectivesPlugin()], | ||
/** | ||
* This plugin is required for a single product build for the odr archive and a build for the site. | ||
* If you have a complex system and a custom script connection system, we recommend using 2 different configurations | ||
* for odr and for the site. | ||
* | ||
* Details: https://dev.vk.com/ru/mini-apps/development/on-demand-resources | ||
*/ | ||
function odrPlugin() { | ||
return { | ||
name: 'odr-plugin', | ||
transformIndexHtml(html) { | ||
const tags = ['audio', 'video', 'img', 'link', 'script']; | ||
const dom = parse(html); | ||
build: { | ||
outDir: 'build', | ||
}, | ||
}); | ||
const htmlElementHandlers: Record<string, (element: HTMLElement) => void> = { | ||
removeCrossorigin: (element) => { | ||
element.removeAttribute('crossorigin'); | ||
}, | ||
changeSrc: (element) => { | ||
let value = element.getAttribute('src'); | ||
if (String(value).startsWith('/')) { | ||
value && element.setAttribute('src', '.' + value); | ||
} | ||
value = element.getAttribute('href'); | ||
if (String(value).startsWith('/')) { | ||
value && element.setAttribute('href', '.' + value); | ||
} | ||
}, | ||
removeScriptType: (element) => { | ||
element.removeAttribute('type'); | ||
}, | ||
changeScriptLoadToDefer: (element) => { | ||
element.setAttribute('defer', 'defer'); | ||
}, | ||
}; | ||
tags.forEach((tag) => { | ||
dom.getElementsByTagName(tag).forEach((element) => { | ||
htmlElementHandlers.changeSrc(element); | ||
htmlElementHandlers.removeCrossorigin(element); | ||
if (element.tagName === 'script'.toUpperCase()) { | ||
htmlElementHandlers.removeScriptType(element); | ||
htmlElementHandlers.changeScriptLoadToDefer(element); | ||
} | ||
}); | ||
}); | ||
return dom.toString(); | ||
}, | ||
}; | ||
} | ||
export default ({ mode }) => { | ||
return defineConfig({ | ||
plugins: [react(), handleModuleDirectivesPlugin(), mode === 'production' && odrPlugin()], | ||
build: { | ||
outDir: 'build', | ||
}, | ||
}); | ||
}; |
@@ -33,2 +33,3 @@ { | ||
"eslint-plugin-react-refresh": "^0.4.5", | ||
"node-html-parser": "^6.1.12", | ||
"typescript": "^5.2.2", | ||
@@ -35,0 +36,0 @@ "vite": "^5.0.8" |
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import { HTMLElement, parse } from 'node-html-parser'; | ||
@@ -16,9 +17,69 @@ function handleModuleDirectivesPlugin() { | ||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react(), handleModuleDirectivesPlugin()], | ||
/** | ||
* This plugin is required for a single product build for the odr archive and a build for the site. | ||
* If you have a complex system and a custom script connection system, we recommend using 2 different configurations | ||
* for odr and for the site. | ||
* | ||
* Details: https://dev.vk.com/ru/mini-apps/development/on-demand-resources | ||
*/ | ||
function odrPlugin() { | ||
return { | ||
name: 'odr-plugin', | ||
transformIndexHtml(html) { | ||
const tags = ['audio', 'video', 'img', 'link', 'script']; | ||
const dom = parse(html); | ||
build: { | ||
outDir: 'build', | ||
}, | ||
}); | ||
const htmlElementHandlers: Record<string, (element: HTMLElement) => void> = { | ||
removeCrossorigin: (element) => { | ||
element.removeAttribute('crossorigin'); | ||
}, | ||
changeSrc: (element) => { | ||
let value = element.getAttribute('src'); | ||
if (String(value).startsWith('/')) { | ||
value && element.setAttribute('src', '.' + value); | ||
} | ||
value = element.getAttribute('href'); | ||
if (String(value).startsWith('/')) { | ||
value && element.setAttribute('href', '.' + value); | ||
} | ||
}, | ||
removeScriptType: (element) => { | ||
element.removeAttribute('type'); | ||
}, | ||
changeScriptLoadToDefer: (element) => { | ||
element.setAttribute('defer', 'defer'); | ||
}, | ||
}; | ||
tags.forEach((tag) => { | ||
dom.getElementsByTagName(tag).forEach((element) => { | ||
htmlElementHandlers.changeSrc(element); | ||
htmlElementHandlers.removeCrossorigin(element); | ||
if (element.tagName === 'script'.toUpperCase()) { | ||
htmlElementHandlers.removeScriptType(element); | ||
htmlElementHandlers.changeScriptLoadToDefer(element); | ||
} | ||
}); | ||
}); | ||
return dom.toString(); | ||
}, | ||
}; | ||
} | ||
export default ({ mode }) => { | ||
return defineConfig({ | ||
plugins: [react(), handleModuleDirectivesPlugin(), mode === 'production' && odrPlugin()], | ||
build: { | ||
outDir: 'build', | ||
}, | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
414982
130
8885