browser-sync-webpack-plugin无法正常工作

时间:2018-05-23 17:00:00

标签: javascript node.js webpack browser-sync

我按照https://www.npmjs.com/package/browser-sync-webpack-plugin

的指示对其进行了配置

这是我的webpack.config.js文件

const path = require('path');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');

const config = {
  mode: 'production',
  entry: './src/app.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  watch: true,
  plugins: [
    new BrowserSyncPlugin({
      host: 'localhost',
      port: 3000,
      server: {
        baseDir: ['dist']
      }
    })
  ]
}

module.exports = config;

的package.json

{
  "name": "real-estate-2",
  "private": true,
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack --config webpack.config.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "browser-sync-webpack-plugin": "^2.2.2",
    "webpack": "^4.8.3",
    "webpack-cli": "^2.1.3"
  },
  "dependencies": {
    "lodash": "^4.17.10",
    "react": "^16.3.2",
    "react-dom": "^16.3.2"
  }
}

但是当我运行webpack时,我在终端上遇到了这个错误: 错误:无法找到模块' browser-sync-webpack-plugin'

我按照说明安装了browser-sync-webpack-plugin:npm install --save-dev browser-sync-webpack-plugin

1 个答案:

答案 0 :(得分:0)

npm install --save-dev browser-sync