-
Notifications
You must be signed in to change notification settings - Fork 123
Update README to mention pin_all_from for local modules #95
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
Changes from all commits
f06f9e1
4575238
fc61d3c
6845bb3
09ed1a4
a66e8a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,27 @@ It's in `app/javascript/application.js` you setup your application by importing | |
|
||
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. | ||
Rotario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```rb | ||
# config/importmap.rb | ||
pin_all_from 'app/javascript/src`, under: 'src', to: 'src' | ||
Rotario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you may need to do this for production anyways. In development Sprockets will serve those plain assets (without the digest), but in production you'll likely see 404 for the same requests. This could maybe be simplified to a warning to make sure that one pins all files one needs from app/javascript. |
||
|
||
## Using npm packages via JavaScript CDNs | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.