Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Support a single webpack entry #230

Closed
joeldenning opened this issue Jan 9, 2020 · 10 comments
Closed

Support a single webpack entry #230

joeldenning opened this issue Jan 9, 2020 · 10 comments

Comments

@joeldenning
Copy link
Contributor

It is possible to have the webpack entry be a string instead of an object. However, webpack-chain doesn't seem to support this, as shown in the following code:

webpack-chain/src/Config.js

Lines 131 to 135 in 573553e

entry: Object.keys(entryPoints).reduce(
(acc, key) =>
Object.assign(acc, { [key]: entryPoints[key].values() }),
{},
),

It's also possible to support an object where the values are strings, instead of arrays of strings.

Is this something you'd be open to changing? Am happy to discuss API and submit a PR for it.

@edmorley
Copy link
Member

edmorley commented Jan 29, 2020

Looking at the webpack docs (concepts; config) and config schema, it looks like the accepted forms of entry are:

A) Single entry shorthand with single filename:

module.exports = {
  entry: './foo.js',
};

B) Single entry shorthand with an array of filenames:

module.exports = {
  entry: [
    './foo.js',
    './bar.js',
  ],
};

C) Object form with single filename:

module.exports = {
  entry: {
    main: './foo.js',
  },
};

D) Object form with an array of filenames:

module.exports = {
  entry: {
    main: [
      './foo.js',
      './bar.js',
    ],
  },
};

E) Dynamic entry(function):

module.exports = {
  entry: () => {
    // Function must return one of the forms above (entry object, string, or array)
    // or a promise to these things.
  },
};

Returning back to webpack-chain, currently to set the entry point(s) one must use either:

config.entry('main')
  .add('./foo.js');

or:

const Config = require('webpack-chain');
const config = new Config();

config.merge({
  entry: {
    main: ['./foo.js']
  },
});

There seem to be as few problems with this:

  1. There is no support for dynamic (function) entry point definitions at all (filed as issue Dynamic entry points not supported? #200)
  2. The schema supported by .merge() is quite limited (though merge has many other issues; I wish we could just remove the feature entirely - not really sure many of the use-cases for it make sense too?)
  3. When the configuration is generated using .toConfig(), it's always output in the long form (form 3 above), even if there are only single entries/filenames. Though perhaps some people would prefer consistency, and if the config is ever diffed, always using the long form reduces diff churn.
  4. When specifying the config via config.entry() one always has to set an entry name (though same could be said for plugins/rules/... I guess?).

@joeldenning was your main concern around (4)?

@joeldenning
Copy link
Contributor Author

joeldenning commented Jan 30, 2020

was your main concern around (4)?

No - my main concern is about (1). As far as I can tell, the following webpack config is not currently possible to construct with webpack chain:

module.exports = {
  entry: 'src/index.js'
}

I agree supporting all possible entry types would be ideal. My PR in #239 doesn't address any missing entry types except for (1)

@edmorley
Copy link
Member

Ah sorry I used numbers for both the "accepted webpack config output" forms and the "there are a few problems with this" list. I've changed the former to use A-E instead of numbers.

By "was your main concern around (4)" I meant more was the issue relating to inputting to webpack-chain or the output format from webpack-chain, or something else?

@joeldenning
Copy link
Contributor Author

Ah I see now. Yes, my main concern is that webpack-chain's entry and entryPoints requires all entries to have a name.

I'm looking to create the webpack config as shown in A)

@edmorley
Copy link
Member

edmorley commented Feb 3, 2020

Sorry I haven't replied yet - need to sit down and think about this some more when I have more solid block of time free :-)

@joeldenning
Copy link
Contributor Author

👍 looking forward to hearing your thoughts on it

@homersimpsons
Copy link

homersimpsons commented Jan 28, 2022

Hello, I have kind of this issue, but I would like to use an object instead of an array for my entries. My goal is to have something like:

entry: {
  app: { import: 'src/main.js', filename: 'main.js' }
}

My main try is

config.entry('app)
  .set('import', 'src/main.js')
  .set('filename', 'main.js')

But of course this does not work.

To me the datastructure of an entryPoints[key] should always be an object. It could then easily be transformed to a more concise structure if applicable.

The values() function may have to be overloaded.

@buksy90
Copy link

buksy90 commented Jan 3, 2023

Hi, I'd like to set library property on my entry point

I'm trying with following

config.entryPoints.set(`widget`, {
          import: `./src/pages/widget/index.ts`,
          library: {
            name: 'widget',
            type: 'jsonp',
          },
        });

But there is following error TypeError: entryPoints[key].values is not a function

@edmorley edmorley closed this as completed Feb 3, 2024
@homersimpsons
Copy link

For the record, this issue is most likely not complete but the project is now abandoned #358.

To all the maintainers, thank you for your contributions !

@edmorley
Copy link
Member

edmorley commented Feb 4, 2024

@homersimpsons Hi! Yeah sadly the GitHub mass-issue closing UI doesn't allow for choosing the closure-type of "Not planned" or leaving a comment (mentioning #358) - which meant I had to mass close as "Completed".

@edmorley edmorley closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

4 participants