Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何去设置publicPath? #1164

Closed
LuoChengIo opened this issue Oct 9, 2018 · 6 comments
Closed

如何去设置publicPath? #1164

LuoChengIo opened this issue Oct 9, 2018 · 6 comments

Comments

@LuoChengIo
Copy link

由于项目没有放到根目录,样式文件里面的背景图片打包后有问题
image
在webpack3中可以这样设置
image
升级到webpack4后我尝试这样配置,但是无效
image
请问该如何配置呢,非常谢谢

@LuoChengIo LuoChengIo reopened this Oct 9, 2018
@LuoChengIo
Copy link
Author

不好意思,我知道怎么改了。。。。

@PanJiaChen
Copy link
Owner

我常规做法还是用alias。

background: url('~@/assets/401_images/401.gif');

@Yanhongliang100
Copy link

怎么改### 能贴一下代码吗?谢谢

@PanJiaChen
Copy link
Owner

@LuoChengIo vuejs/vue-loader#481

@LuoChengIo
Copy link
Author

@Yanhongliang100 我并不是背景图片问题,我是项目没有放到服务器根目录导致的问题,我最终是修改了config里面的index.js
image
把这里改成项目放在服务器的文件夹名称就好了

@tomatobybike
Copy link

这样即可:

const MiniCssExtractPluginLoader = {
loader: MiniCssExtractPlugin.loader,
options: {
// you can specify a publicPath here
// by default it use publicPath in webpackOptions.output
publicPath: '../../'
}
}

// generate loader string to be used with extract text plugin
function generateLoaders(loader, loaderOptions) {
const loaders = []

// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
  loaders.push(MiniCssExtractPluginLoader)
} else {
  loaders.push('vue-style-loader')
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants