markdown 使用Browsersync和Webpack进行设置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 使用Browsersync和Webpack进行设置相关的知识,希望对你有一定的参考价值。

### Fixing our local environment with Browsersync

Whenever we change our templates we still have to use our build script and this can get annoying. Thankfully with `webpack-dev-server` and BrowserSync we can fix this:

```
npm i -D browser-sync browser-sync-webpack-plugin webpack-dev-server
```

BrowserSync will act like a proxy, waiting for webpack to do its thing and then reloading the browser for us. 

We’ll need to include it in our `webpack.config.js`: 

```
var BrowserSyncPlugin = require('browser-sync-webpack-plugin')
```

And then add it to our plugins at the bottom of the same file:

```
plugins: [
    new ExtractTextPlugin("styles.css"),
    new StaticSiteGeneratorPlugin('main', data.routes, data),
    new BrowserSyncPlugin({
        host: 'localhost',
        port: 3000,
        proxy: 'http://localhost:8080/'
    })
]
```

Now we can update our `package.json` script:

```
"scripts": {
	"dev": "webpack-dev-server --progress --colors",
	"start": "webpack && npm run dev"
},
```

So when we run our `npm start` command BrowserSync will open up our browser and refresh itself whenever we change a component.

以上是关于markdown 使用Browsersync和Webpack进行设置的主要内容,如果未能解决你的问题,请参考以下文章

markdown Abrir隧道pelo browsersync

markdown Gulp,Stylus,Browsersync,JS Uglify

gulp 和 Browsersync 的联合使用

Browsersync 简介 and 使用

browserSync.reload 和 browserSync.stream()) - 有啥区别?

没有 gulp 的 Express 和 BrowserSync?