Skip to content

Commit

Permalink
feat: modify generators and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
KonnorRogers committed Jul 19, 2020
1 parent a61f8af commit a305177
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ gem 'snowpacker'

Then run

$ bin/rails g snowpacker
```
bin/rails g snowpacker
```

### Development

Currently `snowpacker` is not integrated with `rails s` so you need a process manager like [foreman]() to run both `rails s` and `snowpack`.

Create `Procfile.dev`, with the following content:

```
```bash
web: bin/rails s
snowpacker: bin/rails snowpacker:serve
```
Expand All @@ -46,21 +48,28 @@ Gem hooks up to the `assets:precompile` and `assets:clobber`, so no special setu

You can start snowpacker's compilation process manually by running

rake snowpacker:compile
```bash
rake snowpacker:compile
```

### Including in views

Use Rails generic helpers to include assets in your views

javascript_include_tag '/snowpacks/application'
stylesheet_link_tag '/snowpacks/application'
```ruby
<%= javascript_snowpack_tag 'application' %> # => snowpacks/javascript
<%= stylesheet_snowpack_tag 'application' %> # => snowpacks/stylesheets
```

### Configuration

After running generator, configuration can be found in config/initializers/snowpacker.rb.
After running generator, the configuration file can be found in
`config/initializers/snowpacker.rb`

config.snowpacker.entry_points = %w(app/javascript/application.js)
config.snowpacker.destination = 'public/snowpacks'
```ruby
config.snowpacker.entry_points = %w(app/javascript/snowpacks/application.js)
config.snowpacker.destination = 'snowpacks'
```

## Changelog

Expand Down
4 changes: 4 additions & 0 deletions examples/railsapp/config/initializers/snowpacker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Rails.application.config.snowpacker do |snowpacker|
snowpacker.entry_points = %w(app/javascript/snowpacks/application.js)
snowpacker.destination = 'snowpacks'
end
1 change: 1 addition & 0 deletions examples/railsapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"devDependencies": {
"@snowpack/plugin-babel": "^1.4.0",
"@snowpack/plugin-parcel": "^1.3.0",
"parcel-bundler": "^1.12.4",
"snowpack": "^2.6.4",
"webpack-dev-server": "^3.11.0"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/railsapp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4969,7 +4969,7 @@ pako@~1.0.5:
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==

parcel-bundler@^1.0.0:
parcel-bundler@^1.0.0, parcel-bundler@^1.12.4:
version "1.12.4"
resolved "https://registry.yarnpkg.com/parcel-bundler/-/parcel-bundler-1.12.4.tgz#31223f4ab4d00323a109fce28d5e46775409a9ee"
integrity sha512-G+iZGGiPEXcRzw0fiRxWYCKxdt/F7l9a0xkiU4XbcVRJCSlBnioWEwJMutOCCpoQmaQtjB4RBHDGIHN85AIhLQ==
Expand Down
6 changes: 4 additions & 2 deletions lib/snowpacker/rails/snowpacker_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def create_initializer_file
end

def add_snowpack
`yarn add snowpack parcel-bundler \
@snowpack/plugin-babel @snowpack/plugin-parcel`
`yarn add -D snowpack \
parcel-bundler \
@snowpack/plugin-babel \
@snowpack/plugin-parcel`
end
end

0 comments on commit a305177

Please sign in to comment.