昨晚要把vue push到heroku , 一直都失敗
早上起來繼續用 , 發現...
真的要會看log很重要
你就會知道 , 他是哪邊有錯誤 ; 例如找不到什麼模組 (但根本用不到)
就可以把那些用不到的程式碼殺掉 ~
heroku的vue , 就可以正常運作了
本機localhost測試不會有問題 , 但heroku會
因為server.js那些 (本機用不到)
server.js 內容
const express = require('express');
const app = express();
const cors = require('cors');
const port = process.env.PORT || 5000;
app.use(cors()); // allow core
// production settings
if (process.env.NODE_ENV === 'production') {
// this will reference the static folder compiled by Vue CLI
app.use(express.static(__dirname + '/dist/'))
// Handle MPA
app.get(/.*/, (req, res) => {
res.sendFile(__dirname + '/dist/index.html')
})
}
app.listen(port);
console.log('server started '+ port);
package.json內容
{
"name": "vue",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"start": "node server.js"
},
"dependencies": {
"axios": "^0.27.2",
"core-js": "^3.8.3",
"cors": "^2.8.5",
"express": "^4.18.1",
"vue": "^3.2.13"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-router": "~5.0.0",
"@vue/cli-plugin-vuex": "~5.0.0",
"@vue/cli-service": "~5.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
]
}
一天進步一點 , 加油 !
留言列表