Home > Web Front-end > JS Tutorial > body text

How to package vue project into static file

一个新手
Release: 2017-09-07 13:16:37
Original
3037 people have browsed it

How to package the vue project into a static file

Packaging

1. Modify the productionSourceMap in index.js in the config to false. The default is true (true means that the packaging environment is development environment, which can be debugged; false indicates the production environment, which is officially online)

2. Run npm run build in cmd, (the build.js file in build is run)

Generate The package is placed under dist

Use node for debugging

1. Create the prod.server.js file in the root directory , this file functions as a small httpserver. Under normal development, you can directly put the files in dist into tomcat for debugging

prod.server.js code



 /**  * Created by Administrator on 2017/2/22.  */
 var express = require('express') var config = require('./config/index') 
 var port = process.env.PORT || config.build.port 
 var app= express() 
 var router = express.Router() 
 router.get('/',function (req, res, next) {   
 req.url = '/index.html'   next() }) 
 app.use(router) 
 //异步接口
 var seller=require('./src/data/data.json')
 var apiRoutes = express.Router()
 apiRoutes.get('/seller',function (req,res) {
  res.json({    
      data:seller  })
}) 
app.use('/api', apiRoutes);  //定义express静态目录 
app.use(express.static('./dist'))  
var autoOpenBrowser = !!config.dev.autoOpenBrowser 
var uri = 'http://localhost:' + port var opn = require('opn') //启动express module.exports = app.listen(port, function (err) {   if (err) {     console.log(err)     return   }    // when env is testing, don't need open it   
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {     
opn(uri)   
} 
})
Copy after login

The above is the detailed content of How to package vue project into static file. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!