mattdesl / budo

:clapper: a dev server for rapid prototyping
MIT License
2.17k stars 106 forks source link

Specifying babelify options with node API #239

Open dbrgn opened 5 years ago

dbrgn commented 5 years ago

How can I pass babelify options using the node API?

With the command line API, I can do something like this:

-t [ babelify --presets [ env ] --extensions .ts ]

But with the Node API, this fails:

budo('src/app.ts:dist/app.js', {
    ...
    browserify: {
        transform: [babelify, {
            presets: ['@babel/preset-env'],
            extensions: '.ts',
        }],
    },
    ...

The error messages is TypeError: Path must be a string.. That error message comes from node_modules/resolve/lib/async.js.

What's the proper syntax for passing options to babelify? Maybe an example could be added to the README.

mattdesl commented 5 years ago

Probably the best is to require('babelify').configure({ ... })

You can also use subarg with a nested array, I believe. Not at my work station now to check, though.

budo('src/app.ts:dist/app.js', {
    ...
    browserify: {
        transform: [
            [ babelify, {
              presets: ['@babel/preset-env'],
              extensions: '.ts',
            } ]
        ],
    }
dbrgn commented 5 years ago

@mattdesl thanks, that seems to work! However, now I'm having issues with specifying a plugin.

This works:

budo src/app.ts:dist/app.js \
    -d public -d . -d src \
    --live -- \
        -d -p tsify -t [ babelify --presets [ @babel/env ] --extensions .ts ]

However, with this node based config...

budo('src/app.ts:dist/app.js', {
    dir: ['public', '.', 'src'],
    live: true,
    stream: process.stdout,
    port: 9966,
    debug: true,
    browserify: {
        plugin: tsify,
        transform: [babelify.configure({
            presets: ['@babel/preset-env'],
            extensions: '.ts',
        })],
    },
})

...I'm getting TypeScript errors:

img

It seems that the TypeScript files aren't being processed, even though the two configs look equivalent to me (but I must be overlooking something).

Any idea?