npm run dev 有效
写的组件能插入
但是build后 本地测试却只有一个单index文件
exp
文件目录:
/--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');
});
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
build后应该放到服务环境下运行,直接打开无效,可以在本地搭建apache服务。
默认vue-cli构建的项目,build出来的是dist目录,index.html中的所有css js都需要手动修改下链接才能通过file://方式打开