当我运行“ ng build”时,我注意到它创建了这样的文件夹结构。
/ dist / projectname /
然后将生成projectname文件夹中的所有文件。
当我运行Angular应用程序时,对于索引文件中的第一个脚本,出现404(未找到)错误。
<body>
<app-root></app-root>
<script src="runtime-es2015.js" type="module"></script>
<script src="runtime-es5.js" nomodule defer></script>
<script src="polyfills-es5.js" nomodule defer></script>
<script src="polyfills-es2015.js" type="module"></script>
<script src="styles-es2015.js" type="module"></script>
<script src="styles-es5.js" nomodule defer></script>
<script src="vendor-es2015.js" type="module"></script>
<script src="vendor-es5.js" nomodule defer></script>
<script src="main-es2015.js" type="module"></script>
<script src="main-es5.js" nomodule defer></script>
</body>
另外,这里是我的server.js文件,因为我觉得这是问题所在。
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const http = require('http');
const app = express();
const api = require('./server/routes/api');
// Parsers
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'dist')));
app.use('/api', api);
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/clinic-manager/index.html'));
});
// Set Port
const port = process.env.PORT || '3000';
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log(`Running on localhost:${port}`));
感谢您提供任何帮助!
我找到了!!
转到angular.json文件,并将“ outputPath”:更改为“ dist”,而不是“ dist / projectname”。