Mithril Mithril - 1 year ago 75
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
    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
(I need hot load, so not expect webpack bundle all).

Now, I write code like:

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

The content of
is empty.

I have tried to change the path from
, but not work.

Also try to set
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 Source

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 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 ?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download