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 Jan 10, 2023
1 parent 2ea80c0 commit b0c0913
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 @@ -77,3 +77,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 . '../assets/blog' --cwd=./public",
"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 @@ -220,7 +220,7 @@ export const createWebpackUtils = (
ROUTES_DIRECTORY,
`public`
)
fileLoaderCommonOptions.publicPath = `/`
fileLoaderCommonOptions.publicPath = publicPath || `/`
}

const loaders: ILoaderUtils = {
Expand Down

0 comments on commit b0c0913

Please sign in to comment.