简体   繁体   English

WebPack 配置失败

[英]WebPack configuration failed

I've some problems with configuration file on webpack.我在 webpack 上的配置文件有一些问题。

Right now I've this structure: the stucture现在我有这个结构:结构

package.json looks like this: package.json 看起来像这样:

{
  "name": "webpack-4-tutorial",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack --mode development ./src/index.js --output ./dist/main.js",
    "build": "webpack --mode production ./src/index.js --output ./dist/main.js"
  },
  "author": "Andrii Hordynsky",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "webpack": "^4.16.2",
    "webpack-cli": "^3.1.0"
  }
}

Index.js is just : console.log("hello, booooiiii"); console.log("hello, booooiiii");只是: console.log("hello, booooiiii");

When I'm running 'npm run build' it works and shows this outcome: outcome当我运行“npm run build”时,它会工作并显示以下结果:结果

I'm adding babel with: " npm install babel-core babel-loader babel-preset-env --save-dev and it works as well too: babel我正在添加 babel:“ npm install babel-core babel-loader babel-preset-env --save-dev它也能正常工作: babel

Adding .babelrc file :添加 .babelrc 文件:

{
"presets": [
   "env"
   ]
}

And start to create webpack.config.js with this structure as well:并开始使用此结构创建 webpack.config.js:

// Webpack v4
const path = require('path');
module.exports = {
  entry: { main: './src/index.js' },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'main.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      }
    ]
  }
}

and delete并删除

"dev": "webpack --mode development ./src/index.js --output ./dist/main.js",
    "build": "webpack --mode production ./src/index.js --output ./dist/main.js"

from 'scripts' at package.json来自 package.json 中的“脚本”

deleting删除

Now I have this structure: newStructure现在我有了这个结构: newStructure

And, when I run npm run build I'm expecting some small .js file in /dist/main.js , but I received the stack of an errors enter image description here而且,当我运行npm run build我期待/dist/main.js有一些小的 .js 文件,但我收到了错误堆栈,请在此处输入图像描述

When I delete "script" from package.json errors still here... new Errors当我从package.json删除“脚本”时,错误仍然存​​在......新错误

Sorry if there is some bad English or text as well, just, the head is completely boiling...对不起,如果还有一些不好的英文或文字,只是,脑袋完全沸腾了......

您忘记添加“.env”文件,如果您刚刚克隆了项目,则您的 gitignore 规则不允许跟踪“.env”文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM