parcel-bundler / parcel

The zero configuration build tool for the web. πŸ“¦πŸš€
https://parceljs.org
MIT License
43.46k stars 2.27k forks source link

Babel config other than presets and plugins is ignored #4435

Open fregante opened 4 years ago

fregante commented 4 years ago

πŸ› bug report

Only presets and plugins are considered from babel's config (package.json's babel and .babelrc). Other keys like comments are completely ignored.

This is the relevant piece of code in v1 and in v2:

https://github.com/parcel-bundler/parcel/blob/f01437e7f646f4aa74a5d3cf48ed7c4f21822352/packages/transformers/babel/src/config.js#L177-L185

Notice how only presets and plugins are taken from the config variable.

πŸŽ› Configuration (.babelrc, package.json, cli command)

parcel build index.js --no-minify
// .babelrc
{
  "comments": false
}

πŸ€” Expected Behavior

Configuration shouldn't be ignored, comments should be omitted (without enabling full-on minification)

😯 Current Behavior

The configuration is ignored and comments are still in the files.

πŸ’ Possible Solution

Include all keys when merging configs

πŸ”¦ Context

I want to use babel to package my browser extensions, which don't accept minified files. Dropping comments saves some bytes without enabling full-on minification.

🌍 Your Environment

Software Version(s)
Parcel 1.12.4 (but the code is unchanged in v2 as well)
Node 13.8.0
npm/Yarn 6.13.6
Operating System macOS 10.15
wbinnssmith commented 4 years ago

I looked into this β€” in v2, we do pass an accurate config to Babel when we transform it, however we don't pass the babel config when we generate β€” which is where I imagine the comments option is used. Right now we only resolve an asset's Babel config in the Babel transformer, and generate can be called on any transformer that supports the AST depending on the pipeline order.

We'll need to get the babel config to whichever transformer ends up generating the asset code. Should we have an API for a transformer to expose options to be available to generation, independent of which transformer generates?

cc @padmaia @devongovett

peakyDicers commented 4 years ago

I'd like to add on that "env" also does not work. (parcel-bundler ^1.12.4)

{
  "presets": ["@babel/preset-env"],
  "env": {
    "production": {
      "plugins": ["transform-remove-console"]
    }
  }
}

Has there been a fix or a hack that people have used to get around this?

hunterloftis commented 3 years ago

Parcel 2 doesn't seem to be respecting a good portion of my .babelrc config. Is there some other pattern I should be following?

{
    "presets": [
        "@parcel/babel-preset-env",
        "@babel/preset-typescript",
        ["minify", { "builtIns": false }]   // ignored?
    ],
    "plugins": [
        "@babel/plugin-proposal-class-properties",
        [
            "@babel/plugin-proposal-decorators",
            {
                "decoratorsBeforeExport": true
            }
        ]
    ],
    "compact": true,    // ignored?
    "comments": false   // ignored?
}