Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling artefacts dependant on other artefacts #3104

Open
zombietfk opened this issue Sep 15, 2021 · 6 comments · Fixed by #3115
Open

Compiling artefacts dependant on other artefacts #3104

zombietfk opened this issue Sep 15, 2021 · 6 comments · Fixed by #3115
Assignees
Projects

Comments

@zombietfk
Copy link

zombietfk commented Sep 15, 2021

  • Laravel Mix Version: 6.0.31
  • Node Version: v16.9.1
  • NPM Version: v7.21.1
  • OS: Ubuntu 20.04

Description:

I'm trying to build artefacts that are dependant on artefacts created by previous build steps - for example, to create one file which is first compiled without minification, then a second which is minified, creating two separate files (where the second artefact is built using the source of the first). This appears to have been asked before, however, the solution/workaround given in the last comment no longer appears to work. Instead, while it does create two files, the minified version will always be an empty file. I've been able to get around this issue by running mix twice, either using the same *.mix.js file or two separate ones, but is not ideal as it results in increased build times by having to run parts of the build twice - redundantly. Is this intended/possible/in the scope of this project?

Steps To Reproduce:

Create a new laravel application, update webpack.mix.js to the following

const mix = require('laravel-mix');

mix.webpackConfig({
    optimization: {
        minimize: false,
    }
});

mix.js('resources/js/app.js', 'public/js/');

mix.minify('public/js/app.js');

Execute npm run production

Expected output is

┌─────────────────────────────────────────┬──────────┐
│                                    File │ Size     │
├─────────────────────────────────────────┼──────────┤
│                              /js/app.js │ 592 KiB  │
│                          /js/app.min.js │ 89.5 KiB │
└─────────────────────────────────────────┴──────────┘

Actual output is

┌──────────────────────────────────────────┬─────────┐
│                                     File │ Size    │
├──────────────────────────────────────────┼─────────┤
│                               /js/app.js │ 592 KiB │
│                           /js/app.min.js │ 1 bytes │
└──────────────────────────────────────────┴─────────┘
@thecrypticace
Copy link
Collaborator

I've been thinking about this. I think that the general case for this might be too complicated however for the case of styles, combine, and maybe minify we are likely going to make it run after the webpack build has finished (if I can find a way to do it within the build and still produce the desired output I'll do that but I'm not certain).

Question about your example: Is there a reason you want to produce unmagnified output and then minify it later rather than let webpack handle it during the production compile? Or was that just a "trivial" example you could use to explain the situation?

@zombietfk
Copy link
Author

zombietfk commented Sep 15, 2021

Yes, this is just a simplified demonstration of what I'm trying to achieve - what I'm actually trying to do is create multiple artefacts with different build targets, which themselves are based on other artefacts which have been built using a mix of mix.babel(..) and mix.js(..) (Although I can probably scrap those)

@thecrypticace
Copy link
Collaborator

What would be the purpose of combining files from multiple build targets?

Also, as an aside, if you're working with different build targets would this WIP PR be useful for you? #3096?

I know of several use cases but I want to be sure I'm planning ahead for future capability. The other thing I'm thinking about (but not sold on because of the inherent complexity) is linear, acyclic dependencies between groups.

@zombietfk
Copy link
Author

zombietfk commented Sep 15, 2021

Yes, that PR does look promising! Hmm I think I'm not explaining my issue very well - But basically I want to take the existing artefact(s) and recompile them to a new target (But both are needed, as separate files). I could probably rebuild from the source again, but I'm not sure if this would be more efficient or not as primarily I'm trying to cut down the overall build time.

@thecrypticace
Copy link
Collaborator

Okay, got it. I'll give it some thought. It may be that the task changes set to land in 6.1 will suffice for your use case.

@thecrypticace
Copy link
Collaborator

Ah I didn't mean to close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
v6.1
To do
Development

Successfully merging a pull request may close this issue.

2 participants