Skip to content

Commit

Permalink
fix: 修复 webpack 构建 publicPath 使用相对路径,导致 css 里面依赖资源路径异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt committed Mar 8, 2024
1 parent 81e503b commit e0e73f9
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 96 deletions.
6 changes: 3 additions & 3 deletions packages/fes-builder-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
"html-webpack-tags-plugin": "^3.0.0",
"less": "^4.1.3",
"less-loader": "^11.1.0",
"mini-css-extract-plugin": "^2.7.5",
"mini-css-extract-plugin": "^2.8.1",
"postcss": "^8.4.33",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-loader": "^7.1.0",
"postcss-safe-parser": "^6.0.0",
"style-loader": "^3.3.2",
"terser-webpack-plugin": "^5.3.6",
"vue-loader": "^17.0.1",
"webpack": "^5.87.0",
"vue-loader": "^17.4.2",
"webpack": "^5.90.3",
"webpack-5-chain": "^8.0.1",
"webpack-bundle-analyzer": "^4.4.0",
"webpack-dev-server": "^4.15.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ function createRules({ isDev, webpackConfig, config, lang, test, loader, options
function applyLoaders(rule, cssLoaderOption = {}) {
if (isDev || !config.extraCSS) {
rule.use('extra-css-loader').loader(require.resolve('style-loader')).options(Object.assign({}, styleLoaderOption));
} else {
}
else {
const loaderOptions = config.extraCSS?.loader ?? {};

if (!loaderOptions.publicPath && config.publicPath.startsWith('./')) {
loaderOptions.publicPath = '../';
}
rule.use('extra-css-loader')
.loader(require('mini-css-extract-plugin').loader)
.options(config.extraCSS?.loader ?? {});
.options(loaderOptions);
}

rule.use('css-loader')
Expand Down
1 change: 0 additions & 1 deletion packages/fes-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@fesjs/plugin-sass": "workspace:*",
"@fesjs/plugin-swc": "workspace:*",
"@fesjs/plugin-watermark": "workspace:*",
"@fesjs/plugin-windicss": "workspace:*",
"core-js": "3.29.1",
"pinia": "^2.0.33",
"vue": "^3.2.47"
Expand Down
4 changes: 4 additions & 0 deletions packages/fes-template/src/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.page {
height: 1000px;
background-image: url('~@/images/hello.png');
}
5 changes: 0 additions & 5 deletions packages/fes-template/src/global.scss

This file was deleted.

Binary file added packages/fes-template/src/images/hello.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/fes-template/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ function go() {
}
</script>

<style>
<style lang="less">
.page {
height: 1000px;
background-image: url('@/images/hello.png');
}
</style>
Loading

0 comments on commit e0e73f9

Please sign in to comment.