K
K
KBBS2020-06-25 05:44:19
Laravel
KBBS, 2020-06-25 05:44:19

How to set the directory in which files created during dynamic import will be saved when using laravel-mix?

Hello.

I use laravel-mix to build the frontend.
In webpack.mix.js, for example, I write:

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

app.js uses dynamic imports. And the file that I will be importing dynamically is stored in the public/0.js path.
Is there any way to force mix to save it to the public/assets/js directory, or any other directory I specify.

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KBBS, 2020-06-25
@KBBS

I asked myself - I answered myself :)
There are:
resources/js/app.js - a file in which we perform dynamic import,
resources/js/some-module.js - a module file that we dynamically import.
We want the compiled files to be placed in public/assets/js.
That is, at the output we want to get:
public/assets/js/app.js,
public/assets/js/some-module.js.
In webpack.mix.js:
mix.js('resources/js/app.js', 'public/assets/js/app.js'); // this is obvious
And in app.js:
import(/* webpackChunkName: "assets/js/some-module" */ './some-module.js');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question