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等资源文件就好用了
标签:Vue,return,Tomcat,loaders,loader,报错,js,extract,options 来源: https://blog.csdn.net/qq_35562291/article/details/89882047