question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Automatic entries via a glob pattern

See original GitHub issue

At Symfony Live, @trappar had an interesting idea: a way to automatically add entries based off of a glob pattern. For example, perhaps all .js files in the root of assets/ should be entry files (assets/*.js). Then it would be cool to be able to say:

Encore.addEntries('assets/*.js')

The one problem is that when you add new files, it would mean that your webpack.config.js config will need to change (we would need to add the new entry). That’s a problem because you’ll need to restart encore if you’re using --watch. So… that’s a bit of a “gotcha” with this feature. We could manually “watch” this directory for new files in Encore and add a notification (#187) in this situation.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
trapparcommented, Oct 26, 2017

@Lyrkan

What would be the name of the generated entries in this case?

In the project where I’m doing this I use something like the following to convert a glob path/pattern into an entry object:

const path = require('path');
const glob = require('glob');​

const globToEntry = (base, pattern) => {
    return glob.sync(path.join(base, pattern)).reduce((entry, file) => {
        const parsedPath = path.parse(path.relative(base, file));
        entry[path.join(parsedPath.dir, parsedPath.name)] = path.resolve(file);
        return entry;
    }, {});
};

I like this because it maintains the same folder structure inside my assets folder when the public versions are built, which allows me to use something like: globToEntry('assets', '**/*.js') to turn assets/admin/users.js into public/build/admin/users.js

Wouldn’t that encourage bad practices?

I personally don’t see having many entry points as a bad practice. Any significantly large MPA is going to end up having tons of them, and that isn’t a terribly inefficient way of building an app as long as common chunks and code splitting are being used properly. Sure moving toward SPA architecture might be more ideal for many applications using Webpack, but that doesn’t mean that this package shouldn’t support other styles of application as well. Just my opinion.

0reactions
weaverryancommented, Nov 16, 2018

Closing this, at least for now. Not sure it’s a good idea, and there are complications

Read more comments on GitHub >

github_iconTop Results From Across the Web

glob (programming)
In computer programming, glob patterns specify sets of filenames with wildcard characters. For example, the Unix Bash shell command mv *.txt textfiles/ ...
Read more >
Common glob pattern
The Glob patterns implemented in the File Log Agent is to provide methods to traverse the file system and returning files or the...
Read more >
Use glob patterns on the Pipelines yaml file | Bitbucket Cloud
Glob patterns don't allow any expression to start with a star. Learn the glob patterns you can use on the Pipelines yaml file....
Read more >
Using Glob Expressions Throughout the LogicMonitor Portal
Glob Syntax. This table below illustrates how to format glob expressions. You can combine these to create more complex expressions: ...
Read more >
c# - glob pattern matching in .NET
I like my code a little more semantic, so I wrote this extension method: using System.Text.RegularExpressions; namespace Whatever { public ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found