browserify / browserify-handbook

how to build modular applications with browserify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document (or change) nested arrays for package.json transform field?

mikemaccana opened this issue · comments

From babel/babelify#142, it seems the syntax where individual transforms are specified as arrays is correct.

"browserify": {
    "transform": [
        "brfs",
        [
            "babelify", 
            { 
                "presets": ["es2015"] 
            }
        ]
    ]
}

The syntax for this part:

 [
    "babelify", 
    { 
        "presets": ["es2015"] 
    }
 ]

is odd: the array doesn't seem to be used as an ordered list of items. "babelify" is item 0, {"presets": ["es2015"]} is item 1. What would item 2 be?

If there wouldn't ever be an item 2, and this is simply a map between babelify and babelify's options, wouldn't an object be more logical?

"browserify": {
    "transform": [
        "brfs",
        {
            "babelify": { 
                "presets": ["es2015"] 
            }
        }
    ]
} 

The docs mention:

"If you want to pass options to the transforms, you can use a 2-element array inside of the primary array. Here fff gets an options object with {"x":3} and ggg gets {"y":4}:"

 {
   "foo": {
     "bar": [["fff",{"x":3}],["ggg",{"y":4}]]
   }
 }

Using an object would be a logical way to map "fff" and "ggg" to their respective options.

Using a key this way makes some semantics ambiguous:

{
  "babelify": { 
    "presets": ["es2015"] 
  }
}

What if there is another key? This would be better:

{
  "name": "babelify",
  "options": {
    "presets": "es2015"
  }
}

but that is much more verbose than the array form.

Thanks for the quick reply Substack! LGTM.