Vue 部署到Tomcat资源报错问题解决

首先 bulid文件夹下

	找到 webpack.prod.conf.js 文件
	 output: {
path: config.build.assetsRoot,
filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js') },  中 加入一句  publicPath:'./',
修改后
 output: {
publicPath:'./',
path: config.build.assetsRoot,
filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')},

其次 在bulid文件夹下 Utils.js文件中
找到

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
    })
  })
  if(options.extract){
    return ExtractTextPlugin.extract({
      use:loader,
    
      fallback:'vue-style-loader'
    })
  }else {
    return ['vue-style-loader'].concat(loaders)
  }
}

// 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'
  })
} else {
  return ['vue-style-loader'].concat(loaders)
} }


return ExtractTextPlugin.extract({
use:loader,
fallback:‘vue-style-loader’
})
加入

      publicPath:"../../",

修改后

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
    })
  })
  if(options.extract){
    return ExtractTextPlugin.extract({
      use:loader,
      publicPath:"../../",
      fallback:'vue-style-loader'
    })
  }else {
    return ['vue-style-loader'].concat(loaders)
  }
}

// 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'
  })
} else {
  return ['vue-style-loader'].concat(loaders)
}

}

之后 Vue 的js css等资源文件就好用了

上一篇:cookie转为字典


下一篇:scrapy 爬取指定贴吧