Mithril Mithril - 4 months ago 7
Node.js Question

How to make <script src="some_path/bootstrap.js"> work on webpack server?

I just want to test if bootstrap work good with my react app. (I am using a boilerplate which already contain webpack)

I could use bootstrap by import the files at webpack entry which learned from how-to-use-webpack-with-react-and-bootstrap:


  1. install some node packages to cope files with different type

  2. edit
    webpack.config.js
    to let it use above installed packages



But, I just want to have a try, and I think it make build slow if bundle other js lib into
bundle.js
(I need hot load, so not expect webpack bundle all).

Now, I write code like:

<!doctype html>
<html>
<head>
<title>test</title>
<script type="text/javascript" src="res/bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="res/bootstrap/css/bootstrap.min.css">
</head>
<body>
<div id="root"></div>
<script src="/static/bundle.js"></script>
</body>
</html>


The content of
bootstrap.min.js
and
bootstrap.min.css
is empty.

I have tried to change the path from
"res/bootstrap/js/bootstrap.min.js"
to
"src/res/bootstrap/js/bootstrap.min.js"
, but not work.

Also try to set
resolve
in webpack config by Resolving require paths with webpack, it result to another error like
Cannot resolve module 'react'


I know I may mistake root path or miss some config, but can't figure it out,
what should I do?

Answer

OK, a little late to post answer, the problem is by express.The project I forked is use express to start webpack project, it does contain webpack.dev.config.js which make me think it is using a webpack devserver.

I understand the problem as soon as see this :

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'index.html'));
});

I didn't care how the base project started before. It used express, not webpack devserver, just a simple route problem.

change to below work,

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'index.html'));
});

One complain: does nodejs devs like to set * router ?

Comments