多包./src/index.js ./dist/bundle.js中的webpack错误

loo*_*4me 9 webpack

配置中的警告尚未设置"模式"选项.将"mode"选项设置为"development"或"production"以启用此环境的默认值.多个./src/index.js ./dist/bundle.js中的错误

Nev*_*ung 35

以下是webpack通过在webpack 4中键入webpack --help的帮助消息

Usage without config file: webpack <entry> [<entry>] --output [-o] <output>
Run Code Online (Sandbox Code Playgroud)

注意: - 输出需要明确指定


解:

webpack src/index.js --output dist/bundle.js --mode development
Run Code Online (Sandbox Code Playgroud)

添加 - 输出就可以了.


kar*_*tos 1

我不确定这里的确切问题是什么,但我也有这个警告,并通过modeWebpack 配置文件中设置属性来解决它们

包.json

    {
      "name": "my-awesome-project",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "build": "NODE_ENV=production webpack",
      },
      ...
      "devDependencies": {
       ...
      },
      "dependencies": {
       ...
      }
    }
Run Code Online (Sandbox Code Playgroud)

webpack.config.js

const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');

const distDir = path.join(__dirname, 'dist');

const config = {
  mode: 'development',
  entry: ['./src/js/app.js'],
  output: {
    path: distDir,
    filename: 'js/[name].js',
  },
  module: {
    rules: [
      ...
    ]
  },
  plugins: [
    ...
  ],
  devtool: "eval-source-map", // Default development sourcemap
};

// Check if build is running in production mode, then change the sourcemap type
if (process.env.NODE_ENV === 'production') {
  config.devtool = ''; // No sourcemap for production
  config.mode = 'production';

  // Add more configuration for production here like
  // Uglify plugin
  // Offline plugin
  // Etc,
}

module.exports = config;
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你。