symfony / webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
https://symfony.com/doc/current/frontend.html
MIT License
2.23k stars 198 forks source link

Create the output directory if it does not exist #189

Closed weaverryan closed 5 years ago

weaverryan commented 7 years ago

Currently, we do create the output directory if it does not exist... but we only go one level deep (if web/ exists, we will create web/build, but if web does not exist, we throw an error): https://github.com/symfony/webpack-encore/blob/799720602aab2069f827704e4a6d672d03d38d76/lib/WebpackConfig.js#L107

We do that for safety, but in this (rare) situation, it's kind of annoying. My friend Beau hit it recently with Encore on Sculpin :).

cascornelissen commented 6 years ago

@weaverryan and others, any news on this?

We'd love to build multiple bundles into the "same" output directory like visualized below. We can't output all files in the build/ directory since the directory gets cleared before compiling and we want to be able to compile the bundles separately.

web
  - build
    - admin  // separate admin build
    - app    // separate app build

You've stated safety as a reason. Maybe we could allow a maximum of 3 levels of directories to be created before the outputPath directory does not exist error gets thrown? Another option might be comparing the base path of the Encore installation (e.g. via require.main.filename or something similar) to the outputPath to make sure it at least gets created within the project?

I could submit a PR for this if you're interested. Let me know!

h3llr4iser commented 6 years ago

I have the same problem, Do you have a workaround?

Lyrkan commented 6 years ago

@h3llr4iser By "same problem" do you mean having multiple build folders? Couldn't you just call cleanupOutputBeforeBuild() with multiple paths?

For instance:

// First build
Encore.cleanupOutputBeforeBuild(['admin/**/*']);

// Second build
Encore.cleanupOutputBeforeBuild(['app/**/*']);