Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/build/vite-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
"fs-extra": "^10.1.0",
"less": "^4.1.2",
"path": "^0.12.7",
"rollup-plugin-polyfill-node": "^0.13.0",
"rollup-plugin-visualizer": "^5.8.3",
"semver": "^7.7.1",
"shelljs": "^0.8.5",
"vite": "^5.4.2",
"vite-plugin-externalize-dependencies": "^1.0.1",
"vite-plugin-monaco-editor": "^1.1.0",
"vite-plugin-node-polyfills": "^0.23.0",
"vite-plugin-static-copy": "^1.0.6",
"vite-plugin-svg-icons": "^2.0.1"
},
Expand Down
24 changes: 20 additions & 4 deletions packages/build/vite-config/src/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import monacoEditorPluginCjs from 'vite-plugin-monaco-editor'
import vueJsx from '@vitejs/plugin-vue-jsx'
import nodeGlobalsPolyfillPluginCjs from '@esbuild-plugins/node-globals-polyfill'
import nodeModulesPolyfillPluginCjs from '@esbuild-plugins/node-modules-polyfill'
import nodePolyfill from 'rollup-plugin-polyfill-node'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import esbuildCopy from 'esbuild-plugin-copy'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import visualizerCjs from 'rollup-plugin-visualizer'
Expand All @@ -31,7 +31,17 @@ const getDefaultConfig = (engineConfig) => {
publicDir: path.resolve(root, './public'),
resolve: {
extensions: ['.js', '.jsx', '.vue', '.ts', '.tsx'],
alias: {}
alias: {
...Object.fromEntries(
['buffer', 'global', 'process'].map((k) => {
const location = `vite-plugin-node-polyfills/shims/${k}`
return [
location,
path.resolve(`node_modules/@opentiny/tiny-engine-vite-config/node_modules/${location}/dist/index.cjs`)
]
})
)
}
},
server: {
// 这里保证本地启动服务是localhost,支持js多线程和谷歌浏览器读写本地文件api
Expand Down Expand Up @@ -75,7 +85,14 @@ const getDefaultConfig = (engineConfig) => {
}
}
}),
vueJsx()
vueJsx(),
nodePolyfills({
globals: {
Buffer: true, // can also be 'build', 'dev', or false
global: true,
process: true
}
})
],
optimizeDeps: {
esbuildOptions: {
Expand Down Expand Up @@ -106,7 +123,6 @@ const getDefaultConfig = (engineConfig) => {
minify: true,
sourcemap: false,
rollupOptions: {
plugins: [nodePolyfill({ include: null })], // 使用@rollup/plugin-inject的默认值{include: null}, 即在所有代码中生效
input: {
index: path.resolve(process.cwd(), './index.html'),
preview: path.resolve(process.cwd(), './preview.html')
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"@types/diff-match-patch": "^1.0.36",
"@vitejs/plugin-vue": "^5.1.2",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"rollup-plugin-polyfill-node": "^0.13.0",
"vite": "^5.4.2"
"vite": "^5.4.2",
"vite-plugin-node-polyfills": "^0.23.0"
},
"peerDependencies": {
"@opentiny/vue": "^3.20.0",
Expand Down
18 changes: 15 additions & 3 deletions packages/canvas/scripts/canvas-vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import nodePolyfill from 'rollup-plugin-polyfill-node'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import path from 'node:path'
// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [
vue(),
vueJsx(),
nodePolyfills({
globals: {
Buffer: true,
global: true,
process: true
}
}),
{
name: 'vite-plugin-style-inline-loader',
apply: 'build',
Expand All @@ -46,13 +54,17 @@ export default defineConfig({
publicDir: false,
resolve: {
alias: {
assert: 'rollup-plugin-node-polyfills/polyfills/assert'
...Object.fromEntries(
['buffer', 'global', 'process'].map((k) => {
const location = `vite-plugin-node-polyfills/shims/${k}`
return [location, path.resolve(`node_modules/${location}/dist/index.cjs`)]
})
)
}
},
build: {
cssCodeSplit: true,
rollupOptions: {
plugins: [nodePolyfill({ include: null })],
external: [
'vue',
'vue-i18n',
Expand Down
2 changes: 1 addition & 1 deletion packages/design-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
"cross-env": "^7.0.3",
"eslint": "^8.38.0",
"less": "^4.1.2",
"rollup-plugin-polyfill-node": "^0.13.0",
"vite": "^5.4.2",
"vite-plugin-node-polyfills": "^0.23.0",
"vite-plugin-static-copy": "^1.0.6"
},
"peerDependencies": {
Expand Down
47 changes: 32 additions & 15 deletions packages/design-core/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { defineConfig } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import nodeGlobalsPolyfillPluginCjs from '@esbuild-plugins/node-globals-polyfill'
import nodeModulesPolyfillPluginCjs from '@esbuild-plugins/node-modules-polyfill'
import nodePolyfill from 'rollup-plugin-polyfill-node'
// import nodeGlobalsPolyfillPluginCjs from '@esbuild-plugins/node-globals-polyfill'
// import nodeModulesPolyfillPluginCjs from '@esbuild-plugins/node-modules-polyfill'
// import { nodePolyfills } from 'vite-plugin-node-polyfills'
import { fileURLToPath } from 'node:url'
import { viteStaticCopy } from 'vite-plugin-static-copy'

const nodeGlobalsPolyfillPlugin = nodeGlobalsPolyfillPluginCjs.default
const nodeModulesPolyfillPlugin = nodeModulesPolyfillPluginCjs.default
// const nodeGlobalsPolyfillPlugin = nodeGlobalsPolyfillPluginCjs.default
// const nodeModulesPolyfillPlugin = nodeModulesPolyfillPluginCjs.default

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
Expand Down Expand Up @@ -44,19 +44,36 @@ export default defineConfig({
}
]
})
// nodePolyfills({
// globals: {
// Buffer: true,
// global: true,
// process: true
// }
// })
],
publicDir: false,
optimizeDeps: {
esbuildOptions: {
plugins: [
nodeGlobalsPolyfillPlugin({
process: true,
buffer: true
}),
nodeModulesPolyfillPlugin()
]
resolve: {
alias: {
...Object.fromEntries(
['buffer', 'global', 'process'].map((k) => {
const location = `vite-plugin-node-polyfills/shims/${k}`
return [location, path.resolve(`node_modules/${location}/dist/index.cjs`)]
})
)
}
},
// optimizeDeps: {
// esbuildOptions: {
// plugins: [
// nodeGlobalsPolyfillPlugin({
// process: true,
// buffer: true
// }),
// nodeModulesPolyfillPlugin()
// ]
// }
// },
base: './',
define: {
'import.meta': 'import.meta',
Expand Down Expand Up @@ -86,7 +103,7 @@ export default defineConfig({
formats: ['es']
},
rollupOptions: {
plugins: [nodePolyfill({ include: null }), addViteIgnorePlugin()],
plugins: [addViteIgnorePlugin()],
output: {
banner: (chunk) => {
if (chunk.name === 'index') {
Expand Down