@atelier-wb/vite-plugin-svelte
Advanced tools
Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "@atelier-wb/vite-plugin-svelte", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Vite plugin to process your svelte components", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -29,3 +29,3 @@ const { resolve } = require('path') | ||
path: './atelier', | ||
url: '/atelier', | ||
url: '/', | ||
toolRegexp: '\\.tools\\.svelte+$', | ||
@@ -35,3 +35,3 @@ workframeHtml: resolve(__dirname, 'workframe.html'), | ||
bundled: true, | ||
publicDirs: [] | ||
publicDir: [] | ||
} | ||
@@ -82,3 +82,6 @@ | ||
} | ||
const hasTrailingUrl = options.url.endsWith('/') | ||
const hasTrailingSlash = options.url.endsWith('/') | ||
const workframeUrl = `${options.url}${hasTrailingSlash ? '' : '/'}${ | ||
options.workframeId | ||
}` | ||
@@ -97,8 +100,10 @@ const toolRegexp = new RegExp(options.toolRegexp, 'i') | ||
} | ||
const serves = [ | ||
const statics = [ | ||
uiPath, | ||
...(Array.isArray(options.publicDir) | ||
? options.publicDir | ||
: [options.publicDir]) | ||
].map(dir => sirv(dir, { etag: true })) | ||
: [options.publicDir] | ||
).filter(Boolean) | ||
] | ||
const serves = statics.map(dir => sirv(dir, { etag: true })) | ||
@@ -114,3 +119,3 @@ // configure a middleware for serving Atelier | ||
createReadStream(options.workframeHtml).pipe(res) | ||
} else if (!hasTrailingUrl && req.originalUrl === options.url) { | ||
} else if (!hasTrailingSlash && req.originalUrl === options.url) { | ||
// append trailing slash to allows resolving <script /> with relative sources | ||
@@ -136,3 +141,3 @@ res.statusCode = 301 | ||
if (toolRegexp.test(normalizePath(path)) || stats?.isDirectory()) { | ||
server.watcher.emit('change', `${options.url}/${options.workframeId}`) | ||
server.watcher.emit('change', workframeUrl) | ||
} | ||
@@ -148,3 +153,3 @@ } | ||
resolveId(id) { | ||
if (id === options.workframeId) { | ||
if (id === workframeUrl) { | ||
return id | ||
@@ -155,6 +160,3 @@ } | ||
async load(id) { | ||
if ( | ||
id === | ||
`${options.url}${hasTrailingUrl ? '' : '/'}${options.workframeId}` | ||
) { | ||
if (id === workframeUrl) { | ||
return buildWorkframe( | ||
@@ -161,0 +163,0 @@ await findTools(options.path, toolRegexp), |
5549
148