简体   繁体   English

Webpack + Babel 不在命令脚本上编译?

[英]Webpack + Babel not compiling on command script?

newish to Webpack and brand new to Babel.对 Webpack 来说是新的,对 Babel 来说是全新的。 I'm trying to set Babel up for my company's JS files to support older browsers, and am having an issue setting it up.我正在尝试为我公司的 JS 文件设置 Babel 以支持旧版浏览器,但在设置时遇到了问题。 Running the npm run start script does nothing.运行npm run start脚本什么也不做。 However, if I comment out the Babel module under my webpack.config.json , npm run start returns the normal functionality.但是,如果我在webpack.config.json下注释掉 Babel 模块, npm run start将返回正常功能。 Can someone tell me where I'm going wrong?有人可以告诉我哪里出错了吗?

I installed Babel using the following command:我使用以下命令安装了 Babel:

npm install -D babel-loader @babel/core @babel/preset-env webpack

package.json package.json

{
// Name, etc here.
  "scripts": {
    "start": "webpack"
  },

  "devDependencies": {
    "@babel/core": "^7.18.13",
    "@babel/preset-env": "^7.18.10",
    "babel-loader": "^8.2.5",
    "browserslist": "^4.21.3",
    "webpack": "^5.74.0",
    "webpack-cli": "^4.9.2"
  },
  "browserslist": [
    " > .5%, last 2 versions, iOS 12.1, Safari 13"
  ]
}

Webpack.json Webpack.json

const path = require("path");
module.exports = {
  entry: {
    theme: __dirname + "/assets/js/modules-theme/index.js",
    product: __dirname + "/assets/js/modules-product/index.js",
  },
  output: {
    filename: "[name].bundled.js",
    path: path.resolve(__dirname, "assets/js/"),
  },
  //mode: "development",
  mode: "production",
  watch: true,

  module: {
    rules: [
      {
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env"],
          },
        },
      },
    ],
  },
};

Thanks to all for any help.感谢所有人的帮助。

After a system restart, I was able to fix this issue.系统重新启动后,我能够解决此问题。 All is working now.现在一切正常。 I will delete this question after.之后我会删除这个问题。

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

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