3 Commits

Author SHA1 Message Date
f111c83817 Fix(Preview): Fixed code pollution bug
Methods and variables in base and main code are isolated to solve the problem of code pollution.
2024-09-09 16:55:41 +08:00
bba90c6783 Build(package.json): Update version from 1.0.0-SNAPSHOT to 1.0.1-SNAPSHOT 2024-09-09 16:55:38 +08:00
d61888d2bf Merge pull request #2 from FatttSnake/FatttSnake
Add doc
2024-09-06 15:06:40 +08:00
7 changed files with 129 additions and 131 deletions

10
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "oxygen-ui",
"version": "1.0.0-SNAPSHOT",
"version": "1.0.1-SNAPSHOT",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "oxygen-ui",
"version": "1.0.0-SNAPSHOT",
"version": "1.0.1-SNAPSHOT",
"dependencies": {
"@ant-design/icons": "^5.3.7",
"@dnd-kit/core": "^6.1.0",
@@ -2153,9 +2153,9 @@
}
},
"node_modules/acorn": {
"version": "8.11.3",
"resolved": "https://registry.npmmirror.com/acorn/-/acorn-8.11.3.tgz",
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
"version": "8.12.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz",
"integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==",
"dev": true,
"bin": {
"acorn": "bin/acorn"

View File

@@ -32,7 +32,7 @@ const Preview = ({
Compiler.compile(files, importMap, entryPoint)
.then((result) => {
setCompiledCode(
`${preExpansionCode}\n${result.outputFiles[0].text}\n${postExpansionCode}`
`(()=>{${preExpansionCode}})();\n(()=>{${result.outputFiles[0].text}})();\n(()=>{${postExpansionCode}})();`
)
setErrorMsg('')
})

View File

@@ -2,7 +2,7 @@ import esbuild, { Loader, OnLoadArgs, Plugin, PluginBuild } from 'esbuild-wasm'
import localforage from 'localforage'
import axios from 'axios'
import { IFiles, IImportMap } from '@/components/Playground/shared'
import { cssToJs, jsonToJs, addReactImport } from '@/components/Playground/files'
import { addReactImport, cssToJs, jsonToJs } from '@/components/Playground/files'
class Compiler {
private init = false
@@ -73,8 +73,7 @@ class Compiler {
files: IFiles,
importMap: IImportMap,
entryPoint: string
): Plugin => {
return {
): Plugin => ({
name: 'file-resolver-plugin',
setup: (build: PluginBuild) => {
build.onResolve({ filter: /.*/ }, (args: esbuild.OnResolveArgs) => {
@@ -216,8 +215,7 @@ class Compiler {
return result
})
}
}
}
})
}
export default new Compiler()

View File

@@ -27,7 +27,7 @@ const Execute = () => {
const output = result.outputFiles[0].text
setCompiledCode('')
setTimeout(() => {
setCompiledCode(`${output}\n${baseDist}`)
setCompiledCode(`(() => {${output}})();\n(() => {${baseDist}})();`)
}, 100)
})
.catch((reason) => {

View File

@@ -145,7 +145,7 @@ const Create = () => {
.compile(files, importMap, template.entryPoint)
.then((result) => {
const output = result.outputFiles[0].text
setCompiledCode(`${output}\n${baseDist}`)
setCompiledCode(`(() => {${output}})();\n(() => {${baseDist}})();`)
})
.catch((reason) => {
void message.error(`编译失败:${reason}`)

View File

@@ -34,7 +34,7 @@ const View = () => {
const output = result.outputFiles[0].text
setCompiledCode('')
setTimeout(() => {
setCompiledCode(`${output}\n${baseDist}`)
setCompiledCode(`(() => {${output}})();\n(() => {${baseDist}})();`)
}, 100)
})
.catch((reason) => {
@@ -49,7 +49,7 @@ const View = () => {
const dist = base64ToStr(toolVo.dist.data!)
setCompiledCode('')
setTimeout(() => {
setCompiledCode(`${dist}\n${baseDist}`)
setCompiledCode(`(() => {${dist}})();\n(() => {${baseDist}})();`)
}, 100)
} catch (e) {
void message.error('载入工具失败')