Skip to content

Wildcards in entry points #370

Closed
Closed
@ampedandwired

Description

@ampedandwired

I think it would be really useful to support wildcards in webpack entry points, like this:

entry: "test/**/*Spec.js"

My use case here is to be able to find all tests in a directory without having to add them to a master index.js. This should work with watch mode as well so that new/removed/changed files in matching the glob would be automatically picked up.

I can work around this by using gulp or grunt to watch for the glob and pipe them into webpack, but it feels a bit awkward.

Activity

sokra

sokra commented on Jul 23, 2014

@sokra
Member

You can easily do this by your own, as the webpack.config.js is just a node.js module and allows to execute any code.

var glob = require("glob");
// ...
entry: glob.sync("./test/**/*Spec.js")
wmertens

wmertens commented on Jun 13, 2015

@wmertens
Contributor

@sokra could this be reopened? If wildcards are supported out of the box more people will know how to use them, and the watch functionality can detect new files...

SgtPooki

SgtPooki commented on Jul 24, 2015

@SgtPooki

+1 for wildcard support.

wildcard support would allow config file to be json, or put into package.json

Phoenixmatrix

Phoenixmatrix commented on Sep 4, 2015

@Phoenixmatrix

@sokra there's another use case for wildcard entry points: not needing to restart webpack -watch when a new file is added. We have a lot of entry points for various reasons (eg: being able to run unit tests on a smaller subset of the files during development), and whenever someone adds a new test file, they'd have to restart webpack for it to get picked up, while everything else is handled by -watch.

adamkdean

adamkdean commented on Nov 13, 2015

@adamkdean

+1

kilianc

kilianc commented on Dec 18, 2015

@kilianc

+1

kilianc

kilianc commented on Dec 18, 2015

@kilianc

@sokra this is mostly for the CLI not the config file, as you said the config file is fine and using glob.sync just works.

missingtrailingcomma

missingtrailingcomma commented on Dec 27, 2015

@missingtrailingcomma

+1

stevenjlho

stevenjlho commented on Jan 14, 2016

@stevenjlho

+1

ixisio

ixisio commented on Jan 14, 2016

@ixisio

+1

cspotcode

cspotcode commented on Jan 15, 2016

@cspotcode

A possible workaround is to use require.context:

// webpack.config.js
entry: "test/all.js"
// test/all.js
var req = require.context('./', true, /Spec\.js$/);
req.keys().forEach(req);
jrhorn424

jrhorn424 commented on Jan 26, 2016

@jrhorn424

Thanks @cspotcode. 👍 🌟

added a commit that references this issue on Jul 19, 2016

54 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @aurimasniekis@wmertens@mac2000@stereobooster@cspotcode

        Issue actions

          Wildcards in entry points · Issue #370 · webpack/webpack