webpack-dev-server 配置
1,安装需要的包
npm install --save-dev webpack webpack-dev-server
2,配置添加
output: { filename: 'bundle.js', //this is the default name, so you can skip it //at this directory our bundle file will be available //make sure port 8090 is used when launching webpack-dev-server publicPath: 'http://localhost:8090/assets' //重点在这里 },
3,安装 http-server
npm install --save-dev http-server
4,页面添加启动脚本
<!DOCTYPE html> <html> <head> <title>Basic Property Grid</title> <!-- include react --> <script src="./node_modules/react/dist/react-with-addons.js"></script> </head> <body> <div id="content"> <!-- this is where the root react component will get rendered --> </div> <!-- include the webpack-dev-server script so our scripts get reloaded when we make a change --> <!-- we'll run the webpack dev server on port 8090, so make sure it is correct --> <script src="http://localhost:8090/webpack-dev-server.js"></script> <!-- include the bundle that contains all our scripts, produced by webpack --> <!-- the bundle is served by the webpack-dev-server, so serve it also from localhost:8090 --> <script type="text/javascript" src="http://localhost:8090/assets/bundle.js"></script> </body> </html>
版权声明
由 davidzhang创作并维护的 Gowhich博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证。
本文首发于 博客( https://www.gowhich.com ),版权所有,侵权必究。
本文永久链接: https://www.gowhich.com/blog/696
版权声明
由 davidzhang创作并维护的 Gowhich博客采用创作共用保留署名-非商业-禁止演绎4.0国际许可证。
本文首发于 Gowhich博客( https://www.gowhich.com ),版权所有,侵权必究。
本文永久链接: https://www.gowhich.com/blog/696