Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack multi./src/index.js./dist/bundle.js中的网页包错误_Webpack - Fatal编程技术网

Webpack multi./src/index.js./dist/bundle.js中的网页包错误

Webpack multi./src/index.js./dist/bundle.js中的网页包错误,webpack,Webpack,配置中的警告 尚未设置“模式”选项。将“模式”选项设置为“开发”或“生产”,以启用此环境的默认设置。 multi./src/index.js./dist/bundle.js中出现错误我不确定这里的确切问题是什么,但我也遇到了这个警告,并通过在Webpack配置文件中设置mode属性解决了它们 package.json { "name": "my-awesome-project", "version": "1.0.0", "description": "

配置中的警告 尚未设置“模式”选项。将“模式”选项设置为“开发”或“生产”,以启用此环境的默认设置。
multi./src/index.js./dist/bundle.js中出现错误我不确定这里的确切问题是什么,但我也遇到了这个警告,并通过在Webpack配置文件中设置
mode
属性解决了它们

package.json

    {
      "name": "my-awesome-project",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "build": "NODE_ENV=production webpack",
      },
      ...
      "devDependencies": {
       ...
      },
      "dependencies": {
       ...
      }
    }
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;

希望对您有所帮助。

以下是通过在webpack 4中键入
webpack--help
从webpack获得的帮助信息

Usage without config file: webpack <entry> [<entry>] --output [-o] <output>

如果您使用的是
webpack.config.js

const path = require('path');

module.exports = {
  mode: 'development',     // set mode option, 'development' or 'production'
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname,'dist'),
    filename: "bundle.js"
  }
};

配置文件中的设置模式有时不起作用。只需添加
--mode=development
就可以了

"scripts": {
  "start": "webpack --config webpack.config.js --hot --mode=development",
}

版本:配置中的webpack 4.0.1警告尚未设置“模式”选项。将“模式”选项设置为“开发”或“生产”,以启用此环境的默认设置。multi./src/index.js./dist/bundle.js模块中的错误未找到:错误:无法解析'/MyDisk/Work/mywork/webServer/documents/webpack demo'@multi./src/index.js./dist/bundle.js中的'/dist/bundle.js'./dist/bundle.js'./dist/dist/bundle.js'./dist/bundle.js'./您的问题太广泛了,我怀疑这与相当新的
webpack v4。查看他们关于如何迁移到
webpackv4
的文档。对于我来说,我只是错过了在输出路径之前编写“-o”标志。谢谢
"scripts": {
  "start": "webpack --config webpack.config.js --hot --mode=development",
}