Skip to content

Commit

Permalink
fixing nuxt module build error (#452)
Browse files Browse the repository at this point in the history
* using createResolver

* fixing issue with importing vite config from @explorer-1/vue
  • Loading branch information
stephiescastle authored May 31, 2024
1 parent edbf1cf commit 428feed
Show file tree
Hide file tree
Showing 14 changed files with 501 additions and 2,405 deletions.
9 changes: 9 additions & 0 deletions packages/nuxt/dist/module.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as _nuxt_schema from '@nuxt/schema';

interface ModuleOptions {
includeStyles: boolean;
includeComponents: boolean;
}
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;

export { type ModuleOptions, _default as default };
11 changes: 9 additions & 2 deletions packages/nuxt/dist/module.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
export * from "/Users/smithste/repos/explorer-1/packages/nuxt/src/module";
export { default } from "/Users/smithste/repos/explorer-1/packages/nuxt/src/module";
import * as _nuxt_schema from '@nuxt/schema';

interface ModuleOptions {
includeStyles: boolean;
includeComponents: boolean;
}
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;

export { type ModuleOptions, _default as default };
57 changes: 48 additions & 9 deletions packages/nuxt/dist/module.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
import jiti from "file:///Users/smithste/repos/explorer-1/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/lib/index.js";
import { defineNuxtModule, createResolver, installModule, addComponentsDir } from '@nuxt/kit';

/** @type {import("/Users/smithste/repos/explorer-1/packages/nuxt/src/module")} */
const _module = jiti(null, {
"esmResolve": true,
"interopDefault": true,
"alias": {
"@explorer-1/nuxt": "/Users/smithste/repos/explorer-1/packages/nuxt"
const module = defineNuxtModule({
meta: {
name: "@explorer-1/nuxt",
configKey: "explorer1"
},
// Default configuration options of the Nuxt module
defaults: {
includeStyles: true,
includeComponents: true
},
async setup(_options, _nuxt) {
const resolver = createResolver(import.meta.url);
const runtimeDir = resolver.resolve("./runtime");
if (_options.includeStyles) {
await installModule("@nuxtjs/tailwindcss", {
configPath: resolver.resolve(runtimeDir, "tailwind.config")
});
_nuxt.options.css.push(
resolver.resolve("./../node_modules/@explorer-1/vue/src/assets/scss/", "styles.scss")
);
_nuxt.options.postcss = {
plugins: {
autoprefixer: {}
}
};
_nuxt.options.vite = {
..._nuxt.options.vite,
css: {
..._nuxt.options.css,
preprocessorOptions: {
scss: {
additionalData: `@import "@explorer-1/common/src/scss/_hover.scss";`
}
}
}
};
}
if (_options.includeComponents) {
addComponentsDir({
path: resolver.resolve("./../node_modules/@explorer-1/vue/src/components"),
global: true,
pathPrefix: false,
extensions: [".vue"]
});
}
}
})("/Users/smithste/repos/explorer-1/packages/nuxt/src/module.ts");
});

export default _module;
export { module as default };
1 change: 0 additions & 1 deletion packages/nuxt/dist/runtime

This file was deleted.

12 changes: 12 additions & 0 deletions packages/nuxt/dist/runtime/tailwind.config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare const _default: {
content: string[];
mode: string;
darkMode: "class";
theme: Partial<import("../../../common/node_modules/tailwindcss/types/config").CustomThemeConfig>;
plugins: any[];
future: {
hoverOnlyWhenSupported: true;
};
safelist: string[];
};
export default _default;
11 changes: 11 additions & 0 deletions packages/nuxt/dist/runtime/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createResolver } from '@nuxt/kit'
import explorer1Config from '@explorer-1/common/tailwind.config'

console.log('ℹ Tailwind Config provided by @explorer-1/nuxt')

const resolver = createResolver(import.meta.url)

export default {
...explorer1Config,
content: [resolver.resolve('./../../node_modules/@explorer-1/vue/src/**/*.vue')]
}
13 changes: 2 additions & 11 deletions packages/nuxt/dist/types.d.mts
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@

import type { ModuleOptions, ModuleHooks, ModuleRuntimeHooks, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module.js'
import type { ModuleOptions } from './module.js'

declare module '#app' {
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
}

declare module '@nuxt/schema' {
interface NuxtConfig { ['explorer1']?: Partial<ModuleOptions> }
interface NuxtOptions { ['explorer1']?: ModuleOptions }
interface NuxtHooks extends ModuleHooks {}
interface RuntimeConfig extends ModuleRuntimeConfig {}
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
}

declare module 'nuxt/schema' {
interface NuxtConfig { ['explorer1']?: Partial<ModuleOptions> }
interface NuxtOptions { ['explorer1']?: ModuleOptions }
interface NuxtHooks extends ModuleHooks {}
interface RuntimeConfig extends ModuleRuntimeConfig {}
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
}


export type { default } from './module.js'
export type { ModuleOptions, default } from './module.js'
13 changes: 2 additions & 11 deletions packages/nuxt/dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@

import type { ModuleOptions, ModuleHooks, ModuleRuntimeHooks, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module'
import type { ModuleOptions } from './module'

declare module '#app' {
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {}
}

declare module '@nuxt/schema' {
interface NuxtConfig { ['explorer1']?: Partial<ModuleOptions> }
interface NuxtOptions { ['explorer1']?: ModuleOptions }
interface NuxtHooks extends ModuleHooks {}
interface RuntimeConfig extends ModuleRuntimeConfig {}
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
}

declare module 'nuxt/schema' {
interface NuxtConfig { ['explorer1']?: Partial<ModuleOptions> }
interface NuxtOptions { ['explorer1']?: ModuleOptions }
interface NuxtHooks extends ModuleHooks {}
interface RuntimeConfig extends ModuleRuntimeConfig {}
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
}


export type { default } from './module'
export type { ModuleOptions, default } from './module'
2 changes: 1 addition & 1 deletion packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"scripts": {
"prepack": "nuxt-module-build build",
"dev": "nuxi dev playground",
"build": "npm run dev:prepare",
"build": "pnpm prepack",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
Expand Down
35 changes: 13 additions & 22 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { defineNuxtModule, addComponentsDir, installModule } from '@nuxt/kit'
import { fileURLToPath } from 'node:url'
import { resolve } from 'node:path'
import explorer1ViteConfig from '@explorer-1/vue/vite.config'
import path from 'path'
import type {} from '@nuxt/schema'
import { defineNuxtModule, addComponentsDir, installModule, createResolver } from '@nuxt/kit'

export interface ModuleOptions {
includeStyles: boolean
includeComponents: boolean
}

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

export default defineNuxtModule<ModuleOptions>({
meta: {
name: '@explorer-1/nuxt',
Expand All @@ -24,16 +17,18 @@ export default defineNuxtModule<ModuleOptions>({
includeComponents: true
},
async setup(_options, _nuxt) {
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
const resolver = createResolver(import.meta.url)
const runtimeDir = resolver.resolve('./runtime')
if (_options.includeStyles) {
await installModule('@nuxtjs/tailwindcss', {
configPath: resolve(runtimeDir, 'tailwind.config')
configPath: resolver.resolve(runtimeDir, 'tailwind.config')
})

// add explorer-1 css
_nuxt.options.css.push(
resolve(__dirname, './../node_modules/@explorer-1/vue/src/assets/scss/styles.scss')
resolver.resolve('./../node_modules/@explorer-1/vue/src/assets/scss/', 'styles.scss')
)

// add postcss options
_nuxt.options.postcss = {
plugins: {
Expand All @@ -44,24 +39,20 @@ export default defineNuxtModule<ModuleOptions>({
// extend nuxt's vite config without overriding nuxt.config.js
_nuxt.options.vite = {
..._nuxt.options.vite,
resolve: {
..._nuxt.options.vite.resolve,
alias: {
..._nuxt.options.vite?.resolve?.alias,
...explorer1ViteConfig?.resolve?.alias
}
},

css: {
..._nuxt.options.css,
...explorer1ViteConfig.css
preprocessorOptions: {
scss: {
additionalData: `@import "@explorer-1/common/src/scss/_hover.scss";`
}
}
}
}
}
if (_options.includeComponents) {
// add all @explorer-1/vue components
addComponentsDir({
path: resolve(__dirname, './../node_modules/@explorer-1/vue/src/components'),
path: resolver.resolve('./../node_modules/@explorer-1/vue/src/components'),
global: true,
pathPrefix: false,
extensions: ['.vue']
Expand Down
11 changes: 4 additions & 7 deletions packages/nuxt/src/runtime/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import path from 'path'
import { fileURLToPath } from 'node:url'
import { createResolver } from '@nuxt/kit'
import explorer1Config from '@explorer-1/common/tailwind.config'

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

console.log('ℹ Tailwind Config provided by @explorer-1/nuxt')

const resolver = createResolver(import.meta.url)

export default {
...explorer1Config,
content: [path.resolve(__dirname, './../../node_modules/@explorer-1/vue/src/**/*.vue')]
content: [resolver.resolve('./../../node_modules/@explorer-1/vue/src/**/*.vue')]
}
Loading

0 comments on commit 428feed

Please sign in to comment.