Skip to content

Commit

Permalink
fix: respect dir option from module for ipx
Browse files Browse the repository at this point in the history
resolves #817
  • Loading branch information
danielroe committed May 31, 2023
1 parent f293072 commit 7e187e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ipx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ipxSetup: ProviderSetup = async (providerOptions, moduleOptions) =>
nitro.options._config.runtimeConfig = nitro.options._config.runtimeConfig || {}
nitro.options._config.runtimeConfig.ipx = { ...ipxOptions }
// Use relative path for built app
ipxOptions.dir = relative(nitro.options.output.serverDir, nitro.options.output.publicDir)
ipxOptions.dir = relative(nitro.options.output.serverDir, moduleOptions.dir)
nitro.options.runtimeConfig.ipx = ipxOptions
})
nuxt.options.serverHandlers.push({
Expand Down
10 changes: 7 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parseURL, withLeadingSlash } from 'ufo'
import { defineNuxtModule, addTemplate, addImports, createResolver, addComponent, addPlugin } from '@nuxt/kit'
import { resolve } from 'pathe'
import { resolveProviders, detectProvider } from './provider'
import type { ImageProviders, ImageOptions, InputProvider, CreateImageOptions } from './types'

Expand All @@ -20,10 +21,10 @@ export interface ModuleOptions extends ImageProviders {
export * from './types'

export default defineNuxtModule<ModuleOptions>({
defaults: {
defaults: nuxt => ({
staticFilename: '[publicPath]/image/[hash][ext]',
provider: 'auto',
dir: '',
dir: nuxt.options.dir.public,
presets: {},
domains: [] as string[],
sharp: {},
Expand All @@ -40,7 +41,7 @@ export default defineNuxtModule<ModuleOptions>({
internalUrl: '',
providers: {},
alias: {}
},
}),
meta: {
name: '@nuxt/image',
configKey: 'image',
Expand All @@ -51,6 +52,9 @@ export default defineNuxtModule<ModuleOptions>({
async setup (options, nuxt) {
const resolver = createResolver(import.meta.url)

// fully resolve directory
options.dir = resolve(nuxt.options.srcDir, options.dir)

// Normalize domains to hostname
options.domains = options.domains.map((d) => {
if (!d.startsWith('http')) { d = 'http://' + d }
Expand Down

0 comments on commit 7e187e5

Please sign in to comment.