Skip to content

Commit

Permalink
fix(client): set process.env.NODE_ENV to production
Browse files Browse the repository at this point in the history
bug introduced by vitejs/vite#8090
  • Loading branch information
shigma committed Aug 6, 2022
1 parent b52aa6c commit a17ddaf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/client/package.json
@@ -1,7 +1,7 @@
{
"name": "@koishijs/client",
"description": "Koishi Console Client",
"version": "4.3.2",
"version": "4.3.3",
"main": "client/index.ts",
"files": [
"app",
Expand Down Expand Up @@ -43,6 +43,7 @@
"cosmokit": "^1.2.1",
"element-plus": "2.2.11",
"marked": "^4.0.18",
"ns-require": "^1.1.4",
"sass": "^1.54.0",
"schemastery": "^3.5.1",
"schemastery-vue": "^1.3.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/client/src/index.ts
Expand Up @@ -41,6 +41,9 @@ export async function buildExtension(root: string, config: UserConfig = {}) {
'@koishijs/client': root + '/client.js',
},
},
define: {
'process.env.NODE_ENV': '"production"',
},
} as InlineConfig, config))

await fsp.rename(root + '/dist/index.mjs', root + '/dist/index.js')
Expand Down
23 changes: 23 additions & 0 deletions packages/client/src/yakumo.ts
@@ -0,0 +1,23 @@
import { Module } from 'module'
import { UserConfig } from 'vite'
import { register } from 'yakumo'
import { buildExtension } from '.'
import ns from 'ns-require'

declare module 'yakumo' {
interface Config {
client?: string
}
}

register('client', async (project) => {
for (const path in project.targets) {
const meta = project.targets[path]
let config: UserConfig = {}
if (meta.yakumo?.client) {
const require = Module.createRequire(project.cwd + path + '/package.json')
config = ns.unwrapExports(require(meta.yakumo.client))
}
await buildExtension(project.cwd + path, config)
}
})
12 changes: 12 additions & 0 deletions packages/status/build/vite.config.ts
@@ -0,0 +1,12 @@
import { defineConfig } from 'vite'

export default defineConfig({
plugins: [{
name: 'fuck-echarts',
renderChunk(code, chunk) {
if (chunk.fileName.includes('echarts')) {
return code.replace(/\bSymbol(?!\.toStringTag)/g, 'FuckSymbol')
}
},
}],
})
3 changes: 3 additions & 0 deletions packages/status/package.json
Expand Up @@ -27,6 +27,9 @@
"status",
"server"
],
"yakumo": {
"client": "./build/vite.config"
},
"koishi": {
"description": {
"en": "Display running status in the console",
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Expand Up @@ -3,6 +3,9 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@koishijs/client/lib/*": [
"packages/client/src/*",
],
"@koishijs/plugin-*": [
"packages/*/src",
],
Expand Down

0 comments on commit a17ddaf

Please sign in to comment.