I'm currently testing the new Symfony UX Dropzone and after a few hours of research I still have one question left to answer: Why don't UX packages include JS scripts? - how is Symfony supposed to include dropzone(.min).js
for example ?
Currently for the code to work I have to:
- Download the
dropzone.js
file from the official website. - Place the file under
/assets/dropzone/dropzone.js
- Add to the
assets/app.js
file the linewindow.Dropzone = require('./dropzone/dist/dropzone.js');
I started by creating a new project and then installing Dropzone as follows:
symfony composer req ux-dropzone
npm install
npm run build
/src/Form/FormType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('file', DropzoneType::class)
;
}
/src/templates/base.html.twig
{% block stylesheets %}
{{ encore_entry_link_tags('app') }}
{% endblock %}
{% block javascripts %}
{{ encore_entry_script_tags('app') }}
{% endblock %}
/assets/app.js
import './styles/app.css';
window.Dropzone = require('./dropzone/dropzone.js');
// start the Stimulus application
import './bootstrap';
Without this manual import of the dropzone(.min).js
file the variable window.Dropzone
is not initialized.
I found a similar topic here, however it seems that in this case the installation of the package created the file /node_modules/ux-dropzone/dist/min/dropzone.min.js
. But in my case here is the generated tree structure:
Is this the right way to proceed?
Wishing you a good day :)