nathanjhood / esbuild-scripts

esbuild-flavoured 'react-scripts'.
Other
0 stars 0 forks source link

TODO: format, platform opts #51

Open nathanjhood opened 1 week ago

nathanjhood commented 1 week ago
const getCommonOptions = () => {
  // ...
    platform: 'browser', // 'node' | browser | neutral,
    format: 'esm',
}
const buildSwr = () => {
  // ...
    platform: 'browser', // 'node' | browser | neutral,
    format: 'esm',
}
const buildSwr = () => {
  // ...
    platform: 'browser', // 'node' | browser | neutral,
    format: 'esm',
}

Consumers must set "type": "module" in their package.json.

This should ensure that global vars are not broken in weird, subtle ways...

nathanjhood commented 1 week ago

Working locally, testing later:

const buildOptions: ESBuild.BuildOptions = {
    // defaults
    ...defaultBuildOptions,
    // // args
    // ...options,
    // required
    banner: {
      // js: `new EventSource('/esbuild').addEventListener('change', () => location.reload(),{once:true});`,
      js:
        proc.env['FAST_REFRESH'] === 'false'
          ? ''
          : `new EventSource('${wdsSocketPath}').addEventListener('change', () => ${wdsSocketHost}.reload(),{once:true});`,
    },
    format: 'esm',
    sourcemap: proc.env['GENERATE_SOURCEMAP'] === 'true' || false,
  };
nathanjhood commented 1 week ago
  • getCommonOptions:
const getCommonOptions = () => {
  // ...
    platform: 'browser', // 'node' | browser | neutral,
    format: 'esm',
    // ...
}

Consumers must set "type": "module" in their package.json.

This should ensure that global vars are not broken in weird, subtle ways...

We could maybe do a require/import on paths.appPackageJson and determine what, if any, is their "type": entry set to, and have esbuild respond to that. There is a possibility that esbuild already does this, but it would be nice to offer a hook for end users here.