Skip to content

Commit

Permalink
fix(gatsby): Restore asset, path prefix for file-loader handled files (
Browse files Browse the repository at this point in the history
  • Loading branch information
tyhopp authored and pastepi committed Dec 16, 2023
1 parent 8a80e16 commit afb2af9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions e2e-tests/path-prefix/cypress/integration/asset-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ describe(`assetPrefix`, () => {
})
})
})

describe(`assetPrefix with assets handled by file-loader`, () => {
beforeEach(() => {
cy.visit(`/file-loader/`).waitForRouteChange()
})

it(`prefixes an asset`, () => {
assetPrefixMatcher(cy.getTestElement(`file-loader-image`), `src`)
})
})
12 changes: 12 additions & 0 deletions e2e-tests/path-prefix/cypress/integration/path-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,15 @@ describe(`Production pathPrefix`, () => {
cy.getTestElement(`server-data`).contains(`foo`)
})
})

describe(`pathPrefix with assets handled by file-loader`, () => {
beforeEach(() => {
cy.visit(`/file-loader/`).waitForRouteChange()
})

it(`prefixes an asset`, () => {
cy.getTestElement(`file-loader-image`)
.invoke(`attr`, `src`)
.should(`include`, withTrailingSlash(pathPrefix))
})
})
2 changes: 2 additions & 0 deletions e2e-tests/path-prefix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
],
"license": "MIT",
"scripts": {
"clean": "gatsby clean",
"prebuild": "del-cli -f assets && make-dir assets/blog",
"build": "cross-env CYPRESS_SUPPORT=y gatsby build --prefix-paths",
"postbuild": "cpy --cwd=./public --parents '**/*' '../assets/blog'",
"develop": "gatsby develop",
"format": "prettier --write '**/*.js'",
"test": "npm run build && npm run start-server-and-test",
"start-server-and-test": "start-server-and-test serve \"http://localhost:9000/blog/|http://localhost:9001/blog/\" cy:run",
"start-server-and-test:locally": "start-server-and-test serve \"http://localhost:9000/blog/|http://localhost:9001/blog/\" cy:open",
"serve": "npm-run-all --parallel serve:*",
"serve:site": "gatsby serve --prefix-paths",
"serve:assets": "node scripts/serve.js",
Expand Down
8 changes: 8 additions & 0 deletions e2e-tests/path-prefix/src/pages/file-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as React from "react"

// Test files that are handled by file-loader
import logo from "../images/citrus-fruits.jpg"

export default function FileLoaderPage() {
return <img src={logo} alt="Citrus fruits" data-testid="file-loader-image" />
}
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/webpack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const createWebpackUtils = (
ROUTES_DIRECTORY,
`public`
)
fileLoaderCommonOptions.publicPath = `/`
fileLoaderCommonOptions.publicPath = publicPath || `/`
}

const loaders: ILoaderUtils = {
Expand Down

0 comments on commit afb2af9

Please sign in to comment.