node.js - 在 Express.js 项目中使用 Webpack 捆绑安装了 npm 的 Bootstrap
问题描述
我的项目的粗略结构:
project
|-- node_modules
| |-- bootstrap
| |-- jquery
| |-- popper.js
|
|-- dist
|
|-- public
| |-- js
| | |-- scripts.js
| |
| |-- css
| |-- styles.css
|
|-- views
| |-- index.ejs
|
|-- app.js
我需要在我bootstrap
的. 如果涉及到 bootstrap,我可以使用它,但我想专门用于将我可能需要的所有内容捆绑到一个文件中,并确保它包含在我的文件中 - 自动(我知道 webpack 具有此功能)或只是确保存在于并在我的.public
index.ejs
CDN
Webpack
dist
index.ejs
bundle.js
dist
<link>
<script>
index.ejs
我想确保所有东西都被捆绑在一起——我不想在我的index.ejs
.
我将不胜感激,因为我找不到有关如何实现这一目标的指南或任何建议。我想这里的主要问题是 - 我应该如何构建webpack.config.js
?
app.js
是我的入口文件,它包含以下代码:
const bodyParser = require('body-parser');
const express = require('express');
const path = require('path');
const indexRoutes = require('./routes/index');
const app = express();
const port = process.env.PORT || 3000;
app.set('view engine', 'ejs');
app.set('views', path.resolve(__dirname, 'views'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.resolve(__dirname, 'public')));
app.use('/', indexRoutes);
app.listen(port);
当前内容webpack.config.js
:
const path = require('path');
module.exports = {
entry: {
app: path.resolve(__dirname, 'app.js'),
},
mode: 'development',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
};
解决方案
推荐阅读
- docker - 我可以通过内部 url 访问 docker 启动的服务吗?
- c++11 - C++:如何使用 lldb 调试“总线错误”?
- java - 选择项目时,Spinner 的 OnItemSelectedListener 不调用
- sql - 为什么“=”运算符在 SQL 查询中没有给出预期的结果?
- javascript - 将 SVG 组件作为背景图像反应到 div
- rxjs - Angular & RXJS - [ts] 属性 'map' 在类型'Observable 上不存在
' - ghostscript.net - 使用 Ghostscript 生成的输出 Tiff 文件中显示的位深度不正确
- php - 尽管使用了默认排序规则,但带有 UTF8 列的 PDO MySQL (MariaDB) 查询不区分大小写
- applescript - 如何在进程“Safari”和应用程序“Safari”之间获得相同的窗口?
- ios - 如何在一个视图控制器中切换不同的视图