Webpack-encore: Question: Multiple entries from an unknown entry object

Created on 15 Oct 2018  路  2Comments  路  Source: symfony/webpack-encore

Hello,

I'm currently migrating an existing webpack configuration under sf3 to webpack-encore under sf4.

The part containing the webpack-encore conf is defined into a vendor and can be used as part as multiple top projects.

Currently i was building an entry object that gathered all js/css files that were declared in the main projetc folders using patterns and an intermediate getEntry function.
The object built looks lke the following:
{ critical: 'path_to_critical/critical.js' content: 'path_to_content/content.js' 'style-critical': 'path_to_style-critical/critical.scss' ... ... ... }

With webpack-encore i don't know how to loop through this object and add as many addEntry or addStyleEntry as needed. JS/css files numbers and declarations varies from project to project.

When i try to merge this config doing:
const config = Encore. /.../ .getWebpackConfig(); config.entry = Object.assign(this.getEntry()); module.exports = config;
I'm stuck at the .getWebpackConfig(); part because the validator won't allow me to define a no entry config first.

How can i deal with that kind of case knowing i don't have the hands on the top projects structures or files.

Most helpful comment

Hi @ELFrontEnd,

Couldn't your simply loop over all the properties of your object and call addEntry/addStyleEntry accordingly?

Encore
  .setOutputPath('build/')
  .setPublicPath('/')
  .cleanupOutputBeforeBuild()
  // (other common properties...)
;

const entries = getEntries();
for (const entryName in entries) {
  // You could check "entries[entryName]" here to detect (s)css
  // files and call Encore.addStyleEntry() instead.
  Encore.addEntry(entryName, entries[entryName]);
}

module.exports = Encore.getWebpackConfig();

All 2 comments

Hi @ELFrontEnd,

Couldn't your simply loop over all the properties of your object and call addEntry/addStyleEntry accordingly?

Encore
  .setOutputPath('build/')
  .setPublicPath('/')
  .cleanupOutputBeforeBuild()
  // (other common properties...)
;

const entries = getEntries();
for (const entryName in entries) {
  // You could check "entries[entryName]" here to detect (s)css
  // files and call Encore.addStyleEntry() instead.
  Encore.addEntry(entryName, entries[entryName]);
}

module.exports = Encore.getWebpackConfig();

Yes that's good i'm ok with that kind of approach.

Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wenmingtang picture wenmingtang  路  4Comments

mstrom picture mstrom  路  3Comments

Growiel picture Growiel  路  4Comments

weaverryan picture weaverryan  路  4Comments

MatthD picture MatthD  路  4Comments