Va1 / browser-sync-webpack-plugin

Easily use BrowserSync in your Webpack project.
MIT License
369 stars 40 forks source link

Webpack unable to find browser-sync-webpack-plugin unless browser-sync package is installed. #95

Closed nparoski closed 1 year ago

nparoski commented 2 years ago

Hello, I was creating custom webpack config and installed browser-sync-webpack-plugin It wouldn't work at all until I installed browser-sync as dev dependecy on my project. Can anyone provide explanation? What did I misunderstand and why is browser-sync not a dependecy of browser-sync-webpack-plugin?

webpack.config.js

/// <binding />
"use strict";
var path = require("path");
var WebpackNotifierPlugin = require("webpack-notifier");
var BrowserSyncPlugin = require("browser-sync-webpack-plugin");

module.exports = {
  entry: ["babel-polyfill", "./React/src/index.js"],
  output: {
    path: path.resolve(__dirname, "./React/dist"),
    filename: "bundle.js",
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
        },
      },
      // Handles style loading
      {
        test: /\.s[ac]ss$/i,
        use: [
          // Creates `style` nodes from JS strings
          "style-loader",
          // Translates CSS into CommonJS
          "css-loader",
          // Compiles Sass to CSS
          "sass-loader",
        ],
      },
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader"],
      },
    ],
  },
  devtool: "inline-source-map",
  plugins: [new WebpackNotifierPlugin(), new BrowserSyncPlugin()],
  resolve: {
    extensions: [".js", ".jsx"],
  },
};

package.json:

{
  "name": "react-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "storybook": "start-storybook -p 6006",
    "build-storybook": "build-storybook",
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.17.10",
    "@babel/core": "^7.17.12",
    "@babel/plugin-proposal-class-properties": "^7.17.12",
    "@babel/preset-env": "^7.17.12",
    "@babel/preset-react": "^7.17.12",
    "@storybook/addon-actions": "^6.5.4",
    "@storybook/addon-essentials": "^6.5.4",
    "@storybook/addon-interactions": "^6.5.4",
    "@storybook/addon-links": "^6.5.4",
    "@storybook/builder-webpack5": "^6.5.4",
    "@storybook/manager-webpack5": "^6.5.4",
    "@storybook/react": "^6.5.4",
    "@storybook/testing-library": "^0.0.11",
    "babel-loader": "^8.2.5",
    "babel-polyfill": "^6.26.0",
    "browser-sync-webpack-plugin": "^2.3.0",
    "css-loader": "^6.7.1",
    "sass": "^1.52.0",
    "sass-loader": "^13.0.0",
    "style-loader": "^3.3.1",
    "webpack": "^5.72.1",
    "webpack-cli": "^4.9.2",
    "webpack-notifier": "^1.15.0"
  },
  "dependencies": {
    "@reduxjs/toolkit": "^1.8.1",
    "axios": "^0.27.2",
    "bootstrap": "^5.1.3",
    "lodash.clonedeep": "^4.5.0",
    "react": "^18.1.0",
    "react-datepicker": "^4.8.0",
    "react-dom": "^18.1.0",
    "react-redux": "^8.0.1"
  }
}
Va1 commented 1 year ago

this is merely a plugin for hooking up webpack and browser-sync. if this plugin would have them defined as dependencies, it would therefore enforce their versions and cause confusion. also this plugin does not refer/use the code of either of them – it is expected to be used in a project where both are already installed, as a plugin for webpack. thus they are only defined as peer dependencies. hope this helps.