gulp icon indicating copy to clipboard operation
gulp copied to clipboard

Support named exports in mjs files

Open perrin4869 opened this issue 2 years ago • 4 comments

Using gulpfile.esm I can do:

import { src, dest, series, parallel } from "gulp";

When using gulpfile.mjs, this doesn't work because doesn't officially export the properties src, dest, etc. Was wondering if there is any interest to support this, maybe in v5?

perrin4869 avatar Sep 25 '21 14:09 perrin4869

Tangentially related to https://github.com/gulpjs/rechoir/issues/43 - the idea is that our rechoir library needs to be updated to support mjs files otherwise we need to rely on the transpiled export format.

phated avatar Sep 25 '21 20:09 phated

My workaround for gulpfile.mjs

import gulp from 'gulp';
const { series, parallel, src, dest, task } = gulp;

noraj avatar Jul 20 '22 21:07 noraj

Well of course that's the way to get this done for now. Actually, this is trivially easy to add using the technique: https://github.com/gulpjs/vinyl/pull/152 Without a whole ESM rewrite...

perrin4869 avatar Jul 21 '22 03:07 perrin4869

@phated Node supports having different entrypoints for import and require. Thus you could have an index.mjs for import and an index.cjs for require (backward compatibility). See https://nodejs.org/dist/latest-v19.x/docs/api/packages.html#package-entry-points for reference.

Haringat avatar Feb 21 '23 15:02 Haringat

I've added this in #2760 but I have an outstanding question on if something special needs to happen to support the bin field. If someone has knowledge of this, please let me know so we can wrap this up.

phated avatar Mar 25 '24 01:03 phated