Skip to content

Commit

Permalink
chore(client): decomposed vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
gearonix committed Aug 2, 2023
1 parent da31b41 commit 5d71369
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 54 deletions.
19 changes: 19 additions & 0 deletions apps/client/config/defineAliases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { resolve } from 'path'
import { AliasOptions, ResolveOptions } from 'vite'

type DefineAliases = ResolveOptions & { alias: AliasOptions }

const resolveLibs = (...args: string[]) =>
resolve(__dirname, '..', '..', '..', 'libs', ...args)

export const defineAliases = (): DefineAliases => {
return {
preserveSymlinks: true,
alias: {
'@code-gear/client-shared': resolve(
__dirname,
resolveLibs('client-shared', 'src', 'index.ts')
)
}
}
}
32 changes: 32 additions & 0 deletions apps/client/config/definePlugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PluginOption } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
import webfontDownload from 'vite-plugin-webfont-dl'
import viteTsConfigPaths from 'vite-tsconfig-paths'

import preact from '@preact/preset-vite'

export const definePlugins = (): PluginOption[] => {
return [
webfontDownload([
'https://fonts.googleapis.com/css2?family=Poppins&display=swap'
]),
preact(),
viteTsConfigPaths(),
VitePWA({
registerType: 'autoUpdate',
injectRegister: 'auto',
strategies: 'injectManifest',
srcDir: 'public',
filename: 'service-worker.js',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
clientsClaim: true,
skipWaiting: true
},
devOptions: {
enabled: false
},
includeAssets: ['**/*']
})
]
}
8 changes: 8 additions & 0 deletions apps/client/config/defineVariables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AnyObject } from '$/client-shared'

export const defineVariables = (): AnyObject => {
return {
'process.env': process.env,
_isDev_: process.env.NODE_ENV === 'development'
}
}
3 changes: 3 additions & 0 deletions apps/client/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { defineAliases } from './defineAliases'
export { definePlugins } from './definePlugins'
export { defineVariables } from './defineVariables'
55 changes: 4 additions & 51 deletions apps/client/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
// / <reference types="vitest" />
// / <reference types="vite-plugin-pwa/client" />
import path from 'path'
import { defineConfig } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
import webfontDownload from 'vite-plugin-webfont-dl'
import viteTsConfigPaths from 'vite-tsconfig-paths'

import preact from '@preact/preset-vite'
import { defineAliases, definePlugins, defineVariables } from './config'

