reactjs - Why do I have to put bundle.js script in html when running webpack-dev-server -


i'm running webpack-dev-server package.json script.

when don't put tag in index.html, bundle not being loaded when webpack-dev-server should put there automatically.

my code looks this:

<body>   <div id="my-app"></div>   <script src="bundle.js"></script>   <script type="text/javascript" src="app.bundle.aa2801db8d757c2f2d78.js"></script> </body> 

i put first bundle there when running webpack-dev-server , second bundle got generated htmlwebpackplugin when built project production. want rid of first bundle in production code.

thanks suggestions.

you need reference javascript bundle html, because not inserted there automatically.

you can use htmlwebpackplugin have bundle reference added automatically. it's added plugins section of webpack.config.js file this:

const webpack = require("webpack"); const htmlwebpackplugin = require("html-webpack-plugin");  module.exports = {     entry: "./source/index.js",     module: {         // keep rules you've got     },     plugins: [         new htmlwebpackplugin({             template: "./index.html"         }),         // ... keep other plugins here...     ] } 

make sure value of template points html file...

source: code taken my webpack project template on github. can see full configuration files , more explanatory text there.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -