Browse Source

在production环境下外部构建

wangdy 8 years ago
parent
commit
bf9e75aed8
3 changed files with 10 additions and 15 deletions
  1. 1 1
      plugins/axios.js
  2. 1 0
      run.sh
  3. 8 14
      server.js

+ 1 - 1
plugins/axios.js

@@ -4,7 +4,7 @@ import store from '~store'
 
 const service = axios.create({
   withCredentials: true,
-  baseURL: process.env.proxyUrl || process.env.baseUrl
+  baseURL: '/'
 })
 
 service.interceptors.request.use(config => {

+ 1 - 0
run.sh

@@ -4,6 +4,7 @@ echo "NODE_ENV: $NODE_ENV"
 echo "BASE_URL: $BASE_URL"
 
 if [ "$NODE_ENV" == 'production' ]; then
+  npm run build
   npm run start
 else
   npm run dev-start

+ 8 - 14
server.js

@@ -57,20 +57,14 @@ const nuxt = new Nuxt(config)
 app.use(nuxt.render)
 
 // Build only in dev mode
-// if (config.dev) {
-//   nuxt.build()
-//     .catch((error) => {
-//       // eslint-disable-line no-console
-//       console.error(error)
-//       process.exit(1)
-//     })
-// }
-nuxt.build()
-  .catch((error) => {
-    // eslint-disable-line no-console
-    console.error(error)
-    process.exit(1)
-  })
+if (config.dev) {
+  nuxt.build()
+    .catch((error) => {
+      // eslint-disable-line no-console
+      console.error(error)
+      process.exit(1)
+    })
+}
 
 // Listen the server
 app.listen(port)