问题: 使用elementui后,Vue 项目打包后,对应的图标不显示,只有一个小方块。
解决方法: 修改build/utils.js 文件,新增publicPath 配置项 publicPath: '../../'
。
// generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) {
const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
})
}
// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
fallback: 'vue-style-loader',
publicPath: '../../' // new edit
})
} else {
return ['vue-style-loader'].concat(loaders)
}
}
备注: 该方法适用Vue Cli2版本