Prevent laravel mix from converting "const" and "let" to "var"


I am using LaravelMix to compile my project.
And I want to prevent LaravelMix from converting const and let to var

I tried to update babel to latest version and tried alot of solutions on stackoverflow with no success.

This is my webpack.mix.js

const mix = require("laravel-mix");

mix.webpackConfig({
  module: {
    rules: [
      {
        test: /.m?js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: [
              [
                "@babel/preset-env",
                { targets: "defaults, not ie 11, not ie_mob 11" },
              ],
            ],
            plugins: ["@babel/plugin-proposal-class-properties"],
          },
        },
      },
    ],
  },
});

mix
  .js("./app.js", "./assets/js")
  .postCss("./app.css", "./assets/css", [
    require("tailwindcss"),
    require("autoprefixer"),
  ]);

And this is my package.json

{
...

"dependencies": {
    "laravel-mix": "^6.0.34",
    "quicklink": "^2.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.16.0",
    "@babel/plugin-proposal-class-properties": "^7.16.0",
    "@babel/preset-env": "^7.16.0",
    "autoprefixer": "^10.4.0",
    "babel-loader": "^8.2.3",
    "browser-sync": "^2.27.5",
    "browser-sync-webpack-plugin": "^2.3.0",
    "postcss": "^8.3.11",
    "tailwindcss": "^2.2.19",
    "webpack": "^5.62.1"
  },
  "browserslist": [
    "defaults, not ie 11, not ie_mob 11"
  ]

...
}

Any help?

Source: JavaSript – Stack Overflow

November 25, 2021
Category : News
Tags: babeljs | javascript | laravel | webpack

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.