Skip to content

Commit

Permalink
✨ (theme) lighten module; better usage of nuxt-extend
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed May 17, 2021
1 parent c020a16 commit 3edb131
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
12 changes: 11 additions & 1 deletion src/defaultTheme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const themeConfig: NuxtConfig = nuxtConfig({
rootDir: __dirname,
themeName: 'defaultTheme',
themeDir: __dirname,
colorMode: {
classSuffix: ''
},
css: [r('./css/main.css'), r('./css/prism.css')],
components: [
{
path: r('./components/atoms'),
Expand Down Expand Up @@ -42,7 +46,13 @@ const themeConfig: NuxtConfig = nuxtConfig({
}
],
plugins: [r('./plugins/menu')],
modules: [themeSetupModule, 'nuxt-windicss', '@nuxtjs/color-mode']
modules: [themeSetupModule, 'nuxt-windicss', '@nuxtjs/color-mode'],
hooks: {
ready: readyHook,
build: {
before: beforeBuildHook
}
}
})

export default themeConfig
Expand Down
30 changes: 13 additions & 17 deletions src/defaultTheme/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,7 @@ const r = (...args: string[]) => resolve(__dirname, ...args)

export const readyHook = ({ options }) => {
// Override editor style on dev mode
if (options.dev) {
options.css.push(r('css/main.dev.css'))
}

// Push local css files
options.css.push(r('css/main.css'))
options.css.push(r('css/prism.css'))

// Disable color mode class suffix
options.colorMode = {
classSuffix: ''
}
if (options.dev) options.css.push(r('css/main.dev.css'))
}

export const beforeBuildHook = async ({ options }) => {
Expand All @@ -42,7 +31,18 @@ export default <Module>function themeSetupModule() {
windiOptions.config = defu.arrayFn(windiOptions.config || {}, defaultWindiConfig)

// Include local & npm depencies directories in scan process
windiOptions.scanOptions.dirs.push(__dirname, join(options.rootDir, '/node_modules/docus/dist'), options.themeDir)
windiOptions.scanOptions.dirs.push(
__dirname,
join(__dirname, '/node_modules/docus/dist'),
join(options.rootDir, '/node_modules/docus/dist'),
join(options.themeDir)
)

windiOptions.scanOptions.include.push(
join(__dirname, '/**/*.{html,vue,md,mdx,pug,jsx,tsx,svelte}'),
join(options.rootDir, '/node_modules/docus/dist/**/*.{html,vue,md,mdx,pug,jsx,tsx,svelte}'),
join(options.themeDir, '/**/*.{html,vue,md,mdx,pug,jsx,tsx,svelte}')
)

windiOptions.config.shortcuts = {
...(windiOptions.shortcuts || {}),
Expand Down Expand Up @@ -73,8 +73,4 @@ export default <Module>function themeSetupModule() {
nuxt.options.watch.push(componentsDirPath)
}
})

hook('ready', readyHook)

hook('build:before', beforeBuildHook)
}

0 comments on commit 3edb131

Please sign in to comment.