export default defineConfig({
cacheDir: '../../node_modules/.vite/client',
define: {
'process.env': process.env,
_isDev_: process.env.NODE_ENV === 'development'
},
resolve: {
preserveSymlinks: true,
alias: {
'@code-gear/client-shared': path.resolve(
__dirname,
'../../libs/client-shared/src/index.ts'
)
}
},
define: defineVariables(),
resolve: defineAliases(),
server: {
port: 3000,
host: 'localhost',
Expand All @@ -34,39 +19,7 @@ export default defineConfig({
port: 4200,
host: 'localhost'
},
plugins: [
webfontDownload([
'https://fonts.googleapis.com/css2?family=Poppins&display=swap'
]),
preact(),
viteTsConfigPaths({
root: '../../'
}),
VitePWA({
registerType: 'autoUpdate',
injectRegister: 'auto',
strategies: 'injectManifest',
srcDir: 'public',
filename: 'service-worker.js',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
clientsClaim: true,
skipWaiting: true
},
devOptions: {
enabled: false
},
includeAssets: ['**/*']
})
],
build: {
rollupOptions: {
external: ['@code-gear/client-shared']
}
},
esbuild: {
exclude: ['@code-gear/client-shared']
},
plugins: definePlugins(),
test: {
globals: true,
cache: {
Expand Down
9 changes: 8 additions & 1 deletion libs/config/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"name": "@code-gear/config",
"version": "1.0.0"
"version": "1.0.0",
"main": "src/index.ts",
"exports": {
".": {
"import": "./src/index.ts",
"require": "./src/index.ts"
}
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@types/bcryptjs": "^2.4.2",
"@types/jest": "^29.4.0",
"@types/node": "18.14.2",
"@types/passport": "^0",
"@types/passport-jwt": "^3.0.9",
"@types/passport-local": "^1.0.35",
"@types/react": "^18.2.14",
Expand Down Expand Up @@ -142,11 +143,13 @@
"bcryptjs": "^2.4.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"dotenv": "^16.3.1",
"graphql": "^16.7.1",
"mobx": "^6.9.0",
"mobx-react-lite": "^3.4.3",
"moment": "^2.29.4",
"normalize.css": "^8.0.1",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"preact-compat": "^3.19.0",
Expand Down
55 changes: 53 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,10 @@ __metadata:
"@code-gear/server@workspace:apps/server":
version: 0.0.0-use.local
resolution: "@code-gear/server@workspace:apps/server"
dependencies:
"@code-gear/config": "workspace:*"
"@types/webpack-node-externals": ^3
webpack-node-externals: ^3.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -2061,6 +2065,7 @@ __metadata:
"@types/bcryptjs": ^2.4.2
"@types/jest": ^29.4.0
"@types/node": 18.14.2
"@types/passport": ^0
"@types/passport-jwt": ^3.0.9
"@types/passport-local": ^1.0.35
"@types/react": ^18.2.14
Expand All @@ -2086,6 +2091,7 @@ __metadata:
class-validator: ^0.14.0
concat-files: ^0.1.1
cypress: ^12.11.0
dotenv: ^16.3.1
eslint: ~8.41.0
eslint-config-gearonix: 1.0.2
eslint-config-google: ^0.14.0
Expand Down Expand Up @@ -2114,6 +2120,7 @@ __metadata:
normalize.css: ^8.0.1
nx: 16.4.0
nx-cloud: latest
passport: ^0.6.0
passport-jwt: ^4.0.1
passport-local: ^1.0.0
preact: ^10.15.1
Expand Down Expand Up @@ -5416,6 +5423,15 @@ __metadata:
languageName: node
linkType: hard

"@types/passport@npm:^0":
version: 0.4.7
resolution: "@types/passport@npm:0.4.7"
dependencies:
"@types/express": "*"
checksum: c22a84226d763db30cc6d8b330022820d067ea4039dc625371825e0d2fb8e3d6e7387cf4619e79a4cc293e8c3f3420f3da3067c564da14c21fadb03b5f5c870f
languageName: node
linkType: hard

"@types/prop-types@npm:*":
version: 15.7.5
resolution: "@types/prop-types@npm:15.7.5"
Expand Down Expand Up @@ -5628,6 +5644,16 @@ __metadata:
languageName: node
linkType: hard

"@types/webpack-node-externals@npm:^3":
version: 3.0.0
resolution: "@types/webpack-node-externals@npm:3.0.0"
dependencies:
"@types/node": "*"
webpack: ^5
checksum: ea87e99d389708ebf144e47ba1353bac2ab524f80f022b07ce683ba451f326a6cfd62acae36f0a727823a3c198e59de70baac20cf1ea9eb5cf0980ab55f758c7
languageName: node
linkType: hard

"@types/wicg-file-system-access@npm:^2020.9.6":
version: 2020.9.6
resolution: "@types/wicg-file-system-access@npm:2020.9.6"
Expand Down Expand Up @@ -8938,6 +8964,13 @@ __metadata:
languageName: node
linkType: hard

"dotenv@npm:^16.3.1":
version: 16.3.1
resolution: "dotenv@npm:16.3.1"
checksum: 15d75e7279018f4bafd0ee9706593dd14455ddb71b3bcba9c52574460b7ccaf67d5cf8b2c08a5af1a9da6db36c956a04a1192b101ee102a3e0cf8817bbcf3dfd
languageName: node
linkType: hard

"dotenv@npm:~10.0.0":
version: 10.0.0
resolution: "dotenv@npm:10.0.0"
Expand Down Expand Up @@ -15069,6 +15102,17 @@ __metadata:
languageName: node
linkType: hard

"passport@npm:^0.6.0":
version: 0.6.0
resolution: "passport@npm:0.6.0"
dependencies:
passport-strategy: 1.x.x
pause: 0.0.1
utils-merge: ^1.0.1
checksum: ef932ad671d50de34765c7a53cd1e058d8331a82a6df09265a9c6c1168911aee4a7b5215803d0101110ab7f317e096b4954ca7e18fb2c33b9929f0bd17dbe159
languageName: node
linkType: hard

"path-browserify@npm:^1.0.1":
version: 1.0.1
resolution: "path-browserify@npm:1.0.1"
Expand Down Expand Up @@ -15172,6 +15216,13 @@ __metadata:
languageName: node
linkType: hard

"pause@npm:0.0.1":
version: 0.0.1
resolution: "pause@npm:0.0.1"
checksum: e96ee581b68085e6f2ba5adbcb4d4a41fe88e5b514061e76df2fe1905f0f65f4fe5a843b538e9551122c6b9184ff4be266c2ee0ea4614702f9a3d04466d9f462
languageName: node
linkType: hard

"pend@npm:~1.2.0":
version: 1.2.0
resolution: "pend@npm:1.2.0"
Expand Down Expand Up @@ -19185,7 +19236,7 @@ __metadata:
languageName: node
linkType: hard

"utils-merge@npm:1.0.1":
"utils-merge@npm:1.0.1, utils-merge@npm:^1.0.1":
version: 1.0.1
resolution: "utils-merge@npm:1.0.1"
checksum: c81095493225ecfc28add49c106ca4f09cdf56bc66731aa8dabc2edbbccb1e1bfe2de6a115e5c6a380d3ea166d1636410b62ef216bb07b3feb1cfde1d95d5080
Expand Down Expand Up @@ -19713,7 +19764,7 @@ __metadata:
languageName: node
linkType: hard

"webpack@npm:^5.80.0":
"webpack@npm:^5, webpack@npm:^5.80.0":
version: 5.88.2
resolution: "webpack@npm:5.88.2"
dependencies:
Expand Down

0 comments on commit 5d71369

Please sign in to comment.