.babelrc ignore ignores invalid js

beginner, excuse me.

1. Question:
webpack + vue-cli project, using babel to escape es6, in which I have a js written in the old-fashioned way, such as this:

delete obj;

webpack will report an error in strict mode, so modify the babel configuration file .babelrc to ignore the js file with ignore, but it is not valid

2. Code:
.babelrc

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": ["transform-vue-jsx", "transform-runtime"],
  "env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]
    }
  },
  "ignore":[
    "./src/assets/alerter.js"
  ]
}

I added the last ignore, myself and everything else is the original

.

3. Error report: the result after
npm run dev is still prompted to escape

in strict mode.

4. Try the
plug-in to remove strict-mode
first: npm install babel-plugin-transform-remove-strict-mode-- save-dev
and then: .babelrc

"plugins": [
  "transform-remove-strict-mode"
]

as follows:

 

  {
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": ["transform-vue-jsx", "transform-runtime","transform-remove-strict-mode"],
  "env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]
    }
  },
  "ignore":[
    "./src/assets/qksheet/alerter.js"
  ]
}

still report an error

Note: the design area of the old code is too large to consider changes until it is a last resort. It used to run normally without the webpack tool.
Thank you!


it seems that you self-packaged the JS as an ES6 module, while the ES6 module automatically adopts strict mode; it is useless to ignore it;

Don't package it as an ES6 module, pick out the JS separately, and quote

separately on the page.
Menu