webpacker 5.4.0 → 6.0.0.rc.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -1
- data/.github/workflows/jest.yml +7 -15
- data/.github/workflows/js-lint.yml +7 -15
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +18 -36
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +5 -4
- data/CHANGELOG.md +45 -9
- data/CONTRIBUTING.md +20 -1
- data/Gemfile.lock +83 -83
- data/README.md +394 -180
- data/config/README.md +3 -0
- data/config/webpacker.yml +1 -0
- data/docs/deployment.md +9 -11
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +61 -25
- data/docs/v6_upgrade.md +113 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/{javascript/packs/application.js → application.js} +2 -5
- data/lib/install/bin/webpack +4 -7
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpack/base.js +3 -0
- data/lib/install/config/webpack/development.js +2 -2
- data/lib/install/config/webpack/production.js +2 -2
- data/lib/install/config/webpack/test.js +2 -2
- data/lib/install/config/webpacker.yml +21 -49
- data/lib/install/package.json +15 -0
- data/lib/install/template.rb +63 -28
- data/lib/tasks/webpacker/binstubs.rake +6 -4
- data/lib/tasks/webpacker/check_binstubs.rake +4 -4
- data/lib/tasks/webpacker/check_node.rake +3 -0
- data/lib/tasks/webpacker/check_yarn.rake +4 -1
- data/lib/tasks/webpacker/clobber.rake +1 -1
- data/lib/tasks/webpacker/compile.rake +4 -2
- data/lib/tasks/webpacker/info.rake +12 -10
- data/lib/tasks/webpacker/install.rake +6 -4
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -10
- data/lib/tasks/webpacker/yarn_install.rake +9 -7
- data/lib/tasks/webpacker.rake +2 -11
- data/lib/tasks/yarn.rake +38 -0
- data/lib/webpacker/commands.rb +21 -16
- data/lib/webpacker/compiler.rb +16 -9
- data/lib/webpacker/configuration.rb +8 -32
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +28 -4
- data/lib/webpacker/helper.rb +47 -81
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +2 -3
- data/lib/webpacker/railtie.rb +8 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +29 -3
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/config.js +5 -37
- data/package/__tests__/development.js +13 -21
- data/package/__tests__/env.js +16 -4
- data/package/__tests__/index.js +9 -0
- data/package/__tests__/production.js +6 -6
- data/package/__tests__/staging.js +7 -6
- data/package/__tests__/test.js +4 -5
- data/package/babel/preset.js +54 -0
- data/package/config.js +6 -14
- data/package/env.js +13 -4
- data/package/environments/__tests__/base.js +20 -52
- data/package/environments/base.js +68 -128
- data/package/environments/development.js +49 -47
- data/package/environments/production.js +66 -64
- data/package/environments/test.js +2 -2
- data/package/index.js +15 -8
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +10 -8
- data/package/rules/coffee.js +6 -0
- data/package/rules/erb.js +15 -0
- data/package/rules/file.js +21 -19
- data/package/rules/index.js +16 -18
- data/package/rules/less.js +22 -0
- data/package/rules/raw.js +5 -0
- data/package/rules/sass.js +9 -10
- data/package/rules/stylus.js +26 -0
- data/package/utils/get_style_rule.js +28 -36
- data/package/utils/helpers.js +28 -35
- data/package.json +23 -43
- data/test/command_test.rb +76 -0
- data/test/compiler_test.rb +0 -12
- data/test/configuration_test.rb +4 -35
- data/test/dev_server_runner_test.rb +36 -6
- data/test/engine_rake_tasks_test.rb +39 -0
- data/test/helper_test.rb +76 -62
- data/test/manifest_test.rb +16 -0
- data/test/mounted_app/Rakefile +4 -0
- data/test/mounted_app/test/dummy/Rakefile +3 -0
- data/test/mounted_app/test/dummy/bin/rails +3 -0
- data/test/mounted_app/test/dummy/bin/rake +3 -0
- data/test/mounted_app/test/dummy/config/application.rb +10 -0
- data/test/mounted_app/test/dummy/config/environment.rb +3 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
- data/test/mounted_app/test/dummy/config.ru +5 -0
- data/test/mounted_app/test/dummy/package.json +7 -0
- data/test/rake_tasks_test.rb +1 -10
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
- data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/test/test_app/config/webpacker.yml +5 -31
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/config/webpacker_public_root.yml +0 -1
- data/test/test_app/public/packs/manifest.json +36 -18
- data/test/test_app/some.config.js +0 -0
- data/test/webpack_runner_test.rb +9 -3
- data/test/webpacker_test.rb +21 -0
- data/webpacker.gemspec +2 -2
- data/yarn.lock +2183 -6524
- metadata +63 -93
- data/.travis.yml +0 -43
- data/docs/assets.md +0 -119
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -308
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -63
- data/docs/es6.md +0 -72
- data/docs/folder-structure.md +0 -66
- data/docs/integrations.md +0 -220
- data/docs/misc.md +0 -23
- data/docs/props.md +0 -223
- data/docs/target.md +0 -22
- data/docs/testing.md +0 -136
- data/docs/typescript.md +0 -190
- data/docs/v4-upgrade.md +0 -142
- data/docs/webpack-dev-server.md +0 -92
- data/docs/webpack.md +0 -364
- data/docs/yarn.md +0 -23
- data/lib/install/angular.rb +0 -23
- data/lib/install/coffee.rb +0 -25
- data/lib/install/config/.browserslistrc +0 -1
- data/lib/install/config/babel.config.js +0 -70
- data/lib/install/config/postcss.config.js +0 -12
- data/lib/install/config/webpack/environment.js +0 -3
- data/lib/install/elm.rb +0 -39
- data/lib/install/erb.rb +0 -25
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
- data/lib/install/examples/angular/hello_angular/index.ts +0 -8
- data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
- data/lib/install/examples/angular/hello_angular.js +0 -7
- data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
- data/lib/install/examples/elm/Main.elm +0 -55
- data/lib/install/examples/elm/hello_elm.js +0 -16
- data/lib/install/examples/erb/hello_erb.js.erb +0 -6
- data/lib/install/examples/react/babel.config.js +0 -87
- data/lib/install/examples/react/hello_react.jsx +0 -26
- data/lib/install/examples/react/tsconfig.json +0 -21
- data/lib/install/examples/stimulus/application.js +0 -1
- data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
- data/lib/install/examples/stimulus/controllers/index.js +0 -9
- data/lib/install/examples/svelte/app.svelte +0 -11
- data/lib/install/examples/svelte/hello_svelte.js +0 -20
- data/lib/install/examples/typescript/hello_typescript.ts +0 -4
- data/lib/install/examples/typescript/tsconfig.json +0 -24
- data/lib/install/examples/vue/app.vue +0 -22
- data/lib/install/examples/vue/hello_vue.js +0 -72
- data/lib/install/loaders/coffee.js +0 -6
- data/lib/install/loaders/elm.js +0 -25
- data/lib/install/loaders/erb.js +0 -11
- data/lib/install/loaders/svelte.js +0 -9
- data/lib/install/loaders/vue.js +0 -6
- data/lib/install/react.rb +0 -18
- data/lib/install/stimulus.rb +0 -12
- data/lib/install/svelte.rb +0 -29
- data/lib/install/typescript.rb +0 -39
- data/lib/install/vue.rb +0 -49
- data/lib/tasks/installers.rake +0 -42
- data/package/config_types/__tests__/config_list.js +0 -118
- data/package/config_types/__tests__/config_object.js +0 -43
- data/package/config_types/config_list.js +0 -75
- data/package/config_types/config_object.js +0 -55
- data/package/config_types/index.js +0 -7
- data/package/rules/module.css.js +0 -3
- data/package/rules/module.sass.js +0 -8
- data/package/rules/node_modules.js +0 -22
- data/package/utils/__tests__/deep_assign.js +0 -32
- data/package/utils/__tests__/deep_merge.js +0 -10
- data/package/utils/__tests__/get_style_rule.js +0 -65
- data/package/utils/__tests__/objectify.js +0 -9
- data/package/utils/deep_assign.js +0 -22
- data/package/utils/deep_merge.js +0 -22
- data/package/utils/objectify.js +0 -3
- /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
- /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
data/README.md
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# Webpacker
|
2
2
|
|
3
|
-
[![
|
4
|
-
[![
|
3
|
+
[![Ruby specs](https://github.com/rails/webpacker/workflows/Ruby%20specs/badge.svg)](https://github.com/rails/webpacker/actions)
|
4
|
+
[![Jest specs](https://github.com/rails/webpacker/workflows/Jest%20specs/badge.svg)](https://github.com/rails/webpacker/actions)
|
5
|
+
[![Rubocop](https://github.com/rails/webpacker/workflows/Rubocop/badge.svg)](https://github.com/rails/webpacker/actions)
|
6
|
+
[![JS lint](https://github.com/rails/webpacker/workflows/JS%20lint/badge.svg)](https://github.com/rails/webpacker/actions)
|
7
|
+
|
8
|
+
[![node.js](https://img.shields.io/badge/node-%3E%3D%2012.0.0-brightgreen.svg)](https://www.npmjs.com/package/@rails/webpacker)
|
5
9
|
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://rubygems.org/gems/webpacker)
|
6
10
|
|
7
11
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
8
|
-
[
|
9
|
-
to manage application-like JavaScript in Rails. It
|
10
|
-
|
11
|
-
even JavaScript Sprinkles (that all continues to live in app/assets).
|
12
|
-
|
13
|
-
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
|
14
|
-
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
|
12
|
+
[Webpack v5](https://webpack.js.org/)
|
13
|
+
to manage application-like JavaScript in Rails. It can coexist with the asset pipeline,
|
14
|
+
leaving Webpack responsible solely for app-like JavaScript, or it can be used exclusively, making it also responsible for images, fonts, and CSS.
|
15
15
|
|
16
|
-
**NOTE:** The master branch now hosts the code for
|
16
|
+
**NOTE:** The master branch now hosts the code for v6.x.x. Please refer to [5-x-stable](https://github.com/rails/webpacker/tree/5-x-stable) branch for 5.x documentation.
|
17
17
|
|
18
18
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
19
19
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
@@ -22,27 +22,29 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
22
22
|
|
23
23
|
- [Prerequisites](#prerequisites)
|
24
24
|
- [Features](#features)
|
25
|
+
- [Optional support](#optional-support)
|
25
26
|
- [Installation](#installation)
|
26
27
|
- [Usage](#usage)
|
28
|
+
- [Server-Side Rendering (SSR)](#server-side-rendering-ssr)
|
27
29
|
- [Development](#development)
|
28
30
|
- [Webpack Configuration](#webpack-configuration)
|
31
|
+
- [Babel Configuration](#babel-configuration)
|
32
|
+
- [Integrations](#integrations)
|
33
|
+
- [React](#react)
|
34
|
+
- [CoffeeScript](#coffeescript)
|
35
|
+
- [TypeScript](#typescript)
|
36
|
+
- [CSS](#css)
|
37
|
+
- [Postcss](#postcss)
|
38
|
+
- [Sass](#sass)
|
39
|
+
- [Less](#less)
|
40
|
+
- [Stylus](#stylus)
|
41
|
+
- [Other frameworks](#other-frameworks)
|
29
42
|
- [Custom Rails environments](#custom-rails-environments)
|
30
43
|
- [Upgrading](#upgrading)
|
31
|
-
- [Integrations](#integrations)
|
32
|
-
- [React](./docs/integrations.md#react)
|
33
|
-
- [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
|
34
|
-
- [Vue](./docs/integrations.md#vue)
|
35
|
-
- [Elm](./docs/integrations.md#elm)
|
36
|
-
- [Stimulus](./docs/integrations.md#stimulus)
|
37
|
-
- [Svelte](./docs/integrations.md#svelte)
|
38
|
-
- [Typescript](./docs/typescript.md)
|
39
|
-
- [CoffeeScript](./docs/integrations.md#coffeescript)
|
40
|
-
- [Erb](./docs/integrations.md#erb)
|
41
44
|
- [Paths](#paths)
|
42
|
-
- [
|
43
|
-
- [Watched](#watched)
|
45
|
+
- [Additional paths](#additional-paths)
|
44
46
|
- [Deployment](#deployment)
|
45
|
-
- [
|
47
|
+
- [Troubleshooting](#troubleshooting)
|
46
48
|
- [Contributing](#contributing)
|
47
49
|
- [License](#license)
|
48
50
|
|
@@ -52,59 +54,52 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
52
54
|
|
53
55
|
- Ruby 2.4+
|
54
56
|
- Rails 5.2+
|
55
|
-
- Node.js
|
56
|
-
- Yarn
|
57
|
+
- Node.js 12.13.0+ || 14+
|
58
|
+
- Yarn
|
57
59
|
|
58
60
|
## Features
|
59
61
|
|
60
|
-
- [
|
62
|
+
- [Webpack v5](https://webpack.js.org/)
|
61
63
|
- ES6 with [babel](https://babeljs.io/)
|
62
64
|
- Automatic code splitting using multiple entry points
|
63
|
-
- Stylesheets - Sass and CSS
|
64
|
-
- Images and fonts
|
65
|
-
- PostCSS - Auto-Prefixer
|
66
65
|
- Asset compression, source-maps, and minification
|
67
66
|
- CDN support
|
68
|
-
- React, Angular, Elm and Vue support out-of-the-box
|
69
67
|
- Rails view helpers
|
70
68
|
- Extensible and configurable
|
71
69
|
|
70
|
+
### Optional support
|
71
|
+
|
72
|
+
_requires extra packages to be installed_
|
73
|
+
|
74
|
+
- Stylesheets - Sass, Less, Stylus and Css, PostCSS
|
75
|
+
- CoffeeScript
|
76
|
+
- TypeScript
|
77
|
+
- React
|
78
|
+
|
72
79
|
## Installation
|
73
80
|
|
74
|
-
You can
|
75
|
-
using new `--webpack` option:
|
81
|
+
You can configure a new Rails application with Webpacker right from the start using the `-j webpack` option:
|
76
82
|
|
77
83
|
```bash
|
78
|
-
|
79
|
-
rails new myapp --webpack
|
84
|
+
rails new myapp -j webpack
|
80
85
|
```
|
81
86
|
|
82
|
-
Or add it
|
87
|
+
Or you can add it later by changing your `Gemfile`:
|
83
88
|
|
84
89
|
```ruby
|
85
90
|
# Gemfile
|
86
|
-
gem 'webpacker', '~>
|
91
|
+
gem 'webpacker', '~> 6.0'
|
87
92
|
|
88
93
|
# OR if you prefer to use master
|
89
94
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
90
95
|
yarn add https://github.com/rails/webpacker.git
|
91
|
-
yarn add core-js regenerator-runtime
|
92
|
-
```
|
93
|
-
|
94
|
-
Finally, run the following to install Webpacker:
|
95
|
-
|
96
|
-
```bash
|
97
|
-
bundle
|
98
|
-
bundle exec rails webpacker:install
|
99
|
-
|
100
|
-
# OR (on rails version < 5.0)
|
101
|
-
bundle exec rake webpacker:install
|
102
96
|
```
|
103
97
|
|
104
|
-
|
98
|
+
Then running the following to install Webpacker:
|
105
99
|
|
106
100
|
```bash
|
107
|
-
|
101
|
+
./bin/bundle install
|
102
|
+
./bin/rails webpacker:install
|
108
103
|
```
|
109
104
|
|
110
105
|
When `package.json` and/or `yarn.lock` changes, such as when pulling down changes to your local environment in a team settings, be sure to keep your NPM packages up-to-date:
|
@@ -119,10 +114,9 @@ Once installed, you can start writing modern ES6-flavored JavaScript apps right
|
|
119
114
|
|
120
115
|
```yml
|
121
116
|
app/javascript:
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
│ └── application.css
|
117
|
+
# Only Webpack entry files here
|
118
|
+
└── application.js
|
119
|
+
└── application.css
|
126
120
|
└── src:
|
127
121
|
│ └── my_component.js
|
128
122
|
└── stylesheets:
|
@@ -131,102 +125,116 @@ app/javascript:
|
|
131
125
|
└── logo.svg
|
132
126
|
```
|
133
127
|
|
134
|
-
|
135
|
-
|
136
|
-
```js
|
137
|
-
import 'core-js/stable'
|
138
|
-
import 'regenerator-runtime/runtime'
|
139
|
-
```
|
140
|
-
|
141
|
-
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
|
142
|
-
If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
|
128
|
+
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper. If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
|
143
129
|
|
144
130
|
```erb
|
145
131
|
<%= javascript_pack_tag 'application' %>
|
146
132
|
<%= stylesheet_pack_tag 'application' %>
|
147
133
|
```
|
148
134
|
|
149
|
-
|
150
|
-
|
135
|
+
The `javascript_pack_tag` and `stylesheet_pack_tag` helpers will include all the transpiled
|
136
|
+
packs with the chunks in your view, which creates html tags for all the chunks.
|
137
|
+
|
138
|
+
The result looks like this:
|
151
139
|
|
152
140
|
```erb
|
153
|
-
|
154
|
-
|
141
|
+
<%= javascript_pack_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
|
142
|
+
|
143
|
+
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
|
144
|
+
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
|
145
|
+
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload" defer"></script>
|
146
|
+
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
|
147
|
+
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
|
155
148
|
```
|
156
149
|
|
157
|
-
|
158
|
-
|
150
|
+
**Important:** Pass all your pack names as multiple arguments, not multiple calls, when using `javascript_pack_tag` and the **`stylesheet_pack_tag`. Otherwise, you will get duplicated chunks on the page. Be especially careful if you might be calling these view helpers from your view, partials, and the layout for a page. You will need some logic to ensure you call the helpers only once with multiple arguments.
|
151
|
+
|
152
|
+
```erb
|
153
|
+
<%# DO %>
|
154
|
+
<%= javascript_pack_tag 'calendar', 'map' %>
|
155
|
+
<%= stylesheet_pack_tag 'calendar', 'map' %>
|
156
|
+
|
157
|
+
<%# DON'T %>
|
158
|
+
<%= javascript_pack_tag 'calendar' %>
|
159
|
+
<%= javascript_pack_tag 'map' %>
|
160
|
+
<%= stylesheet_pack_tag 'calendar' %>
|
161
|
+
<%= stylesheet_pack_tag 'map' %>
|
162
|
+
```
|
159
163
|
|
164
|
+
If you want to link a static asset for `<img />` tag, you can use the `asset_pack_path` helper:
|
160
165
|
```erb
|
161
|
-
<%=
|
166
|
+
<img src="<%= asset_pack_path 'images/logo.svg' %>" />
|
167
|
+
```
|
162
168
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
169
|
+
Or use the dedicated helper:
|
170
|
+
```erb
|
171
|
+
<%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
|
172
|
+
<%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
|
168
173
|
```
|
169
174
|
|
170
|
-
|
171
|
-
|
175
|
+
If you want to create a favicon:
|
176
|
+
```erb
|
177
|
+
<%= favicon_pack_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %>
|
178
|
+
```
|
172
179
|
|
180
|
+
If you want to preload a static asset in your `<head>`, you can use the `preload_pack_asset` helper:
|
173
181
|
```erb
|
174
|
-
|
175
|
-
|
182
|
+
<%= preload_pack_asset 'fonts/fa-regular-400.woff2' %>
|
183
|
+
```
|
176
184
|
|
177
|
-
|
178
|
-
|
179
|
-
|
185
|
+
If you want to use images in your stylesheets:
|
186
|
+
|
187
|
+
```css
|
188
|
+
.foo {
|
189
|
+
background-image: url('../images/logo.svg')
|
190
|
+
}
|
180
191
|
```
|
192
|
+
##### Defer for `javascript_pack_tag`
|
193
|
+
Note, the default of "defer" for the `javascript_pack_tag`. You can override that to `false`. If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/packs/entrypoints/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
|
181
194
|
|
182
|
-
|
183
|
-
|
195
|
+
#### Server-Side Rendering (SSR)
|
196
|
+
|
197
|
+
Note, if you are using server-side rendering of JavaScript with dynamic code-splitting, as is often done with extensions to Webpacker, like [React on Rails](https://github.com/shakacode/react_on_rails), your JavaScript should create the link prefetch HTML tags that you will use, so you won't need to use to `asset_pack_path` in those circumstances.
|
198
|
+
|
199
|
+
**Note:** In order for your styles or static assets files to be available in your view, you would need to link them in your "pack" or entry file. Otherwise, Webpack won't know to package up those files.
|
184
200
|
|
185
201
|
### Development
|
186
202
|
|
187
|
-
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
|
188
|
-
Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js`
|
189
|
-
executables to ensure that the right configuration files and environmental variables
|
190
|
-
are loaded based on your environment.
|
203
|
+
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`. Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js` executables to ensure that the right configuration files and environmental variables are loaded based on your environment.
|
191
204
|
|
192
|
-
In development, Webpacker compiles on demand rather than upfront by default. This
|
193
|
-
happens when you refer to any of the pack assets using the Webpacker helper methods.
|
194
|
-
This means that you don't have to run any separate processes. Compilation errors are logged
|
195
|
-
to the standard Rails log.
|
205
|
+
In development, Webpacker compiles on demand rather than upfront by default. This happens when you refer to any of the pack assets using the Webpacker helper methods. This means that you don't have to run any separate processes. Compilation errors are logged to the standard Rails log. However, this auto-compilation happens when a web request is made that requires an updated webpack build, not when files change. Thus, that can be painfully slow for front-end development in this default way. Instead, you should either run the `bin/webpack --watch` or run `./bin/webpack-dev-server`
|
196
206
|
|
197
|
-
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`. Windows users will need to run these commands
|
198
|
-
in a terminal separate from `bundle exec rails s`. This process will watch for changes
|
199
|
-
in the `app/javascript/packs/*.js` files and automatically reload the browser to match.
|
207
|
+
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`. Windows users will need to run these commands in a terminal separate from `bundle exec rails s`. This process will watch for changes in the relevant files, defined by `webpacker.yml` configuration settings for `source_path`, `source_entry_path`, and `additional_paths`, and it will then automatically reload the browser to match. This feature is also known as [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
200
208
|
|
201
209
|
```bash
|
202
210
|
# webpack dev server
|
203
211
|
./bin/webpack-dev-server
|
204
212
|
|
205
213
|
# watcher
|
206
|
-
./bin/webpack --watch --
|
214
|
+
./bin/webpack --watch --progress
|
207
215
|
|
208
216
|
# standalone build
|
209
|
-
./bin/webpack
|
217
|
+
./bin/webpack --progress
|
218
|
+
|
219
|
+
# Help
|
220
|
+
./bin/webpack help
|
221
|
+
|
222
|
+
# Version
|
223
|
+
./bin/webpack version
|
224
|
+
|
225
|
+
# Info
|
226
|
+
./bin/webpack info
|
210
227
|
```
|
211
228
|
|
212
|
-
Once you start this development server, Webpacker will automatically start proxying all
|
213
|
-
webpack asset requests to this server. When you stop the server, it'll revert back to
|
214
|
-
on-demand compilation.
|
229
|
+
Once you start this webpack development server, Webpacker will automatically start proxying all webpack asset requests to this server. When you stop this server, Rails will detect that it's not running and Rails will revert back to on-demand compilation _if_ you have the `compile` option set to true in your `config/webpacker.yml`
|
215
230
|
|
216
|
-
You can use environment variables as options supported by
|
217
|
-
[webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
|
218
|
-
form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental
|
219
|
-
variables will always take precedence over the ones already set in the
|
220
|
-
configuration file, and that the _same_ environmental variables must
|
221
|
-
be available to the `rails server` process.
|
231
|
+
You can use environment variables as options supported by [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental variables will always take precedence over the ones already set in the configuration file, and that the _same_ environmental variables must be available to the `rails server` process.
|
222
232
|
|
223
233
|
```bash
|
224
234
|
WEBPACKER_DEV_SERVER_HOST=example.com WEBPACKER_DEV_SERVER_INLINE=true WEBPACKER_DEV_SERVER_HOT=false ./bin/webpack-dev-server
|
225
235
|
```
|
226
236
|
|
227
|
-
By default, the webpack dev server listens on `localhost` in development for security purposes.
|
228
|
-
However, if you want your app to be available over local LAN IP or a VM instance like vagrant,
|
229
|
-
you can set the `host` when running `./bin/webpack-dev-server` binstub:
|
237
|
+
By default, the webpack dev server listens on `localhost` in development for security purposes. However, if you want your app to be available over local LAN IP or a VM instance like vagrant, you can set the `host` when running `./bin/webpack-dev-server` binstub:
|
230
238
|
|
231
239
|
```bash
|
232
240
|
WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
@@ -235,16 +243,254 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
235
243
|
**Note:** You need to allow webpack-dev-server host as an 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+ in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this:
|
236
244
|
|
237
245
|
```ruby
|
238
|
-
|
239
|
-
|
240
|
-
|
246
|
+
Rails.application.config.content_security_policy do |policy|
|
247
|
+
policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?
|
248
|
+
end
|
241
249
|
```
|
242
250
|
|
243
251
|
**Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
|
244
252
|
|
253
|
+
|
245
254
|
### Webpack Configuration
|
246
255
|
|
247
|
-
|
256
|
+
Webpacker gives you a default set of configuration files for test, development and production environments in `config/webpack/*.js`. You can configure each individual environment in their respective files or configure them all in the base
|
257
|
+
`config/webpack/base.js` file.
|
258
|
+
|
259
|
+
By default, you don't need to make any changes to `config/webpack/*.js` files since it's all standard production-ready configuration. However, if you do need to customize or add a new loader, this is where you would go.
|
260
|
+
|
261
|
+
Here is how you can modify webpack configuration:
|
262
|
+
|
263
|
+
You might add separate files to keep your code more organized.
|
264
|
+
|
265
|
+
```js
|
266
|
+
// config/webpack/custom.js
|
267
|
+
module.exports = {
|
268
|
+
resolve: {
|
269
|
+
alias: {
|
270
|
+
jquery: 'jquery/src/jquery',
|
271
|
+
vue: 'vue/dist/vue.js',
|
272
|
+
React: 'react',
|
273
|
+
ReactDOM: 'react-dom',
|
274
|
+
vue_resource: 'vue-resource/dist/vue-resource'
|
275
|
+
}
|
276
|
+
}
|
277
|
+
}
|
278
|
+
```
|
279
|
+
|
280
|
+
Then `require` this file in your `config/webpack/base.js`:
|
281
|
+
|
282
|
+
```js
|
283
|
+
// config/webpack/base.js
|
284
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
285
|
+
const customConfig = require('./custom')
|
286
|
+
|
287
|
+
module.exports = merge(webpackConfig, customConfig)
|
288
|
+
```
|
289
|
+
|
290
|
+
If you need access to configs within Webpacker's configuration, you can import them like so:
|
291
|
+
|
292
|
+
```js
|
293
|
+
// config/webpack/base.js
|
294
|
+
const { webpackConfig } = require('@rails/webpacker')
|
295
|
+
|
296
|
+
console.log(webpackConfig.output_path)
|
297
|
+
console.log(webpackConfig.source_path)
|
298
|
+
|
299
|
+
// Or to print out your whole webpack configuration
|
300
|
+
console.log(JSON.stringify(webpackConfig, undefined, 2))
|
301
|
+
```
|
302
|
+
|
303
|
+
### Babel configuration
|
304
|
+
|
305
|
+
By default, you will find the Webpacker preset in your `package.json`.
|
306
|
+
|
307
|
+
```json
|
308
|
+
"babel": {
|
309
|
+
"presets": [
|
310
|
+
"./node_modules/@rails/webpacker/package/babel/preset.js"
|
311
|
+
]
|
312
|
+
},
|
313
|
+
```
|
314
|
+
|
315
|
+
Optionally, you can change your Babel configuration by removing these lines in your `package.json` and add [a Babel configuration file](https://babeljs.io/docs/en/config-files) in your project.
|
316
|
+
|
317
|
+
|
318
|
+
### Integrations
|
319
|
+
|
320
|
+
Webpacker out of the box supports JS and static assets (fonts, images etc.) compilation. To enable support for CoffeeScript or TypeScript install relevant packages:
|
321
|
+
|
322
|
+
#### React
|
323
|
+
|
324
|
+
```bash
|
325
|
+
yarn add react react-dom @babel/preset-react
|
326
|
+
```
|
327
|
+
|
328
|
+
...if you are using typescript, update your `tsconfig.json`
|
329
|
+
|
330
|
+
```json
|
331
|
+
{
|
332
|
+
"compilerOptions": {
|
333
|
+
"declaration": false,
|
334
|
+
"emitDecoratorMetadata": true,
|
335
|
+
"experimentalDecorators": true,
|
336
|
+
"lib": ["es6", "dom"],
|
337
|
+
"module": "es6",
|
338
|
+
"moduleResolution": "node",
|
339
|
+
"sourceMap": true,
|
340
|
+
"target": "es5",
|
341
|
+
"jsx": "react",
|
342
|
+
"noEmit": true
|
343
|
+
},
|
344
|
+
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
345
|
+
"compileOnSave": false
|
346
|
+
}
|
347
|
+
```
|
348
|
+
|
349
|
+
#### CoffeeScript
|
350
|
+
|
351
|
+
```bash
|
352
|
+
yarn add coffeescript coffee-loader
|
353
|
+
```
|
354
|
+
|
355
|
+
#### TypeScript
|
356
|
+
|
357
|
+
```bash
|
358
|
+
yarn add typescript @babel/preset-typescript
|
359
|
+
```
|
360
|
+
|
361
|
+
Babel won’t perform any type-checking on TypeScript code. To optionally use type-checking run:
|
362
|
+
|
363
|
+
```bash
|
364
|
+
yarn add fork-ts-checker-webpack-plugin
|
365
|
+
```
|
366
|
+
|
367
|
+
Add tsconfig.json
|
368
|
+
|
369
|
+
```json
|
370
|
+
{
|
371
|
+
"compilerOptions": {
|
372
|
+
"declaration": false,
|
373
|
+
"emitDecoratorMetadata": true,
|
374
|
+
"experimentalDecorators": true,
|
375
|
+
"lib": ["es6", "dom"],
|
376
|
+
"module": "es6",
|
377
|
+
"moduleResolution": "node",
|
378
|
+
"baseUrl": ".",
|
379
|
+
"paths": {
|
380
|
+
"*": ["node_modules/*", "app/packs/*"]
|
381
|
+
},
|
382
|
+
"sourceMap": true,
|
383
|
+
"target": "es5",
|
384
|
+
"noEmit": true
|
385
|
+
},
|
386
|
+
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
387
|
+
"compileOnSave": false
|
388
|
+
}
|
389
|
+
```
|
390
|
+
|
391
|
+
Then modify the webpack config to use it as a plugin:
|
392
|
+
|
393
|
+
```js
|
394
|
+
// config/webpack/base.js
|
395
|
+
const { webpackConfig, merge } = require("@rails/webpacker");
|
396
|
+
const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
397
|
+
|
398
|
+
module.exports = merge(webpackConfig, {
|
399
|
+
plugins: [new ForkTSCheckerWebpackPlugin()],
|
400
|
+
});
|
401
|
+
```
|
402
|
+
|
403
|
+
#### CSS
|
404
|
+
|
405
|
+
To enable CSS support in your application, add following packages:
|
406
|
+
|
407
|
+
```bash
|
408
|
+
yarn add css-loader style-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
409
|
+
```
|
410
|
+
|
411
|
+
Optionally, add the `CSS` extension to webpack config for easy resolution.
|
412
|
+
|
413
|
+
```js
|
414
|
+
// config/webpack/base.js
|
415
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
416
|
+
const customConfig = {
|
417
|
+
resolve: {
|
418
|
+
extensions: ['.css']
|
419
|
+
}
|
420
|
+
}
|
421
|
+
|
422
|
+
module.exports = merge(webpackConfig, customConfig)
|
423
|
+
```
|
424
|
+
|
425
|
+
To enable `PostCSS`, `Sass` or `Less` support, add `CSS` support first and
|
426
|
+
then add the relevant pre-processors:
|
427
|
+
|
428
|
+
#### Postcss
|
429
|
+
|
430
|
+
```bash
|
431
|
+
yarn add postcss postcss-loader
|
432
|
+
```
|
433
|
+
|
434
|
+
Optionally add these two plugins if they are required in your `postcss.config.js`:
|
435
|
+
```bash
|
436
|
+
yarn add postcss-preset-env postcss-flexbugs-fixes
|
437
|
+
```
|
438
|
+
|
439
|
+
#### Sass
|
440
|
+
|
441
|
+
```bash
|
442
|
+
yarn add sass sass-loader
|
443
|
+
```
|
444
|
+
|
445
|
+
#### Less
|
446
|
+
|
447
|
+
```bash
|
448
|
+
yarn add less less-loader
|
449
|
+
```
|
450
|
+
|
451
|
+
#### Stylus
|
452
|
+
|
453
|
+
```bash
|
454
|
+
yarn add stylus stylus-loader
|
455
|
+
```
|
456
|
+
|
457
|
+
#### Other frameworks
|
458
|
+
|
459
|
+
Please follow webpack integration guide for relevant framework or library,
|
460
|
+
|
461
|
+
1. [Svelte](https://github.com/sveltejs/svelte-loader#install)
|
462
|
+
2. [Angular](https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack)
|
463
|
+
3. [Vue](https://vue-loader.vuejs.org/guide/)
|
464
|
+
|
465
|
+
For example to add Vue support:
|
466
|
+
```js
|
467
|
+
// config/webpack/rules/vue.js
|
468
|
+
const { VueLoaderPlugin } = require('vue-loader')
|
469
|
+
|
470
|
+
module.exports = {
|
471
|
+
module: {
|
472
|
+
rules: [
|
473
|
+
{
|
474
|
+
test: /\.vue$/,
|
475
|
+
loader: 'vue-loader'
|
476
|
+
}
|
477
|
+
]
|
478
|
+
},
|
479
|
+
plugins: [new VueLoaderPlugin()],
|
480
|
+
resolve: {
|
481
|
+
extensions: ['.vue']
|
482
|
+
}
|
483
|
+
}
|
484
|
+
```
|
485
|
+
|
486
|
+
```js
|
487
|
+
// config/webpack/base.js
|
488
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
489
|
+
const vueConfig = require('./rules/vue')
|
490
|
+
|
491
|
+
module.exports = merge(vueConfig, webpackConfig)
|
492
|
+
```
|
493
|
+
|
248
494
|
|
249
495
|
### Custom Rails environments
|
250
496
|
|
@@ -266,8 +512,7 @@ staging:
|
|
266
512
|
public_output_path: packs-staging
|
267
513
|
```
|
268
514
|
|
269
|
-
|
270
|
-
This means you don't need to create additional environment files inside `config/webpacker/*` and instead use webpacker.yml to load different configurations using `RAILS_ENV`.
|
515
|
+
Otherwise Webpacker will use production environment as a fallback environment for loading configurations. Please note, `NODE_ENV` can either be set to `production`, `development` or `test`. This means you don't need to create additional environment files inside `config/webpacker/*` and instead use webpacker.yml to load different configurations using `RAILS_ENV`.
|
271
516
|
|
272
517
|
For example, the below command will compile assets in production mode but will use staging configurations from `config/webpacker.yml` if available or use fallback production environment configuration:
|
273
518
|
|
@@ -275,22 +520,20 @@ For example, the below command will compile assets in production mode but will u
|
|
275
520
|
RAILS_ENV=staging bundle exec rails assets:precompile
|
276
521
|
```
|
277
522
|
|
278
|
-
And, this will compile in development mode and load configuration for cucumber environment
|
279
|
-
if defined in webpacker.yml or fallback to production configuration
|
523
|
+
And, this will compile in development mode and load configuration for cucumber environment if defined in webpacker.yml or fallback to production configuration
|
280
524
|
|
281
525
|
```bash
|
282
526
|
RAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile
|
283
527
|
```
|
284
528
|
|
285
|
-
Please note, binstubs compiles in development mode however rake tasks
|
286
|
-
compiles in production mode.
|
529
|
+
Please note, binstubs compiles in development mode however rake tasks compiles in production mode.
|
287
530
|
|
288
531
|
```bash
|
289
|
-
# Compiles in development mode unless NODE_ENV is specified
|
532
|
+
# Compiles in development mode unless NODE_ENV is specified, per the binstub source
|
290
533
|
./bin/webpack
|
291
534
|
./bin/webpack-dev-server
|
292
535
|
|
293
|
-
#
|
536
|
+
# Compiles in production mode by default unless NODE_ENV is specified, per `lib/tasks/webpacker/compile.rake`
|
294
537
|
bundle exec rails assets:precompile
|
295
538
|
bundle exec rails webpacker:compile
|
296
539
|
```
|
@@ -300,53 +543,37 @@ bundle exec rails webpacker:compile
|
|
300
543
|
You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
|
301
544
|
|
302
545
|
```bash
|
546
|
+
# check your Gemfile for version restrictions
|
303
547
|
bundle update webpacker
|
304
|
-
|
548
|
+
|
549
|
+
# overwrite your changes to the default install files and revert any unwanted changes from the install
|
550
|
+
rails webpacker:install
|
551
|
+
|
552
|
+
# yarn 1 instructions
|
305
553
|
yarn upgrade @rails/webpacker --latest
|
306
554
|
yarn upgrade webpack-dev-server --latest
|
307
555
|
|
556
|
+
# yarn 2 instructions
|
557
|
+
yarn up @rails/webpacker@latest
|
558
|
+
yarn up webpack-dev-server@latest
|
559
|
+
|
308
560
|
# Or to install the latest release (including pre-releases)
|
309
561
|
yarn add @rails/webpacker@next
|
310
562
|
```
|
311
563
|
|
312
|
-
|
313
|
-
|
314
|
-
Webpacker ships with basic out-of-the-box integration. You can see a list of available commands/tasks by running `bundle exec rails webpacker`.
|
315
|
-
|
316
|
-
Included install integrations:
|
317
|
-
|
318
|
-
- [React](./docs/integrations.md#React)
|
319
|
-
- [Angular with TypeScript](./docs/integrations.md#Angular-with-TypeScript)
|
320
|
-
- [Vue](./docs/integrations.md#Vue)
|
321
|
-
- [Elm](./docs/integrations.md#Elm)
|
322
|
-
- [Svelte](./docs/integrations.md#Svelte)
|
323
|
-
- [Stimulus](./docs/integrations.md#Stimulus)
|
324
|
-
- [CoffeeScript](./docs/integrations.md#CoffeeScript)
|
325
|
-
- [Typescript](./docs/typescript.md)
|
326
|
-
- [Erb](./docs/integrations.md#Erb)
|
327
|
-
|
328
|
-
See [Integrations](./docs/integrations.md) for further details.
|
564
|
+
Also, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.
|
329
565
|
|
330
566
|
## Paths
|
331
567
|
|
332
|
-
By default, Webpacker ships with simple conventions for where the JavaScript
|
333
|
-
app files and compiled webpack bundles will go in your Rails app.
|
334
|
-
All these options are configurable from `config/webpacker.yml` file.
|
568
|
+
By default, Webpacker ships with simple conventions for where the JavaScript app files and compiled webpack bundles will go in your Rails app. All these options are configurable from `config/webpacker.yml` file.
|
335
569
|
|
336
|
-
The configuration for what webpack is supposed to compile by default rests
|
337
|
-
on the convention that every file in `app/javascript/packs/*`**(default)**
|
338
|
-
or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
|
339
|
-
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
|
340
|
-
an entry file. As a rule of thumb, put all files you want to link in your views inside
|
341
|
-
"packs" directory and keep everything else under `app/javascript`.
|
570
|
+
The configuration for what webpack is supposed to compile by default rests on the convention that every file in `app/packs/entrypoints/*`**(default)** or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration 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 an entry file. As a rule of thumb, put all files you want to link in your views inside "packs" directory and keep everything else under `app/packs`.
|
342
571
|
|
343
|
-
Suppose you want to change the source directory from `app/
|
344
|
-
to `frontend` and output to `assets/packs`. This is how you would do it:
|
572
|
+
Suppose you want to change the source directory from `app/packs` to `frontend` and output to `assets/packs`. This is how you would do it:
|
345
573
|
|
346
574
|
```yml
|
347
575
|
# config/webpacker.yml
|
348
|
-
source_path: frontend
|
349
|
-
source_entry_path: packs
|
576
|
+
source_path: frontend # packs are in frontend/packs
|
350
577
|
public_output_path: assets/packs # outputs to => public/assets/packs
|
351
578
|
```
|
352
579
|
|
@@ -362,16 +589,13 @@ development:
|
|
362
589
|
|
363
590
|
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.
|
364
591
|
|
365
|
-
###
|
592
|
+
### Additional paths
|
366
593
|
|
367
|
-
If you are adding Webpacker to an existing app that has most of the assets inside
|
368
|
-
|
369
|
-
with webpack modules, you can use the `additional_paths`
|
370
|
-
option available in `config/webpacker.yml`. This lets you
|
371
|
-
add additional paths that webpack should lookup when resolving modules:
|
594
|
+
If you are adding Webpacker to an existing app that has most of the assets inside `app/assets` or inside an engine, and you want to share that with webpack modules, you can use the `additional_paths` option available in `config/webpacker.yml`. This lets you
|
595
|
+
add additional paths that webpack should look up when resolving modules:
|
372
596
|
|
373
597
|
```yml
|
374
|
-
additional_paths: ['app/assets']
|
598
|
+
additional_paths: ['app/assets', 'vendor/assets']
|
375
599
|
```
|
376
600
|
|
377
601
|
You can then import these items inside your modules like so:
|
@@ -382,9 +606,10 @@ import 'stylesheets/main'
|
|
382
606
|
import 'images/rails.png'
|
383
607
|
```
|
384
608
|
|
385
|
-
**Note:** Please be careful when adding paths here otherwise it
|
386
|
-
|
387
|
-
|
609
|
+
**Note:** Please be careful when adding paths here otherwise it will make the compilation slow, consider adding specific paths instead of whole parent directory if you just need to reference one or two modules
|
610
|
+
|
611
|
+
**Also note:** While importing assets living outside your `source_path` defined in webpacker.yml (like, for instance, assets under `app/assets`) from within your packs using _relative_ paths like `import '../../assets/javascripts/file.js'` will work in development, Webpacker won't recompile the bundle in production unless a file that lives in one of it's watched paths has changed (check out `Webpacker::Compiler#watched_files_digest`). That's why you'd need to add `app/assets` to the additional_paths as stated above and use `import 'javascripts/file.js'` instead.
|
612
|
+
|
388
613
|
|
389
614
|
## Deployment
|
390
615
|
|
@@ -392,25 +617,13 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
392
617
|
|
393
618
|
When compiling assets for production on a remote server, such as a continuous integration environment, it's recommended to use `yarn install --frozen-lockfile` to install NPM packages on the remote host to ensure that the installed packages match the `yarn.lock` file.
|
394
619
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
- [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
|
403
|
-
- [Props](./docs/props.md)
|
404
|
-
- [Typescript](./docs/typescript.md)
|
405
|
-
- [Yarn](./docs/yarn.md)
|
406
|
-
- [Misc](./docs/misc.md)
|
407
|
-
- [Deployment](./docs/deployment.md)
|
408
|
-
- [Docker](./docs/docker.md)
|
409
|
-
- [Using in Rails engines](./docs/engines.md)
|
410
|
-
- [Webpacker on Cloud9](./docs/cloud9.md)
|
411
|
-
- [Testing](./docs/testing.md)
|
412
|
-
- [Troubleshooting](./docs/troubleshooting.md)
|
413
|
-
- [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
|
620
|
+
If you are using a CDN setup, webpacker will use the configured [asset host](https://guides.rubyonrails.org/configuring.html#rails-general-configuration) value to prefix URLs for images or font icons which are included inside JS code or CSS. It is possible to override this value during asset compilation by setting the `WEBPACKER_ASSET_HOST` environment variable.
|
621
|
+
|
622
|
+
|
623
|
+
## Troubleshooting
|
624
|
+
|
625
|
+
See the doc page for [Troubleshooting](./docs/troubleshooting.md).
|
626
|
+
|
414
627
|
|
415
628
|
## Contributing
|
416
629
|
|
@@ -418,6 +631,7 @@ When compiling assets for production on a remote server, such as a continuous in
|
|
418
631
|
|
419
632
|
We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
|
420
633
|
|
634
|
+
|
421
635
|
## License
|
422
636
|
|
423
637
|
Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
|