Vue-element-admin: 如何去设置publicPath?

Created on 9 Oct 2018  ·  6Comments  ·  Source: PanJiaChen/vue-element-admin

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

Most helpful comment

这样即可:

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')
}

}

All 6 comments

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

我常规做法还是用alias。

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

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

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

这样即可:

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')
}

}

Was this page helpful?
0 / 5 - 0 ratings