打包部署生產環境之前需要修改配置文件:
修改一:build > utils.js (修改publicPath:"../../" , 這樣寫是處理打包后找不到靜態文件的問題)
// 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: '../../'
})
} else {
return ['vue-style-loader'].concat(loaders)
}
修改二:config > index.js (修改assetsPublicPath:'./' ,修改目的是為了解決js找不到的問題)
// Template for index.html index: path.resolve(__dirname, '../dist/index.html'), // Paths assetsRoot: path.resolve(__dirname, '../dist'), assetsSubDirectory: 'static', assetsPublicPath: './',
3.運行命令:npm run build 打包直接訪問dist文件夾中的index.html即可。