很簡單不復雜只須要幾步
一、找到項目的 webpack環境配置的config目錄下的index.js文件的assetsPublicPath把"/"改爲 "./"
得出: build: {
env: require('./prod.env'),
index: path.resolve(dirname, '../dist/index.html'),
assetsRoot: path.resolve(dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',//這個就是剛剛修改的
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to true
, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css']
....
}
二、找到biuld目錄下的utils文件修改爲 publicPath:'../../'
三、修改路由router目錄下的文件
router = new VueRoter({
mode: 'history',
base: '/aaa/', //aaa 就是服務器Tomact相對於根目錄的名稱 在此目錄放的就是 static 和 index.html文件 這兩文件你是項目打包生成的dist文件只要copy過來就能成功部署在服務器上進行訪問了
routes:[{
path:'./',
name:'',
component:'''
....省略
}]
)}css