Skip to content

Commit

Permalink
chore(compiler): disabled devtools by default and turn on config
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ksem committed Aug 26, 2024
1 parent c1eb7f8 commit 682fc16
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
35 changes: 35 additions & 0 deletions packages/compiler/shared/merge-deep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copied from ui/src/utils/merge-deep.ts

const isObject = (obj: any) => obj && typeof obj === 'object' && !Array.isArray(obj)

/**
* Merge objects deep
* If property is array, it will replace target value
*/
export const mergeDeep = (target: any, source: any): any => {
if (!isObject(target)) {
target = {}
}

Object.keys(source).forEach(key => {
const targetValue = target[key]
const sourceValue = source[key]

if (sourceValue instanceof RegExp || sourceValue instanceof Date) {
target[key] = sourceValue
} else if (isObject(targetValue) && isObject(sourceValue)) {
target[key] = mergeDeep(Object.create(
Object.getPrototypeOf(targetValue),
Object.getOwnPropertyDescriptors(targetValue),
), sourceValue)
} else {
target[key] = sourceValue
}
})

return target
}

export const mergeDeepMultiple = (...objects: any[]): any => {
return objects.reduce((acc, obj) => mergeDeep(acc, obj), {})
}
13 changes: 12 additions & 1 deletion packages/compiler/vite-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createLogger, Plugin } from "vite"
import { devtools, PluginOptions as DevtoolsPluginOptions } from "../devtools"
import { cssLayers } from "../css-layers"
import { vuesticConfig, Options as VuesticConfigPluginOptions } from "../vuestic-config"
import { mergeDeep } from "../shared/merge-deep"

type Options = {
/** @default true */
Expand Down Expand Up @@ -40,7 +41,17 @@ const logger = createLogger('info', {
prefix: '[vuestic:compiler]'
})

const defaultOptions: Required<Options> = {
devtools: false,
cssLayers: false,
config: {
configPath: 'vuestic.config.ts'
},
}

export const vuestic = (options: Options = {}): Plugin[] => {
options = mergeDeep(defaultOptions, options)

const extractOptions = (key: keyof Options) => {
// Build fails without as Record<string, string> cast
return typeof options[key] === 'object' ? options[key] as Record<string, string> : undefined
Expand All @@ -55,7 +66,7 @@ export const vuestic = (options: Options = {}): Plugin[] => {
plugins.push(devtools(extractOptions('devtools')))
}

if (options.cssLayers === true) {
if (options.cssLayers !== false) {
logger.info('Using vuestic:css-layers', {
timestamp: true,
})
Expand Down
4 changes: 3 additions & 1 deletion packages/docs/page-config/compiler/devtools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import { vuestic } from '@vuestic/compiler/vite'
export default defineConfig({
plugins: [
vuestic(),
vuestic({
devtools: true,
}),
vue(),
],
})
Expand Down
4 changes: 1 addition & 3 deletions packages/docs/page-config/compiler/vuestic-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ import { vuestic } from '@vuestic/compiler/vite'
export default defineConfig({
plugins: [
vuestic({
config: true,
}),
vuestic(),
vue(),
],
})
Expand Down

0 comments on commit 682fc16

Please sign in to comment.