Skip to content

"zero configuration" - but not respecting most package.json options? #938

@mindplay-dk

Description

@mindplay-dk

I may be completely ignorant of something, so forgive me, but isn't "zero configuration" meant to imply that your package.json gets treated as the "source of truth"?

Meaning, the intent is for package.json to govern what gets generated, filenames, and so forth - directly ensuring that the default settings match what your package.json specifies?

Because it seems like microbundle more or less completely ignores my package.json, and I have to manually configure everything anyway?

For example, I tried this first:

{
  "name": "lol",
  "module": "./dist/lol.js",
  "scripts": {
    "build": "microbundle"
  },
  "files": [
    "dist"
  ]
}

Which resulted in builds for every format supported - I had to add the --format modern switch to disable the other formats.

By adding module and specifying a path, haven't I explicitly said "this is the only kind of format I need"?

It also does not seem to respect the path. The output filename is lol.modern.js, despite my specifying module as ./dist/lol.js, and you end up with a package that can't be installed at all.

I decided to try exports with default instead:

{
  "name": "lol",
  "module": "./dist/lol.js",
  "scripts": {
    "build": "microbundle --format modern"
  },
  "files": [
    "dist"
  ]
}

This similarly gets ignored - it doesn't use the filename, and it doesn't govern what gets generated; the filename, apparently, is always derived from name and the paths you specify are ignored.

(and yes, I noticed the --name switch, where I could explicitly specify this again - but having to configure the same thing first for npm and then for microbundle, doesn't that kind of clash with the idea of "zero configuration"?)

Likewise, this being a Typescript project, I tried adding types:

{
  "name": "lol",
  "module": "./dist/lol.js",
  "types": "./dist/lol.d.ts",
  "scripts": {
    "build": "microbundle --format modern"
  },
  "files": [
    "dist"
  ]
}

This gets even more confusing, as the presence of types does have an effect - it does trigger the creation of .d.ts files. However, the value appears to be ignored - the .d.ts files just get filenames derived from the input filenames. (It also does not emit a single .d.ts file, as I had hoped - but that's probably an unrelated issue or a non-feature.)

Things got more curious still, when I attempted multiple entry-points:

{
  "name": "lol",
  "exports": {
    ".": "./dist/lol.js",
    "./wat": "./dist/wat.js"
  },
  "scripts": {
    "build": "microbundle --format modern"
  },
  "files": [
    "dist"
  ]
}

As I expected at this point, this had no effect, and reporting.js just wasn't generated - however, when I added src/index.ts src/reporting.ts to the microbundle command, not only did it generate both files, but in addition, suddenly the filenames in exports were being applied:

{
  "name": "lol",
  "exports": {
    ".": "./dist/lol.js",
    "./wat": "./dist/wat.js"
  },
  "scripts": {
    "build": "microbundle --format modern src/index.ts src/wat.ts"
  },
  "files": [
    "dist"
  ]
}

(Side note: the contents of the output dist/wat.js file somehow magically is what I expected - it's not clear to me how microbundle gets from src/index.ts src/wat.ts back to either the ./wat name or the ./dist/wat.js path in the exports section and figures this out? Other than the word wat, there's no direct relationship between either the name or the path and the input file - I wasn't expecting this to work, I was just sort of trying things and got lucky...)

Thinking I had figured out the special sauce (explicitly specifying the entry file) I reverted back to this:

{
  "name": "lol",
  "exports": {
    "default": "./dist/lol.js"
  },
  "scripts": {
    "build": "microbundle --format modern src/index.ts"
  },
  "files": [
    "dist"
  ]
}

Solved, right? 😅

Wrong.

Apparently, specifying the filenames in exports only works when you specify more than one entry point.

I wanted to share this whole user journey to give you some idea of what the developer experience might be like for some people. I'm sure there's some way to find a "winning configuration", but after sinking another half-day into this, I'm just going to go back to rollup... again.

It's not the first time I've attempted to use microbundle - and please don't get me wrong, I don't mean any disrespect, and I see this working for a bunch of projects.

But as compilers/bundlers go, this is not the most intuitive or pleasant experience. The idea of "zero configuration" appeals to me, but I can't honestly say that this delivers.

I guess maybe it depends on what you expect or mean by "zero configuration"? Personally, I take that to mean "zero extra configuration" - as it's obviously not possible to do anything without some sort of configuration, somewhere. I thought the idea was you derive a sensible default configuration from what's there anyway, your package.json file, and perhaps with the option to override?

Maybe that's not it at all, but I got the impression from other tools that that's the idea?

Are my expectations way off track here?? 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions