I'm new to webpacker and yarn. I installed successfully the package with:
yarn add moment
EDIT2:
This is my import
# app/javascript/packs/application.js
import moment from 'moment/moment'
import 'moment/locale/de-ch'
Problem: I can't use the "moment" package in my old JS asset files
First works, the other not:
# in: app/javascript/packs/application.js
console.log('Log: ' + moment([2007, 0, 29]).toNow()) #=> Log: in 10 Jahren
# in app/*assets*/javascripts/application.js
console.log('Log2: ' + moment([2007, 0, 29]).toNow()) #=> Uncaught ReferenceError: moment is not defined
EDIT1:
Here the key points of the installation process of webpacker:
- in gemfile: gem 'webpacker', github: 'rails/webpacker'
- Add this line to assets.rb: Rails.application.config.assets.paths << Rails.root.join('node_modules')
- Add in %head of application.html.haml this: = javascript_pack_tag 'application'
- Restart Rails server and start webpacker
Note: I upgraded my app from Rails 4.2 to 5.0 and later to 5.1; maybe something is missing in my app