Skip to content

Commit

Permalink
🐛 Fix loading assets in dev-middleware from deep paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Steel Brain committed Sep 6, 2018
1 parent 0b60469 commit d7d8972
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/pundle-chunk-generator-js/src/wrapper/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (!global.sbPundle) {
let sbPundleServer = ''
if (typeof document !== 'undefined' && document.currentScript) {
const parsed = new URL(document.currentScript.src)
sbPundleServer = `${parsed.protocol}//${parsed.host}/`
sbPundleServer = `${parsed.protocol}//${parsed.host}`
}

const sbPundleCache = sbPundle.cache
Expand Down
4 changes: 3 additions & 1 deletion packages/pundle-dev-middleware/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { getPundleConfig } from 'pundle-core'
import { getFileKey, type Job, type Chunk, type ImportResolved } from 'pundle-api'

export async function getOutputFormats(pundleOptions: Object, publicPath: string): { [string]: string | false } {
invariant(publicPath.length, 'publicPath must never be empty')

const pundleConfig = await getPundleConfig(pundleOptions)
const { formats } = pundleConfig.output

const newFormats = {}
Object.keys(formats).forEach(function(key) {
const value = formats[key]
const value: string | false = formats[key]
if (value) {
newFormats[key] = path.join(publicPath, value)
} else {
Expand Down
8 changes: 2 additions & 6 deletions packages/pundle-dev-middleware/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function getPundleDevMiddleware(options: Payload) {
const router = new Router()

let { publicPath = '/' } = options
if (publicPath.endsWith('/')) {
if (publicPath.length > 1 && publicPath.endsWith('/')) {
publicPath = publicPath.slice(0, -1)
}
const pundleOptions = pick(options, PUNDLE_OPTIONS)
Expand Down Expand Up @@ -225,10 +225,6 @@ async function getPundleDevMiddleware(options: Payload) {

if (!pathname) return

if (pathname.startsWith('/')) {
pathname = pathname.slice(1)
}

if (pathname.endsWith('.pundle.hmr')) {
res.write(JSON.stringify({ type: 'status', enabled: !!options.hmr }))
if (!options.hmr) {
Expand All @@ -244,7 +240,7 @@ async function getPundleDevMiddleware(options: Payload) {
return
}

if (pathname.endsWith('/') || pathname === '') {
if (pathname.endsWith('/')) {
pathname = `${pathname}index`
}

Expand Down

0 comments on commit d7d8972

Please sign in to comment.