README.md in importmap-rails-1.2.1 vs README.md in importmap-rails-1.2.2

- old
+ new

@@ -61,9 +61,30 @@ It's in `app/javascript/application.js` you setup your application by importing any of the modules that have been defined in the import map. You can use the full ESM functionality of importing any particular export of the modules or everything. It makes sense to use logical names that match the package names used by npm, such that if you later want to start transpiling or bundling your code, you won't have to change any module imports. +### Local modules + +If you want to import local js module files from `app/javascript/src` or other sub-folders of `app/javascript` (such as `channels`), you must pin these to be able to import them. +You can use `pin_all_from` to pick all files in a specific folder, so you don't have to `pin` each module individually. + +```rb +# config/importmap.rb +pin_all_from 'app/javascript/src`, under: 'src', to: 'src' +``` + +The `:to` parameter is only required if you want to change the destination logical import name. If you drop the :to option, you must place the :under option directly after the first parameter. + +Allows you to: + +```js +// app/javascript/application.js +import { ExampleFunction } from 'src/example_function' +``` +Which imports the function from `app/javascript/src/example_function.js`. + +Note: Sprockets used to serve assets (albeit without filename digests) it couldn't find from the `app/javascripts` folder with logical relative paths, meaning pinning local files wasn't needed. Propshaft doesn't have this fallback, so when you use Propshaft you have to pin your local modules. ## Using npm packages via JavaScript CDNs Importmap for Rails is designed to be used with JavaScript CDNs for your npm package dependencies. The CDNs provide pre-compiled distribution versions ready to use, and offer a fast, efficient way of serving them.