使用 webpack 发布 运行 yarn watch

Issue running yarn watch with webpack

我正在做一个项目,第一次使用 webpack。我运行进入一个问题运行yarn watch。这是我在 webpage.config.js 中的代码:

const path = require('path');

// include the js minification plugin
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

// include the css extraction and minification plugins
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");

module.exports = {
  entry: ['./src/js/site.js', './src/scss/style.scss'],
  output: {
    filename: './dist/js/site.min.js',
    path: path.resolve(__dirname)
  },
  module: {
    rules: [
      // perform js babelization on all .js files
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
          presets: ['babel-preset-env']
          }
        }
      },
      // compile all .scss files to plain old css
      {
        test: /\.(sass|scss)$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader']
      }
    ]
  },
  plugins: [
    // extract css into dedicated file
    new MiniCssExtractPlugin({
      filename: './dist/css/style.min.css',
      path: path.resolve(__dirname)
    })
  ],
  optimization: {
    minimizer: [
      // enable the js minification plugin
      new UglifyJSPlugin({
        cache: true,
        parallel: true
      }),
      // enable the css minification plugin
      new OptimizeCSSAssetsPlugin({})
    ]
  }
};

在 运行 中,我遇到了一些错误。第一个说:

Insufficient number of arguments or no entry found

然后另一个出现说:

ERROR in Entry module not found: Error: Can't resolve './src' in 'FOLDER_NAME_HERE' error Command failed with exit code 2.

这也是我的 package.json 文件:

{
  "name": "project name",
  "version": "1.0.0",
  "description": "project description",
  "scripts": {
    "build": "webpack --mode development",
    "dist": "webpack --mode production",
    "watch": "webpack --watch --mode development"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.4",
    "babel-preset-env": "^1.7.0",
    "css-loader": "^1.0.0",
    "imagemin-cli": "^3.0.0",
    "mini-css-extract-plugin": "^0.4.4",
    "node-sass": "^4.9.3",
    "npm-run-all": "^4.1.3",
    "optimize-css-assets-webpack-plugin": "^5.0.1",
    "sass-loader": "^7.1.0",
    "uglifyjs-webpack-plugin": "^2.0.1",
    "webpack": "^4.20.2",
    "webpack-cli": "^3.1.2"
  },
  "author": "Me",
  "license": "MIT"
}

我做了一些搜索,在 Github 上找到了一些关于此的内容,但没有真正的解决方案。我有一个“/src”文件夹,所以除非文件路径不正确,否则错误说它无法解析“./src”是没有意义的(我已经尝试了所有其他可能性只是为了测试它,什么我现在拥有的是原来的样子)。非常感谢任何帮助。

"watch": "webpack --watch --mode development --config ./path/to/my/webpack/config"

你没有说要查找哪个配置...你必须说出来