Added hot dev mode

pull/6424/head
Mert Sincan 2024-09-17 22:55:40 +01:00
parent 4795c2382b
commit 02094f31ae
5 changed files with 41 additions and 11 deletions

View File

@ -12,6 +12,14 @@ const alias = {
'@primevue/icons': path.resolve(__dirname, '../../packages/icons/src') '@primevue/icons': path.resolve(__dirname, '../../packages/icons/src')
}; };
let PROCESS_ENV = {};
try {
PROCESS_ENV = process?.env || {};
} catch {
// NOOP
}
// https://nuxt.com/docs/api/configuration/nuxt-config // https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({ export default defineNuxtConfig({
typescript: false, typescript: false,
@ -35,7 +43,14 @@ export default defineNuxtConfig({
'/accessibility': { redirect: { to: '/guides/accessibility', statusCode: 301 } }, '/accessibility': { redirect: { to: '/guides/accessibility', statusCode: 301 } },
'/installation': { redirect: { to: '/vite', statusCode: 301 } } '/installation': { redirect: { to: '/vite', statusCode: 301 } }
}, },
primevue: { primevue:
PROCESS_ENV.DEV_ENV === 'hot'
? {
usePrimeVue: false,
autoImport: true,
loadStyles: false
}
: {
autoImport: true, // When enabled, the module automatically imports PrimeVue components and directives used throughout the application. autoImport: true, // When enabled, the module automatically imports PrimeVue components and directives used throughout the application.
importTheme: { from: '@/themes/app-theme.js' } importTheme: { from: '@/themes/app-theme.js' }
}, },
@ -79,7 +94,8 @@ export default defineNuxtConfig({
}, },
runtimeConfig: { runtimeConfig: {
public: { public: {
contextPath: baseUrl contextPath: baseUrl,
DEV_ENV: PROCESS_ENV.DEV_ENV
} }
}, },
gtag: { gtag: {

View File

@ -16,6 +16,15 @@ const $appState = {
} }
}; };
export default defineNuxtPlugin((nuxtApp) => { export default defineNuxtPlugin(async (nuxtApp) => {
const runtimeConfig = useRuntimeConfig();
nuxtApp.vueApp.use($appState); nuxtApp.vueApp.use($appState);
if (runtimeConfig.public.DEV_ENV === 'hot') {
const { default: PrimeVue } = await import('primevue/config');
const { default: Noir } = await import('@/themes/app-theme');
nuxtApp.vueApp.use(PrimeVue, { theme: Noir });
}
}); });

View File

@ -27,9 +27,10 @@
"build:lib": "pnpm --filter primevue build", "build:lib": "pnpm --filter primevue build",
"build:themes": "pnpm --filter themes build", "build:themes": "pnpm --filter themes build",
"build:icons": "pnpm --filter icons build", "build:icons": "pnpm --filter icons build",
"build:showcase": "pnpm --filter showcase build:prebuild", "build:showcase": "pnpm --filter showcase build",
"build:apidoc": "pnpm --filter themes build:tokens && pnpm --filter showcase build:apidoc", "build:apidoc": "pnpm --filter themes build:tokens && pnpm --filter showcase build:apidoc",
"dev": "pnpm --filter showcase dev", "dev": "pnpm --filter showcase dev",
"hot:dev": "DEV_ENV=hot pnpm --filter showcase dev",
"module:dev": "pnpm --filter @primevue/nuxt-module dev", "module:dev": "pnpm --filter @primevue/nuxt-module dev",
"security:check": "pnpm audit --prod --audit-level high", "security:check": "pnpm audit --prod --audit-level high",
"format": "prettier --write \"**/*.{vue,js,mjs,ts,d.ts}\" --cache", "format": "prettier --write \"**/*.{vue,js,mjs,ts,d.ts}\" --cache",

View File

@ -21,6 +21,7 @@ export default defineNuxtModule<ModuleOptions>({
//cssLayerOrder: undefined, //cssLayerOrder: undefined,
importPT: undefined, importPT: undefined,
importTheme: undefined, importTheme: undefined,
loadStyles: true,
options: {}, options: {},
components: { components: {
prefix: '', prefix: '',
@ -47,7 +48,7 @@ export default defineNuxtModule<ModuleOptions>({
const resolver = createResolver(import.meta.url); const resolver = createResolver(import.meta.url);
const registered = register(moduleOptions); const registered = register(moduleOptions);
const { autoImport, importPT, importTheme, options } = moduleOptions; const { autoImport, importPT, importTheme, options, loadStyles } = moduleOptions;
const hasTheme = (importTheme || options?.theme) && !options?.unstyled; const hasTheme = (importTheme || options?.theme) && !options?.unstyled;
nuxt.options.runtimeConfig.public.primevue = { nuxt.options.runtimeConfig.public.primevue = {
@ -84,6 +85,8 @@ export default defineNuxtModule<ModuleOptions>({
} }
const styleContent = () => { const styleContent = () => {
if (!loadStyles) return `export const styles = [], stylesToTop = [], themes = [];`;
const uniqueRegisteredStyles = Array.from(new Map(registeredStyles?.map((m: MetaType) => [m.name, m])).values()); const uniqueRegisteredStyles = Array.from(new Map(registeredStyles?.map((m: MetaType) => [m.name, m])).values());
return ` return `

View File

@ -14,6 +14,7 @@ export interface ModuleOptions {
/*cssLayerOrder?: string;*/ /*cssLayerOrder?: string;*/
importPT?: ImportOptions; importPT?: ImportOptions;
importTheme?: ImportOptions; importTheme?: ImportOptions;
loadStyles?: boolean;
options?: PrimeVueOptions; options?: PrimeVueOptions;
components?: ConstructsType; components?: ConstructsType;
directives?: ConstructsType; directives?: ConstructsType;