webpacker-jets 3.2.100
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.eslintignore +4 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +124 -0
- data/.travis.yml +32 -0
- data/CHANGELOG.md +523 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +445 -0
- data/Rakefile +12 -0
- data/docs/assets.md +106 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +116 -0
- data/docs/deployment.md +74 -0
- data/docs/docker.md +49 -0
- data/docs/env.md +65 -0
- data/docs/es6.md +53 -0
- data/docs/folder-structure.md +66 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +223 -0
- data/docs/testing.md +128 -0
- data/docs/troubleshooting.md +119 -0
- data/docs/typescript.md +116 -0
- data/docs/webpack-dev-server.md +92 -0
- data/docs/webpack.md +297 -0
- data/docs/yarn.md +12 -0
- data/exe/webpack +8 -0
- data/exe/webpack-dev-server +8 -0
- data/gemfiles/Gemfile-rails-edge +13 -0
- data/gemfiles/Gemfile-rails.4.2.x +10 -0
- data/gemfiles/Gemfile-rails.5.0.x +10 -0
- data/gemfiles/Gemfile-rails.5.1.x +10 -0
- data/lib/install/angular.rb +27 -0
- data/lib/install/coffee.rb +22 -0
- data/lib/install/config/.babelrc +18 -0
- data/lib/install/config/.postcssrc.yml +3 -0
- data/lib/install/config/webpack/development.js +3 -0
- data/lib/install/config/webpack/environment.js +3 -0
- data/lib/install/config/webpack/production.js +3 -0
- data/lib/install/config/webpack/staging.js +3 -0
- data/lib/install/config/webpack/test.js +3 -0
- data/lib/install/config/webpacker.yml +79 -0
- data/lib/install/elm.rb +38 -0
- data/lib/install/erb.rb +22 -0
- data/lib/install/examples/angular/hello_angular.js +7 -0
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
- data/lib/install/examples/angular/hello_angular/index.ts +8 -0
- data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
- data/lib/install/examples/angular/tsconfig.json +19 -0
- data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
- data/lib/install/examples/elm/Main.elm +54 -0
- data/lib/install/examples/elm/hello_elm.js +12 -0
- data/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/lib/install/examples/react/.babelrc +6 -0
- data/lib/install/examples/react/hello_react.jsx +26 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +70 -0
- data/lib/install/javascript/packs/application.js +10 -0
- data/lib/install/loaders/coffee.js +6 -0
- data/lib/install/loaders/elm.js +23 -0
- data/lib/install/loaders/erb.js +11 -0
- data/lib/install/loaders/typescript.js +6 -0
- data/lib/install/loaders/vue.js +13 -0
- data/lib/install/react.rb +28 -0
- data/lib/install/template.rb +37 -0
- data/lib/install/vue.rb +26 -0
- data/lib/tasks/installers.rake +24 -0
- data/lib/tasks/webpacker.rake +22 -0
- data/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker/check_node.rake +24 -0
- data/lib/tasks/webpacker/check_yarn.rake +24 -0
- data/lib/tasks/webpacker/clobber.rake +16 -0
- data/lib/tasks/webpacker/compile.rake +41 -0
- data/lib/tasks/webpacker/install.rake +13 -0
- data/lib/tasks/webpacker/verify_install.rake +16 -0
- data/lib/tasks/webpacker/yarn_install.rake +6 -0
- data/lib/webpacker.rb +32 -0
- data/lib/webpacker/commands.rb +23 -0
- data/lib/webpacker/compiler.rb +88 -0
- data/lib/webpacker/configuration.rb +87 -0
- data/lib/webpacker/dev_server.rb +61 -0
- data/lib/webpacker/dev_server_proxy.rb +26 -0
- data/lib/webpacker/dev_server_runner.rb +51 -0
- data/lib/webpacker/helper.rb +66 -0
- data/lib/webpacker/instance.rb +44 -0
- data/lib/webpacker/manifest.rb +75 -0
- data/lib/webpacker/railtie.rb +82 -0
- data/lib/webpacker/rake_tasks.rb +6 -0
- data/lib/webpacker/runner.rb +22 -0
- data/lib/webpacker/version.rb +9 -0
- data/lib/webpacker/webpack_runner.rb +15 -0
- data/package.json +67 -0
- data/package/__tests__/environment.js +74 -0
- data/package/config.js +34 -0
- data/package/config_types/__tests__/config_list.js +123 -0
- data/package/config_types/__tests__/config_object.js +43 -0
- data/package/config_types/config_list.js +85 -0
- data/package/config_types/config_object.js +55 -0
- data/package/config_types/index.js +7 -0
- data/package/environment.js +116 -0
- data/package/environments/development.js +46 -0
- data/package/environments/production.js +37 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +20 -0
- data/package/rules/babel.js +13 -0
- data/package/rules/css.js +39 -0
- data/package/rules/file.js +13 -0
- data/package/rules/index.js +11 -0
- data/package/rules/sass.js +15 -0
- data/package/utils/__tests__/deep_assign.js +11 -0
- data/package/utils/__tests__/deep_merge.js +10 -0
- data/package/utils/__tests__/objectify.js +9 -0
- data/package/utils/deep_assign.js +22 -0
- data/package/utils/deep_merge.js +23 -0
- data/package/utils/helpers.js +32 -0
- data/package/utils/objectify.js +4 -0
- data/test/command_test.rb +27 -0
- data/test/compiler_test.rb +35 -0
- data/test/configuration_test.rb +69 -0
- data/test/dev_server_test.rb +24 -0
- data/test/helper_test.rb +52 -0
- data/test/manifest_test.rb +28 -0
- data/test/rake_tasks_test.rb +29 -0
- data/test/test_app/Rakefile +3 -0
- data/test/test_app/app/javascript/packs/application.js +10 -0
- data/test/test_app/config/application.rb +11 -0
- data/test/test_app/config/environment.rb +4 -0
- data/test/test_app/config/webpacker.yml +65 -0
- data/test/test_app/public/packs/manifest.json +6 -0
- data/test/test_helper.rb +29 -0
- data/webpacker-jets.gemspec +29 -0
- data/yarn.lock +5768 -0
- metadata +250 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
webpacker-jets (3.2.100)
|
5
|
+
activesupport (>= 4.2)
|
6
|
+
rack-proxy (>= 0.6.1)
|
7
|
+
railties (>= 4.2)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actioncable (5.2.1)
|
13
|
+
actionpack (= 5.2.1)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailer (5.2.1)
|
17
|
+
actionpack (= 5.2.1)
|
18
|
+
actionview (= 5.2.1)
|
19
|
+
activejob (= 5.2.1)
|
20
|
+
mail (~> 2.5, >= 2.5.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
actionpack (5.2.1)
|
23
|
+
actionview (= 5.2.1)
|
24
|
+
activesupport (= 5.2.1)
|
25
|
+
rack (~> 2.0)
|
26
|
+
rack-test (>= 0.6.3)
|
27
|
+
rails-dom-testing (~> 2.0)
|
28
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
29
|
+
actionview (5.2.1)
|
30
|
+
activesupport (= 5.2.1)
|
31
|
+
builder (~> 3.1)
|
32
|
+
erubi (~> 1.4)
|
33
|
+
rails-dom-testing (~> 2.0)
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
35
|
+
activejob (5.2.1)
|
36
|
+
activesupport (= 5.2.1)
|
37
|
+
globalid (>= 0.3.6)
|
38
|
+
activemodel (5.2.1)
|
39
|
+
activesupport (= 5.2.1)
|
40
|
+
activerecord (5.2.1)
|
41
|
+
activemodel (= 5.2.1)
|
42
|
+
activesupport (= 5.2.1)
|
43
|
+
arel (>= 9.0)
|
44
|
+
activestorage (5.2.1)
|
45
|
+
actionpack (= 5.2.1)
|
46
|
+
activerecord (= 5.2.1)
|
47
|
+
marcel (~> 0.3.1)
|
48
|
+
activesupport (5.2.1)
|
49
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
50
|
+
i18n (>= 0.7, < 2)
|
51
|
+
minitest (~> 5.1)
|
52
|
+
tzinfo (~> 1.1)
|
53
|
+
arel (9.0.0)
|
54
|
+
ast (2.4.0)
|
55
|
+
builder (3.2.3)
|
56
|
+
byebug (10.0.2)
|
57
|
+
concurrent-ruby (1.0.5)
|
58
|
+
crass (1.0.4)
|
59
|
+
erubi (1.7.1)
|
60
|
+
globalid (0.4.1)
|
61
|
+
activesupport (>= 4.2.0)
|
62
|
+
i18n (1.1.1)
|
63
|
+
concurrent-ruby (~> 1.0)
|
64
|
+
jaro_winkler (1.5.1)
|
65
|
+
loofah (2.2.3)
|
66
|
+
crass (~> 1.0.2)
|
67
|
+
nokogiri (>= 1.5.9)
|
68
|
+
mail (2.7.1)
|
69
|
+
mini_mime (>= 0.1.1)
|
70
|
+
marcel (0.3.3)
|
71
|
+
mimemagic (~> 0.3.2)
|
72
|
+
method_source (0.9.0)
|
73
|
+
mimemagic (0.3.2)
|
74
|
+
mini_mime (1.0.1)
|
75
|
+
mini_portile2 (2.3.0)
|
76
|
+
minitest (5.11.3)
|
77
|
+
nio4r (2.3.1)
|
78
|
+
nokogiri (1.8.5)
|
79
|
+
mini_portile2 (~> 2.3.0)
|
80
|
+
parallel (1.12.1)
|
81
|
+
parser (2.5.3.0)
|
82
|
+
ast (~> 2.4.0)
|
83
|
+
powerpack (0.1.2)
|
84
|
+
rack (2.0.5)
|
85
|
+
rack-proxy (0.6.5)
|
86
|
+
rack
|
87
|
+
rack-test (1.1.0)
|
88
|
+
rack (>= 1.0, < 3)
|
89
|
+
rails (5.2.1)
|
90
|
+
actioncable (= 5.2.1)
|
91
|
+
actionmailer (= 5.2.1)
|
92
|
+
actionpack (= 5.2.1)
|
93
|
+
actionview (= 5.2.1)
|
94
|
+
activejob (= 5.2.1)
|
95
|
+
activemodel (= 5.2.1)
|
96
|
+
activerecord (= 5.2.1)
|
97
|
+
activestorage (= 5.2.1)
|
98
|
+
activesupport (= 5.2.1)
|
99
|
+
bundler (>= 1.3.0)
|
100
|
+
railties (= 5.2.1)
|
101
|
+
sprockets-rails (>= 2.0.0)
|
102
|
+
rails-dom-testing (2.0.3)
|
103
|
+
activesupport (>= 4.2.0)
|
104
|
+
nokogiri (>= 1.6)
|
105
|
+
rails-html-sanitizer (1.0.4)
|
106
|
+
loofah (~> 2.2, >= 2.2.2)
|
107
|
+
railties (5.2.1)
|
108
|
+
actionpack (= 5.2.1)
|
109
|
+
activesupport (= 5.2.1)
|
110
|
+
method_source
|
111
|
+
rake (>= 0.8.7)
|
112
|
+
thor (>= 0.19.0, < 2.0)
|
113
|
+
rainbow (3.0.0)
|
114
|
+
rake (12.3.1)
|
115
|
+
rubocop (0.60.0)
|
116
|
+
jaro_winkler (~> 1.5.1)
|
117
|
+
parallel (~> 1.10)
|
118
|
+
parser (>= 2.5, != 2.5.1.1)
|
119
|
+
powerpack (~> 0.1)
|
120
|
+
rainbow (>= 2.2.2, < 4.0)
|
121
|
+
ruby-progressbar (~> 1.7)
|
122
|
+
unicode-display_width (~> 1.4.0)
|
123
|
+
ruby-progressbar (1.10.0)
|
124
|
+
sprockets (3.7.2)
|
125
|
+
concurrent-ruby (~> 1.0)
|
126
|
+
rack (> 1, < 3)
|
127
|
+
sprockets-rails (3.2.1)
|
128
|
+
actionpack (>= 4.0)
|
129
|
+
activesupport (>= 4.0)
|
130
|
+
sprockets (>= 3.0.0)
|
131
|
+
thor (0.20.0)
|
132
|
+
thread_safe (0.3.6)
|
133
|
+
tzinfo (1.2.5)
|
134
|
+
thread_safe (~> 0.1)
|
135
|
+
unicode-display_width (1.4.0)
|
136
|
+
websocket-driver (0.7.0)
|
137
|
+
websocket-extensions (>= 0.1.0)
|
138
|
+
websocket-extensions (0.1.3)
|
139
|
+
|
140
|
+
PLATFORMS
|
141
|
+
ruby
|
142
|
+
|
143
|
+
DEPENDENCIES
|
144
|
+
bundler (~> 1.12)
|
145
|
+
byebug
|
146
|
+
minitest (~> 5.0)
|
147
|
+
rack-proxy
|
148
|
+
rails
|
149
|
+
rake (>= 11.1)
|
150
|
+
rubocop (>= 0.49)
|
151
|
+
webpacker-jets!
|
152
|
+
|
153
|
+
BUNDLED WITH
|
154
|
+
1.16.3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016-2017 David Heinemeier Hansson, Basecamp
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,445 @@
|
|
1
|
+
# Webpacker
|
2
|
+
|
3
|
+
NOTE: This is a fork of [rails/webpacker](https://github.com/rails/webpacker) to work with [jets](http://rubyonjets.com/). The master branch tries to mirror the upstream repo and jets changes are actually in the [tongueroo/webpacker jets branch](https://github.com/tongueroo/webpacker/tree/jets).
|
4
|
+
|
5
|
+
In that branch the gem is also renamed and released as webpacker-jets.
|
6
|
+
|
7
|
+
## Release
|
8
|
+
|
9
|
+
git checkout jets
|
10
|
+
rake release
|
11
|
+
|
12
|
+
The rest of the Readme is the original README.
|
13
|
+
|
14
|
+
---
|
15
|
+
|
16
|
+

|
17
|
+
[](https://nodejs.org/en/)
|
18
|
+
[](https://github.com/rails/webpacker)
|
19
|
+
|
20
|
+
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
21
|
+
[webpack 3.x.x+](https://webpack.js.org/)
|
22
|
+
to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
|
23
|
+
as the primary purpose for webpack is app-like JavaScript, not images, CSS, or
|
24
|
+
even JavaScript Sprinkles (that all continues to live in app/assets).
|
25
|
+
|
26
|
+
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
|
27
|
+
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
|
28
|
+
|
29
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
30
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
31
|
+
## Table of Contents
|
32
|
+
|
33
|
+
- [Prerequisites](#prerequisites)
|
34
|
+
- [Features](#features)
|
35
|
+
- [Installation](#installation)
|
36
|
+
- [Usage](#usage)
|
37
|
+
- [Development](#development)
|
38
|
+
- [webpack configuration](#webpack-configuration)
|
39
|
+
- [Upgrading](#upgrading)
|
40
|
+
- [Yarn Integrity](#yarn-integrity)
|
41
|
+
- [Integrations](#integrations)
|
42
|
+
- [React](#react)
|
43
|
+
- [Angular with TypeScript](#angular-with-typescript)
|
44
|
+
- [Vue](#vue)
|
45
|
+
- [Elm](#elm)
|
46
|
+
- [Coffeescript](#coffeescript)
|
47
|
+
- [Erb](#erb)
|
48
|
+
- [Paths](#paths)
|
49
|
+
- [Resolved](#resolved)
|
50
|
+
- [Watched](#watched)
|
51
|
+
- [Deployment](#deployment)
|
52
|
+
- [Docs](#docs)
|
53
|
+
- [License](#license)
|
54
|
+
|
55
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
56
|
+
|
57
|
+
|
58
|
+
## Prerequisites
|
59
|
+
|
60
|
+
* Ruby 2.2+
|
61
|
+
* Rails 4.2+
|
62
|
+
* Node.js 6.0.0+
|
63
|
+
* Yarn 0.25.2+
|
64
|
+
|
65
|
+
|
66
|
+
## Features
|
67
|
+
|
68
|
+
* [webpack 3.x.x](https://webpack.js.org/)
|
69
|
+
* ES6 with [babel](https://babeljs.io/)
|
70
|
+
* Automatic code splitting using multiple entry points
|
71
|
+
* Stylesheets - Sass and CSS
|
72
|
+
* Images and fonts
|
73
|
+
* PostCSS - Auto-Prefixer
|
74
|
+
* Asset compression, source-maps, and minification
|
75
|
+
* CDN support
|
76
|
+
* React, Angular, Elm and Vue support out-of-the-box
|
77
|
+
* Rails view helpers
|
78
|
+
* Extensible and configurable
|
79
|
+
|
80
|
+
|
81
|
+
## Installation
|
82
|
+
|
83
|
+
You can either add Webpacker during setup of a new Rails 5.1+ application
|
84
|
+
using new `--webpack` option:
|
85
|
+
|
86
|
+
```bash
|
87
|
+
# Available Rails 5.1+
|
88
|
+
rails new myapp --webpack
|
89
|
+
```
|
90
|
+
|
91
|
+
Or add it to your `Gemfile`:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
# Gemfile
|
95
|
+
gem 'webpacker', '~> 3.0'
|
96
|
+
|
97
|
+
# OR if you prefer to use master
|
98
|
+
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
99
|
+
```
|
100
|
+
|
101
|
+
and finally, run following to install Webpacker:
|
102
|
+
|
103
|
+
```bash
|
104
|
+
bundle
|
105
|
+
jets webpacker:install
|
106
|
+
|
107
|
+
# OR (on rails version < 5.0)
|
108
|
+
bundle exec rake webpacker:install
|
109
|
+
```
|
110
|
+
|
111
|
+
|
112
|
+
### Usage
|
113
|
+
|
114
|
+
Once installed you can start writing modern ES6-flavored JavaScript app today:
|
115
|
+
|
116
|
+
```yml
|
117
|
+
app/javascript:
|
118
|
+
├── packs:
|
119
|
+
│ # only webpack entry files here
|
120
|
+
│ └── application.js
|
121
|
+
└── src:
|
122
|
+
│ └── application.css
|
123
|
+
└── images:
|
124
|
+
└── logo.svg
|
125
|
+
```
|
126
|
+
|
127
|
+
You can then link the JavaScript pack in Rails view using `javascript_pack_tag` helper.
|
128
|
+
If you have styles imported in your pack file, you can link using `stylesheet_pack_tag`:
|
129
|
+
|
130
|
+
```erb
|
131
|
+
<%= javascript_pack_tag 'application' %>
|
132
|
+
<%= stylesheet_pack_tag 'application' %>
|
133
|
+
```
|
134
|
+
|
135
|
+
If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
|
136
|
+
can use `asset_pack_path` helper:
|
137
|
+
|
138
|
+
```erb
|
139
|
+
<link rel="prefetch" href="<%= asset_pack_path 'application.css' %>" />
|
140
|
+
<img src="<%= asset_pack_path 'images/logo.svg' %>" />
|
141
|
+
```
|
142
|
+
|
143
|
+
**Note:** In order for your styles or static assets files to be available in your view,
|
144
|
+
you would need to link them in your "pack" or entry file.
|
145
|
+
|
146
|
+
|
147
|
+
### Development
|
148
|
+
|
149
|
+
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
|
150
|
+
Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js`
|
151
|
+
executable to ensure that the right configuration file and environment variables
|
152
|
+
are loaded depending on your environment.
|
153
|
+
|
154
|
+
In development, Webpacker compiles on demand rather than upfront by default. This
|
155
|
+
happens when you refer to any of the pack assets using the Webpacker helper methods.
|
156
|
+
That means you don't have to run any separate process. Compilation errors are logged
|
157
|
+
to the standard Rails log.
|
158
|
+
|
159
|
+
If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/webpack-dev-server` or `ruby ./bin/webpack-dev-server` if on windows,
|
160
|
+
in a separate terminal from `bundle exec rails s`. This process will watch for changes
|
161
|
+
in the `app/javascript/packs/*.js` files and automatically reload the browser to match.
|
162
|
+
|
163
|
+
```bash
|
164
|
+
# webpack dev server
|
165
|
+
./bin/webpack-dev-server
|
166
|
+
|
167
|
+
# watcher
|
168
|
+
./bin/webpack --colors --progress
|
169
|
+
|
170
|
+
# standalone build
|
171
|
+
./bin/webpack
|
172
|
+
```
|
173
|
+
|
174
|
+
Once you start this development server, Webpacker will automatically start proxying all
|
175
|
+
webpack asset requests to this server. When you stop the server, it'll revert to
|
176
|
+
on-demand compilation again.
|
177
|
+
|
178
|
+
You can use environment variables as options supported by
|
179
|
+
[webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
|
180
|
+
form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environment
|
181
|
+
variables will always take precedence over the ones already set in the
|
182
|
+
configuration file, and that the _same_ environment variables must
|
183
|
+
be available to the `rails server` process.
|
184
|
+
|
185
|
+
```bash
|
186
|
+
WEBPACKER_DEV_SERVER_HOST=example.com WEBPACKER_DEV_SERVER_INLINE=true WEBPACKER_DEV_SERVER_HOT=false ./bin/webpack-dev-server
|
187
|
+
```
|
188
|
+
|
189
|
+
By default, webpack dev server listens on `localhost` in development for security
|
190
|
+
but if you want your app to be available over local LAN IP or VM instance like vagrant
|
191
|
+
you can set the `host` when running `./bin/webpack-dev-server` binstub:
|
192
|
+
|
193
|
+
```bash
|
194
|
+
WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
195
|
+
```
|
196
|
+
|
197
|
+
**Note:** You need to allow webpack-dev-server host as allowed origin for `connect-src` if you are running your application in a restrict CSP environment like Rails 5.2+. This can be done in Rails 5.2+ for development environment in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this:
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
p.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?
|
201
|
+
```
|
202
|
+
|
203
|
+
**Note:** Don't forget to prefix `ruby` when running these binstubs on windows
|
204
|
+
|
205
|
+
### webpack configuration
|
206
|
+
|
207
|
+
See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
|
208
|
+
|
209
|
+
|
210
|
+
### Upgrading
|
211
|
+
|
212
|
+
You can run following commands to upgrade Webpacker to the latest stable version, this involves upgrading the gem and related npm modules:
|
213
|
+
|
214
|
+
```bash
|
215
|
+
bundle update webpacker
|
216
|
+
yarn upgrade @rails/webpacker --latest
|
217
|
+
yarn upgrade webpack-dev-server --latest
|
218
|
+
```
|
219
|
+
|
220
|
+
### Yarn Integrity
|
221
|
+
|
222
|
+
By default in development, webpacker runs a yarn integrity check to ensure that all local npm packages are up-to-date. This is similar to what bundler does currently in Rails, but for JavaScript packages. If your system is out of date, then Rails will not initialize and you will be asked to upgrade your local npm packages by running `yarn install`.
|
223
|
+
|
224
|
+
To turn off this option, you will need to override the default by adding a new config options to your Rails development environment configuration file (`config/environment/development.rb`):
|
225
|
+
|
226
|
+
```
|
227
|
+
config.webpacker.check_yarn_integrity = false
|
228
|
+
```
|
229
|
+
|
230
|
+
You may also turn on this option by adding the config option to any Rails environment configuration file:
|
231
|
+
|
232
|
+
```
|
233
|
+
config.webpacker.check_yarn_integrity = true
|
234
|
+
```
|
235
|
+
|
236
|
+
## Integrations
|
237
|
+
|
238
|
+
Webpacker ships with basic out-of-the-box integration for React, Angular, Vue and Elm.
|
239
|
+
You can see a list of available commands/tasks by running `jets webpacker`:
|
240
|
+
|
241
|
+
### React
|
242
|
+
|
243
|
+
To use Webpacker with [React](https://facebook.github.io/react/), create a
|
244
|
+
new Rails 5.1+ app using `--webpack=react` option:
|
245
|
+
|
246
|
+
```bash
|
247
|
+
# Rails 5.1+
|
248
|
+
rails new myapp --webpack=react
|
249
|
+
```
|
250
|
+
|
251
|
+
(or run `jets webpacker:install:react` in a existing Rails app already
|
252
|
+
setup with Webpacker).
|
253
|
+
|
254
|
+
The installer will add all relevant dependencies using Yarn, any changes
|
255
|
+
to the configuration files and an example React component to your
|
256
|
+
project in `app/javascript/packs` so that you can experiment with React right away.
|
257
|
+
|
258
|
+
|
259
|
+
### Angular with TypeScript
|
260
|
+
|
261
|
+
To use Webpacker with [Angular](https://angular.io/), create a
|
262
|
+
new Rails 5.1+ app using `--webpack=angular` option:
|
263
|
+
|
264
|
+
```bash
|
265
|
+
# Rails 5.1+
|
266
|
+
rails new myapp --webpack=angular
|
267
|
+
```
|
268
|
+
|
269
|
+
(or run `jets webpacker:install:angular` on a Rails app already
|
270
|
+
setup with Webpacker).
|
271
|
+
|
272
|
+
The installer will add TypeScript and Angular core libraries using Yarn plus
|
273
|
+
any changes to the configuration files. An example component is written in
|
274
|
+
TypeScript will also be added to your project in `app/javascript` so that
|
275
|
+
you can experiment with Angular right away.
|
276
|
+
|
277
|
+
By default Angular uses a JIT compiler for development environment, this
|
278
|
+
compiler is not compatible with restrictive CSP (Content Security
|
279
|
+
Policy) environments like Rails 5.2+. You can use Angular AOT compiler
|
280
|
+
in development with the [@ngtools/webpack](https://www.npmjs.com/package/@ngtools/webpack#usage) plugin.
|
281
|
+
|
282
|
+
Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for
|
283
|
+
development environment, this can be done in the `config/initializers/content_security_policy.rb`
|
284
|
+
with the following configuration:
|
285
|
+
|
286
|
+
```ruby
|
287
|
+
if Rails.env.development?
|
288
|
+
p.script_src :self, :https, :unsafe_eval
|
289
|
+
else
|
290
|
+
p.script_src :self, :https
|
291
|
+
end
|
292
|
+
```
|
293
|
+
|
294
|
+
|
295
|
+
### Vue
|
296
|
+
|
297
|
+
To use Webpacker with [Vue](https://vuejs.org/), create a
|
298
|
+
new Rails 5.1+ app using `--webpack=vue` option:
|
299
|
+
|
300
|
+
```bash
|
301
|
+
# Rails 5.1+
|
302
|
+
rails new myapp --webpack=vue
|
303
|
+
```
|
304
|
+
(or run `jets webpacker:install:vue` on a Rails app already setup with Webpacker).
|
305
|
+
|
306
|
+
The installer will add Vue and required libraries using Yarn plus
|
307
|
+
any changes to the configuration files. An example component will
|
308
|
+
also be added to your project in `app/javascript` so that you can
|
309
|
+
experiment Vue right away.
|
310
|
+
|
311
|
+
If you're using Rails 5.2+ you need to enable `unsafe-eval` rule for development environment,
|
312
|
+
this can be done in the `config/initializers/content_security_policy.rb` with the following
|
313
|
+
configuration:
|
314
|
+
|
315
|
+
```ruby
|
316
|
+
if Rails.env.development?
|
317
|
+
p.script_src :self, :https, :unsafe_eval
|
318
|
+
else
|
319
|
+
p.script_src :self, :https
|
320
|
+
end
|
321
|
+
```
|
322
|
+
You can read more this in [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
|
323
|
+
|
324
|
+
|
325
|
+
### Elm
|
326
|
+
|
327
|
+
To use Webpacker with [Elm](http://elm-lang.org), create a
|
328
|
+
new Rails 5.1+ app using `--webpack=elm` option:
|
329
|
+
|
330
|
+
```
|
331
|
+
# Rails 5.1+
|
332
|
+
rails new myapp --webpack=elm
|
333
|
+
```
|
334
|
+
|
335
|
+
(or run `jets webpacker:install:elm` on a Rails app already setup with Webpacker).
|
336
|
+
|
337
|
+
The Elm library and core packages will be added via Yarn and Elm itself.
|
338
|
+
An example `Main.elm` app will also be added to your project in `app/javascript`
|
339
|
+
so that you can experiment with Elm right away.
|
340
|
+
|
341
|
+
### Coffeescript
|
342
|
+
|
343
|
+
To add [Coffeescript](http://coffeescript.org/) support,
|
344
|
+
run `bundle exec rails webpacker:install:coffee` on a Rails app already
|
345
|
+
setup with Webpacker.
|
346
|
+
|
347
|
+
An example `hello_coffee.coffee` file will also be added to your project
|
348
|
+
in `app/javascript/packs` so that you can experiment with Coffeescript right away.
|
349
|
+
|
350
|
+
### Erb
|
351
|
+
|
352
|
+
To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates,
|
353
|
+
run `bundle exec rails webpacker:install:erb` on a Rails app already
|
354
|
+
setup with Webpacker.
|
355
|
+
|
356
|
+
An example `hello_erb.js.erb` file will also be added to your project
|
357
|
+
in `app/javascript/packs` so that you can experiment with Erb flavoured
|
358
|
+
javascript right away.
|
359
|
+
|
360
|
+
|
361
|
+
## Paths
|
362
|
+
|
363
|
+
By default, Webpacker ships with simple conventions for where the JavaScript
|
364
|
+
app files and compiled webpack bundles will go in your Rails app,
|
365
|
+
but all these options are configurable from `config/webpacker.yml` file.
|
366
|
+
|
367
|
+
The configuration for what webpack is supposed to compile by default rests
|
368
|
+
on the convention that every file in `app/javascript/packs/*`**(default)**
|
369
|
+
or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
|
370
|
+
is turned into their own output files (or entry points, as webpack calls it). Therefore you don't want to put anything inside `packs` directory that you do not want to be
|
371
|
+
an entry file. As a rule of thumb, put all files you want to link in your views inside
|
372
|
+
"packs" directory and keep everything else under `app/javascript`.
|
373
|
+
|
374
|
+
Suppose you want to change the source directory from `app/javascript`
|
375
|
+
to `frontend` and output to `assets/packs`. This is how you would do it:
|
376
|
+
|
377
|
+
```yml
|
378
|
+
# config/webpacker.yml
|
379
|
+
source_path: frontend
|
380
|
+
source_entry_path: packs
|
381
|
+
public_output_path: assets/packs # outputs to => public/assets/packs
|
382
|
+
```
|
383
|
+
|
384
|
+
Similarly you can also control and configure `webpack-dev-server` settings from `config/webpacker.yml` file:
|
385
|
+
|
386
|
+
```yml
|
387
|
+
# config/webpacker.yml
|
388
|
+
development:
|
389
|
+
dev_server:
|
390
|
+
host: localhost
|
391
|
+
port: 3035
|
392
|
+
```
|
393
|
+
|
394
|
+
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output, as you will want to configure your styles to be inlined in your JavaScript for hot reloading. During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
|
395
|
+
|
396
|
+
|
397
|
+
### Resolved
|
398
|
+
|
399
|
+
If you are adding Webpacker to an existing app that has most of the assets inside
|
400
|
+
`app/assets` or inside an engine and you want to share that
|
401
|
+
with webpack modules then you can use `resolved_paths`
|
402
|
+
option available in `config/webpacker.yml`, which lets you
|
403
|
+
add additional paths webpack should lookup when resolving modules:
|
404
|
+
|
405
|
+
```yml
|
406
|
+
resolved_paths: ['app/assets']
|
407
|
+
```
|
408
|
+
|
409
|
+
You can then import them inside your modules like so:
|
410
|
+
|
411
|
+
```js
|
412
|
+
// Note it's relative to parent directory i.e. app/assets
|
413
|
+
import 'stylesheets/main'
|
414
|
+
import 'images/rails.png'
|
415
|
+
```
|
416
|
+
|
417
|
+
**Note:** Please be careful when adding paths here otherwise it
|
418
|
+
will make the compilation slow, consider adding specific paths instead of
|
419
|
+
whole parent directory if you just need to reference one or two modules
|
420
|
+
|
421
|
+
|
422
|
+
### Watched
|
423
|
+
|
424
|
+
By default, the lazy compilation is cached until a file is changed under
|
425
|
+
tracked paths. You can configure the paths tracked
|
426
|
+
by adding new paths to `watched_paths` array, much like Rails `autoload_paths`:
|
427
|
+
|
428
|
+
```rb
|
429
|
+
# config/initializers/webpacker.rb
|
430
|
+
# or config/application.rb
|
431
|
+
Webpacker::Compiler.watched_paths << 'bower_components'
|
432
|
+
```
|
433
|
+
|
434
|
+
|
435
|
+
## Deployment
|
436
|
+
|
437
|
+
Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets `webpacker:compile` is automatically aliased to `assets:precompile`. Remember to set NODE_ENV environment variable to production during deployment or when running the rake task.
|
438
|
+
|
439
|
+
## Docs
|
440
|
+
|
441
|
+
You can find more detailed guides under [docs](./docs).
|
442
|
+
|
443
|
+
|
444
|
+
## License
|
445
|
+
Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
|