php bin/console importmap:require

Requires JavaScript packages

Usage

importmap:require [-d|--download] [-p|--preload] [--path PATH] [--] <packages>...

Arguments

packages   The packages to add 

Options

-d,   --download   Download packages locally 
-p,   --preload    Preload packages 
      --path       The local path where the package lives relative to the project root 

Help

The importmap:require command adds packages to importmap.php usually
by finding a CDN URL for the given package and version.

For example:

    php bin/console importmap:require lodash --preload
    php bin/console importmap:require "lodash@^4.15"

You can also require specific paths of a package:

    php bin/console importmap:require "chart.js/auto"

Or download one package/file, but alias its name in your import map:

    php bin/console importmap:require "vue/dist/vue.esm-bundler.js=vue"

The preload option will set the preload option in the importmap,
which will tell the browser to preload the package. This should be used for all
critical packages that are needed on page load.

The download option will download the package locally and point the
importmap to it. Use this if you want to avoid using a CDN or if you want to
ensure that the package is available even if the CDN is down.

Sometimes, a package may require other packages and multiple new items may be added
to the import map.

You can also require multiple packages at once:

    php bin/console importmap:require "lodash@^4.15" "@hotwired/stimulus"