Skip to content

Commit

Permalink
fix(bundler-webpack): Fix runtimePublicPath effects assets url in css…
Browse files Browse the repository at this point in the history
… file (#832)

* fix(bundler-webpack): Fix runtimePublicPath effects assets url in css file

* fix(bundler-webpack): Add test

* fix(bundler-webpack): code format
  • Loading branch information
yuaanlin authored and sorrycc committed Jun 23, 2022
1 parent 64c0a25 commit 9f6abc0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/bundler-webpack/src/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ const expects: Record<string, Function> = {
'postcss-flexbugs-fixes'({ files }: IOpts) {
expect(files['index.css']).toContain(`.foo { flex: 1 1; }`);
},
'runtime-public-path'({ files }: IOpts) {
expect(files['index.css']).toContain(`background: url(./static/`);
},
svgo({ files }: IOpts) {
expect(files['static']).toContain(EXISTS);
expect(files['index.js']).toContain(`.svg`);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
runtimePublicPath: {}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: url("./bg.jpg");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './index.css';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export class RuntimePublicPathPlugin {
// The hook to get the public path ('__webpack_require__.p')
// https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
if (module.constructor.name === 'PublicPathRuntimeModule') {
// If current public path is handled by mini-css-extract-plugin, skip it
if (module.getGeneratedCode().includes('webpack:///mini-css-extract-plugin'))
return;
// @ts-ignore
module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath || '/';`;
}
Expand Down

0 comments on commit 9f6abc0

Please sign in to comment.