html本地修改浏览器自动更新,当index.html更改时浏览器自动重新加载

我终于绊倒了html-webpack-plugin如in this guide所述。

我运行:

npm i -D html-webpack-plugin

和编辑我webpack.config.js看起来像这样:

'use strict';

const path = require('path');

const APPDIR = 'app/';

const HtmlWebpackPlugin = require('html-webpack-plugin');

const HTMLWebpackPluginConfig = new HtmlWebpackPlugin({

template: path.resolve(__dirname, APPDIR, 'index.html'),

filename: 'index.html',

inject: 'body'

});

const config = {

context: path.resolve(__dirname, APPDIR),

entry: './main.js',

output: {

path: path.resolve(__dirname, 'build'),

filename: 'bundle.js'

},

module: {

loaders: [

{

test: /\.js$/,

loader: 'babel',

include: path.resolve(__dirname, 'app/')

},{

test: /\.css$/,

loaders: ['style', 'css']

}

]

},

plugins: [HTMLWebpackPluginConfig]

};

module.exports = config;

“模板” index.html文件现在驻留在我的app目录,并在建立项目生成的index.html文件被放置在build目录中。后者文件包含对捆绑输出文件bundle.js的正确引用(这是两个文件之间的唯一区别)。

“模板” 的index.html文件中应用:运行webpack-dev-server时

现在:

生成的输出的index.html文件中构建更改为index.html也会立即在br中刷新owser。 这就是说,index.html是如此之小,编辑它并希望编辑自动刷新浏览器的用例似乎微不足道。 尽管如此,感觉更好的是index.html驻留在我的app目录中,而不是build目录。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值