0

npm run dev 有效
写的组件能插入
但是build后 本地测试却只有一个单index文件

<!DOCTYPE html>
<html>

<head>
    <meta charset=utf-8>
    <title>exp</title>
    <link href=/static/css/app.dfca11727ccf9e74f393b0c223db19ce.css rel=stylesheet>
</head>

<body>
    <div id=app></div>
    <script type=text/javascript src=/static/js/manifest.8b2730109200b8e8f8a7.js></script>
    <script type=text/javascript src=/static/js/vendor.4637c3c2f43169eeb3fd.js></script>
    <script type=text/javascript src=/static/js/app.a0ac06dfefc13fa202d2.js></script>
</body>

</html>

文件目录:

/--build
 --config
 --dist
   |-static
   |-index.html
 --server
   |-app.js  后端   
 --src  vue目录
 --index.html   

后端代码:

const express = require('express');
const fs = require('fs');
const path = require('path');
const bodyParser = require('body-parser');

const router = require('./router.js');

let resolve = file => path.resolve(__dirname, file);


const app = express();

app.use(bodyParser.json());
app.use('/dist', express.static(resolve('../dist')))
app.use(router);

app.get('*', function(req, res) {
    let html = fs.readFileSync(resolve('../dist/index.html'), 'utf-8');
    res.send(html);
})

app.listen(3000, function() {
    console.log('server is running on: 3000');
});

查看全部 2 个回答

0

默认vue-cli构建的项目,build出来的是dist目录,index.html中的所有css js都需要手动修改下链接才能通过file://方式打开

推荐答案

0

已采纳

build后应该放到服务环境下运行,直接打开无效,可以在本地搭建apache服务。