webpack 3 零基础入门教程 #5
之前我们已经可以转化 js 文件了,但是一般来说,我们放在网页上的是 html 页面。 现在我们就把 html 和 js 还有 webpack 结合来玩玩。 很简单,只要把 js 文件引入到 html 中就好。 1. 创建 index.html 首先在 dist 目录下创建 index.html 文件,其内容如下: <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>Project </title> </head> <body> <script src= "app.bundle.js" ></script> </body> </html> 这样,你在服务器上把这个 index.html 和 app.bundle.js 放到网站根目录中,用 nginx 托管起来,就可以用了。 前端的项目不就是这样处理的吗? 但是,我一般不会这么做,我会用更好的方式来处理这个问题。 为什么呢? 因为 index.html 文件太死了,连 js 文件都写死了,有时候引用的 js 文件是动态变化的呢? 打个比方,类似下面这种例子: <script src= "app.bundle1.js" ></script> <script src= "app.bundle2.js" ></script> <script