webpacker 4.2.2 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +8 -8
- data/.github/workflows/jest.yml +38 -0
- data/.github/workflows/js-lint.yml +39 -0
- data/.github/workflows/rubocop.yml +39 -0
- data/.github/workflows/ruby.yml +70 -0
- data/.node-version +1 -1
- data/.travis.yml +7 -20
- data/CHANGELOG.md +40 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +81 -78
- data/README.md +59 -295
- data/docs/css.md +61 -7
- data/docs/deployment.md +2 -2
- data/docs/docker.md +17 -17
- data/docs/engines.md +13 -0
- data/docs/env.md +0 -2
- data/docs/integrations.md +220 -0
- data/docs/target.md +22 -0
- data/docs/testing.md +2 -3
- data/docs/troubleshooting.md +3 -1
- data/docs/typescript.md +92 -28
- data/docs/webpack-dev-server.md +1 -1
- data/lib/install/config/babel.config.js +1 -3
- data/lib/install/config/webpacker.yml +1 -5
- data/lib/install/examples/react/tsconfig.json +2 -1
- data/lib/install/examples/typescript/tsconfig.json +2 -1
- data/lib/install/loaders/svelte.js +2 -2
- data/lib/install/template.rb +1 -1
- data/lib/install/typescript.rb +5 -12
- data/lib/tasks/webpacker/check_node.rake +15 -8
- data/lib/tasks/webpacker/check_yarn.rake +17 -10
- data/lib/tasks/webpacker/clean.rake +12 -6
- data/lib/tasks/webpacker/clobber.rake +8 -4
- data/lib/tasks/webpacker/yarn_install.rake +5 -16
- data/lib/webpacker/commands.rb +33 -9
- data/lib/webpacker/compiler.rb +9 -5
- data/lib/webpacker/configuration.rb +13 -9
- data/lib/webpacker/dev_server_proxy.rb +3 -1
- data/lib/webpacker/dev_server_runner.rb +6 -6
- data/lib/webpacker/helper.rb +37 -18
- data/lib/webpacker/manifest.rb +4 -4
- data/lib/webpacker/railtie.rb +2 -45
- data/lib/webpacker/runner.rb +1 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +2 -2
- data/package.json +39 -39
- data/package/__tests__/config.js +12 -1
- data/package/__tests__/dev_server.js +2 -0
- data/package/__tests__/development.js +14 -1
- data/package/config.js +4 -1
- data/package/configPath.js +3 -0
- data/package/dev_server.js +1 -1
- data/package/env.js +1 -2
- data/package/environments/__tests__/base.js +30 -3
- data/package/environments/base.js +17 -7
- data/package/environments/development.js +39 -37
- data/package/environments/production.js +1 -3
- data/package/rules/babel.js +12 -5
- data/package/rules/file.js +1 -0
- data/package/rules/node_modules.js +1 -3
- data/package/rules/sass.js +7 -1
- data/package/utils/helpers.js +1 -1
- data/test/compiler_test.rb +8 -3
- data/test/configuration_test.rb +8 -7
- data/test/dev_server_runner_test.rb +1 -1
- data/test/helper_test.rb +3 -0
- data/test/manifest_test.rb +37 -6
- data/test/rake_tasks_test.rb +11 -0
- data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
- data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
- data/test/test_app/config/application.rb +0 -1
- data/test/test_app/config/webpacker.yml +7 -1
- data/test/test_app/public/packs/manifest.json +1 -0
- data/test/webpack_runner_test.rb +1 -1
- data/webpacker.gemspec +4 -3
- data/yarn.lock +3413 -2843
- metadata +34 -13
- data/gemfiles/Gemfile-rails.4.2.x +0 -9
- data/gemfiles/Gemfile-rails.5.0.x +0 -9
- data/gemfiles/Gemfile-rails.5.1.x +0 -9
- data/lib/install/loaders/typescript.js +0 -11
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Webpacker
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/rails/webpacker.svg?branch=master)](https://travis-ci.org/rails/webpacker)
|
4
|
-
[![node.js](https://img.shields.io/badge/node-%3E%3D%
|
5
|
-
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://
|
4
|
+
[![node.js](https://img.shields.io/badge/node-%3E%3D%2010.17.0-brightgreen.svg)](https://www.npmjs.com/package/@rails/webpacker)
|
5
|
+
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://rubygems.org/gems/webpacker)
|
6
6
|
|
7
7
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
8
8
|
[webpack 4.x.x+](https://webpack.js.org/)
|
@@ -13,10 +13,11 @@ even JavaScript Sprinkles (that all continues to live in app/assets).
|
|
13
13
|
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
|
14
14
|
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
|
15
15
|
|
16
|
-
**NOTE:** The master branch now hosts the code for
|
16
|
+
**NOTE:** The master branch now hosts the code for v5.x.x. Please refer to [4-x-stable](https://github.com/rails/webpacker/tree/4-x-stable) branch for 4.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 -->
|
20
|
+
|
20
21
|
## Table of Contents
|
21
22
|
|
22
23
|
- [Prerequisites](#prerequisites)
|
@@ -27,16 +28,16 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
27
28
|
- [Webpack Configuration](#webpack-configuration)
|
28
29
|
- [Custom Rails environments](#custom-rails-environments)
|
29
30
|
- [Upgrading](#upgrading)
|
30
|
-
- [Yarn Integrity](#yarn-integrity)
|
31
31
|
- [Integrations](#integrations)
|
32
|
-
- [React](#react)
|
33
|
-
- [Angular with TypeScript](#angular-with-typescript)
|
34
|
-
- [Vue](#vue)
|
35
|
-
- [Elm](#elm)
|
36
|
-
- [Stimulus](#stimulus)
|
37
|
-
- [Svelte](#svelte)
|
38
|
-
- [
|
39
|
-
- [
|
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)
|
40
41
|
- [Paths](#paths)
|
41
42
|
- [Resolved](#resolved)
|
42
43
|
- [Watched](#watched)
|
@@ -47,29 +48,26 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
47
48
|
|
48
49
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
49
50
|
|
50
|
-
|
51
51
|
## Prerequisites
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
- Ruby 2.4+
|
54
|
+
- Rails 5.2+
|
55
|
+
- Node.js 10.17.0+
|
56
|
+
- Yarn 1.x+
|
58
57
|
|
59
58
|
## Features
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
60
|
+
- [webpack 4.x.x](https://webpack.js.org/)
|
61
|
+
- ES6 with [babel](https://babeljs.io/)
|
62
|
+
- Automatic code splitting using multiple entry points
|
63
|
+
- Stylesheets - Sass and CSS
|
64
|
+
- Images and fonts
|
65
|
+
- PostCSS - Auto-Prefixer
|
66
|
+
- Asset compression, source-maps, and minification
|
67
|
+
- CDN support
|
68
|
+
- React, Angular, Elm and Vue support out-of-the-box
|
69
|
+
- Rails view helpers
|
70
|
+
- Extensible and configurable
|
73
71
|
|
74
72
|
## Installation
|
75
73
|
|
@@ -85,7 +83,7 @@ Or add it to your `Gemfile`:
|
|
85
83
|
|
86
84
|
```ruby
|
87
85
|
# Gemfile
|
88
|
-
gem 'webpacker', '~>
|
86
|
+
gem 'webpacker', '~> 5.x'
|
89
87
|
|
90
88
|
# OR if you prefer to use master
|
91
89
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
@@ -109,6 +107,12 @@ Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/web
|
|
109
107
|
yarn upgrade
|
110
108
|
```
|
111
109
|
|
110
|
+
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:
|
111
|
+
|
112
|
+
```bash
|
113
|
+
yarn install
|
114
|
+
```
|
115
|
+
|
112
116
|
### Usage
|
113
117
|
|
114
118
|
Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
|
@@ -118,8 +122,11 @@ app/javascript:
|
|
118
122
|
├── packs:
|
119
123
|
│ # only webpack entry files here
|
120
124
|
│ └── application.js
|
121
|
-
└── src:
|
122
125
|
│ └── application.css
|
126
|
+
└── src:
|
127
|
+
│ └── my_component.js
|
128
|
+
└── stylesheets:
|
129
|
+
│ └── my_styles.css
|
123
130
|
└── images:
|
124
131
|
└── logo.svg
|
125
132
|
```
|
@@ -127,8 +134,8 @@ app/javascript:
|
|
127
134
|
In `/packs/application.js`, include this at the top of the file:
|
128
135
|
|
129
136
|
```js
|
130
|
-
import
|
131
|
-
import
|
137
|
+
import 'core-js/stable'
|
138
|
+
import 'regenerator-runtime/runtime'
|
132
139
|
```
|
133
140
|
|
134
141
|
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
|
@@ -175,7 +182,6 @@ helper otherwise you will get duplicated chunks on the page.
|
|
175
182
|
**Note:** In order for your styles or static assets files to be available in your view,
|
176
183
|
you would need to link them in your "pack" or entry file.
|
177
184
|
|
178
|
-
|
179
185
|
### Development
|
180
186
|
|
181
187
|
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
|
@@ -240,7 +246,6 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
240
246
|
|
241
247
|
See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
|
242
248
|
|
243
|
-
|
244
249
|
### Custom Rails environments
|
245
250
|
|
246
251
|
Out of the box Webpacker ships with - development, test and production environments in `config/webpacker.yml` however, in most production apps extra environments are needed as part of deployment workflow. Webpacker supports this out of the box from version 3.4.0+ onwards.
|
@@ -290,7 +295,6 @@ bundle exec rails assets:precompile
|
|
290
295
|
bundle exec rails webpacker:compile
|
291
296
|
```
|
292
297
|
|
293
|
-
|
294
298
|
### Upgrading
|
295
299
|
|
296
300
|
You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
|
@@ -305,247 +309,23 @@ yarn upgrade webpack-dev-server --latest
|
|
305
309
|
yarn add @rails/webpacker@next
|
306
310
|
```
|
307
311
|
|
308
|
-
### Yarn Integrity
|
309
|
-
|
310
|
-
By default, in development, webpacker runs a yarn integrity check to ensure that all local JavaScript 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. You will be asked to upgrade your local JavaScript packages by running `yarn install`.
|
311
|
-
|
312
|
-
To turn off this option, you will need to change the default setting in `config/webpacker.yml`:
|
313
|
-
|
314
|
-
```yaml
|
315
|
-
# config/webpacker.yml
|
316
|
-
development:
|
317
|
-
...
|
318
|
-
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
|
319
|
-
check_yarn_integrity: false
|
320
|
-
```
|
321
|
-
|
322
|
-
You may also turn on this feature by adding the config option for any Rails environment in `config/webpacker.yml`:
|
323
|
-
|
324
|
-
```yaml
|
325
|
-
check_yarn_integrity: true
|
326
|
-
```
|
327
|
-
|
328
312
|
## Integrations
|
329
313
|
|
330
|
-
Webpacker ships with basic out-of-the-box integration
|
331
|
-
You can see a list of available commands/tasks by running `bundle exec rails webpacker`:
|
332
|
-
|
333
|
-
### React
|
334
|
-
|
335
|
-
To use Webpacker with [React](https://facebook.github.io/react/), create a
|
336
|
-
new Rails 5.1+ app using `--webpack=react` option:
|
337
|
-
|
338
|
-
```bash
|
339
|
-
# Rails 5.1+
|
340
|
-
rails new myapp --webpack=react
|
341
|
-
```
|
342
|
-
|
343
|
-
(or run `bundle exec rails webpacker:install:react` in an existing Rails app already
|
344
|
-
setup with Webpacker).
|
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`.
|
345
315
|
|
346
|
-
|
347
|
-
to the configuration files, and an example React component to your
|
348
|
-
project in `app/javascript/packs` so that you can experiment with React right away.
|
316
|
+
Included install integrations:
|
349
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)
|
350
327
|
|
351
|
-
|
352
|
-
|
353
|
-
To use Webpacker with [Angular](https://angular.io/), create a
|
354
|
-
new Rails 5.1+ app using `--webpack=angular` option:
|
355
|
-
|
356
|
-
```bash
|
357
|
-
# Rails 5.1+
|
358
|
-
rails new myapp --webpack=angular
|
359
|
-
```
|
360
|
-
|
361
|
-
(or run `bundle exec rails webpacker:install:angular` on a Rails app already
|
362
|
-
setup with Webpacker).
|
363
|
-
|
364
|
-
The installer will add the TypeScript and Angular core libraries using Yarn alongside
|
365
|
-
a few changes to the configuration files. An example component written in
|
366
|
-
TypeScript will also be added to your project in `app/javascript` so that
|
367
|
-
you can experiment with Angular right away.
|
368
|
-
|
369
|
-
By default, Angular uses a JIT compiler for development environment. This
|
370
|
-
compiler is not compatible with restrictive CSP (Content Security
|
371
|
-
Policy) environments like Rails 5.2+. You can use Angular AOT compiler
|
372
|
-
in development with the [@ngtools/webpack](https://www.npmjs.com/package/@ngtools/webpack#usage) plugin.
|
373
|
-
|
374
|
-
Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for your
|
375
|
-
development environment. This can be done in the `config/initializers/content_security_policy.rb`
|
376
|
-
with the following code:
|
377
|
-
|
378
|
-
```ruby
|
379
|
-
Rails.application.config.content_security_policy do |policy|
|
380
|
-
if Rails.env.development?
|
381
|
-
policy.script_src :self, :https, :unsafe_eval
|
382
|
-
else
|
383
|
-
policy.script_src :self, :https
|
384
|
-
end
|
385
|
-
end
|
386
|
-
```
|
387
|
-
|
388
|
-
|
389
|
-
### Vue
|
390
|
-
|
391
|
-
To use Webpacker with [Vue](https://vuejs.org/), create a
|
392
|
-
new Rails 5.1+ app using `--webpack=vue` option:
|
393
|
-
|
394
|
-
```bash
|
395
|
-
# Rails 5.1+
|
396
|
-
rails new myapp --webpack=vue
|
397
|
-
```
|
398
|
-
(or run `bundle exec rails webpacker:install:vue` on a Rails app already setup with Webpacker).
|
399
|
-
|
400
|
-
The installer will add Vue and its required libraries using Yarn alongside
|
401
|
-
automatically applying changes needed to the configuration files. An example component will
|
402
|
-
be added to your project in `app/javascript` so that you can experiment with Vue right away.
|
403
|
-
|
404
|
-
If you're using Rails 5.2+ you'll need to enable `unsafe-eval` rule for your development environment.
|
405
|
-
This can be done in the `config/initializers/content_security_policy.rb` with the following
|
406
|
-
configuration:
|
407
|
-
|
408
|
-
```ruby
|
409
|
-
Rails.application.config.content_security_policy do |policy|
|
410
|
-
if Rails.env.development?
|
411
|
-
policy.script_src :self, :https, :unsafe_eval
|
412
|
-
else
|
413
|
-
policy.script_src :self, :https
|
414
|
-
end
|
415
|
-
end
|
416
|
-
```
|
417
|
-
You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
|
418
|
-
|
419
|
-
#### Lazy loading integration
|
420
|
-
|
421
|
-
See [docs/es6](docs/es6.md) to know more about Webpack and Webpacker configuration.
|
422
|
-
|
423
|
-
For instance, you can lazy load Vue JS components:
|
424
|
-
|
425
|
-
Before:
|
426
|
-
```js
|
427
|
-
import Vue from 'vue'
|
428
|
-
import { VCard } from 'vuetify/lib'
|
429
|
-
|
430
|
-
Vue.component('VCard', VCard)
|
431
|
-
```
|
432
|
-
|
433
|
-
After:
|
434
|
-
```js
|
435
|
-
import Vue from 'vue'
|
436
|
-
|
437
|
-
// With destructuring assignment
|
438
|
-
Vue.component('VCard', import('vuetify/lib').then(({ VCard }) => VCard)
|
439
|
-
|
440
|
-
// Or without destructuring assignment
|
441
|
-
Vue.component('OtherComponent', () => import('./OtherComponent'))
|
442
|
-
```
|
443
|
-
|
444
|
-
You can use it in a Single File Component as well:
|
445
|
-
|
446
|
-
```html
|
447
|
-
<template>
|
448
|
-
...
|
449
|
-
</template>
|
450
|
-
|
451
|
-
<script>
|
452
|
-
export default {
|
453
|
-
components: {
|
454
|
-
OtherComponent: () => import('./OtherComponent')
|
455
|
-
}
|
456
|
-
}
|
457
|
-
</script>
|
458
|
-
```
|
459
|
-
|
460
|
-
By wrapping the import function into an arrow function, Vue will execute it only when it gets requested, loading the module in that moment.
|
461
|
-
|
462
|
-
##### Automatic registration
|
463
|
-
|
464
|
-
```js
|
465
|
-
/**
|
466
|
-
* The following block of code may be used to automatically register your
|
467
|
-
* Vue components. It will recursively scan this directory for the Vue
|
468
|
-
* components and automatically register them with their "basename".
|
469
|
-
*
|
470
|
-
* Eg. ./components/OtherComponent.vue -> <other-component></other-component>
|
471
|
-
* Eg. ./UI/ButtonComponent.vue -> <button-component></button-component>
|
472
|
-
*/
|
473
|
-
|
474
|
-
const files = require.context('./', true, /\.vue$/i)
|
475
|
-
files.keys().map(key => {
|
476
|
-
const component = key.split('/').pop().split('.')[0]
|
477
|
-
|
478
|
-
// With Lazy Loading
|
479
|
-
Vue.component(component, () => import(`${key}`))
|
480
|
-
|
481
|
-
// Or without Lazy Loading
|
482
|
-
Vue.component(component, files(key).default)
|
483
|
-
})
|
484
|
-
```
|
485
|
-
|
486
|
-
### Elm
|
487
|
-
|
488
|
-
To use Webpacker with [Elm](http://elm-lang.org), create a
|
489
|
-
new Rails 5.1+ app using `--webpack=elm` option:
|
490
|
-
|
491
|
-
```
|
492
|
-
# Rails 5.1+
|
493
|
-
rails new myapp --webpack=elm
|
494
|
-
```
|
495
|
-
|
496
|
-
(or run `bundle exec rails webpacker:install:elm` on a Rails app already setup with Webpacker).
|
497
|
-
|
498
|
-
The Elm library and its core packages will be added via Yarn and Elm.
|
499
|
-
An example `Main.elm` app will also be added to your project in `app/javascript`
|
500
|
-
so that you can experiment with Elm right away.
|
501
|
-
|
502
|
-
### Svelte
|
503
|
-
|
504
|
-
To use Webpacker with [Svelte](https://svelte.dev), create a
|
505
|
-
new Rails 5.1+ app using `--webpack=svelte` option:
|
506
|
-
|
507
|
-
```
|
508
|
-
# Rails 5.1+
|
509
|
-
rails new myapp --webpack=svelte
|
510
|
-
```
|
511
|
-
|
512
|
-
(or run `bundle exec rails webpacker:install:svelte` on a Rails app already setup with Webpacker).
|
513
|
-
|
514
|
-
Please play with the [Svelte Tutorial](https://svelte.dev/tutorial/basics) or learn more about its API at https://svelte.dev/docs
|
515
|
-
|
516
|
-
### Stimulus
|
517
|
-
|
518
|
-
To use Webpacker with [Stimulus](http://stimulusjs.org), create a
|
519
|
-
new Rails 5.1+ app using `--webpack=stimulus` option:
|
520
|
-
|
521
|
-
```
|
522
|
-
# Rails 5.1+
|
523
|
-
rails new myapp --webpack=stimulus
|
524
|
-
```
|
525
|
-
|
526
|
-
(or run `bundle exec rails webpacker:install:stimulus` on a Rails app already setup with Webpacker).
|
527
|
-
|
528
|
-
Please read [The Stimulus Handbook](https://stimulusjs.org/handbook/introduction) or learn more about its source code at https://github.com/stimulusjs/stimulus
|
529
|
-
|
530
|
-
### CoffeeScript
|
531
|
-
|
532
|
-
To add [CoffeeScript](http://coffeescript.org/) support,
|
533
|
-
run `bundle exec rails webpacker:install:coffee` on a Rails app already
|
534
|
-
setup with Webpacker.
|
535
|
-
|
536
|
-
An example `hello_coffee.coffee` file will also be added to your project
|
537
|
-
in `app/javascript/packs` so that you can experiment with CoffeeScript right away.
|
538
|
-
|
539
|
-
### Erb
|
540
|
-
|
541
|
-
To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates,
|
542
|
-
run `bundle exec rails webpacker:install:erb` on a Rails app already
|
543
|
-
setup with Webpacker.
|
544
|
-
|
545
|
-
An example `hello_erb.js.erb` file will also be added to your project
|
546
|
-
in `app/javascript/packs` so that you can experiment with Erb-flavoured
|
547
|
-
javascript right away.
|
548
|
-
|
328
|
+
See [Integrations](./docs/integrations.md) for further details.
|
549
329
|
|
550
330
|
## Paths
|
551
331
|
|
@@ -582,17 +362,16 @@ development:
|
|
582
362
|
|
583
363
|
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.
|
584
364
|
|
585
|
-
|
586
365
|
### Resolved
|
587
366
|
|
588
367
|
If you are adding Webpacker to an existing app that has most of the assets inside
|
589
368
|
`app/assets` or inside an engine, and you want to share that
|
590
|
-
with webpack modules, you can use the `
|
369
|
+
with webpack modules, you can use the `additional_paths`
|
591
370
|
option available in `config/webpacker.yml`. This lets you
|
592
371
|
add additional paths that webpack should lookup when resolving modules:
|
593
372
|
|
594
373
|
```yml
|
595
|
-
|
374
|
+
additional_paths: ['app/assets']
|
596
375
|
```
|
597
376
|
|
598
377
|
You can then import these items inside your modules like so:
|
@@ -607,24 +386,11 @@ import 'images/rails.png'
|
|
607
386
|
will make the compilation slow, consider adding specific paths instead of
|
608
387
|
whole parent directory if you just need to reference one or two modules
|
609
388
|
|
610
|
-
|
611
|
-
### Watched
|
612
|
-
|
613
|
-
By default, the lazy compilation is cached until a file is changed under your
|
614
|
-
tracked paths. You can configure which paths are tracked
|
615
|
-
by adding new paths to `watched_paths` array. This is much like Rails' `autoload_paths`:
|
616
|
-
|
617
|
-
```rb
|
618
|
-
# config/initializers/webpacker.rb
|
619
|
-
# or config/application.rb
|
620
|
-
Webpacker::Compiler.watched_paths << 'bower_components'
|
621
|
-
```
|
622
|
-
|
623
|
-
|
624
389
|
## Deployment
|
625
390
|
|
626
391
|
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`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/webpacker.yml` (if available).
|
627
392
|
|
393
|
+
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.
|
628
394
|
|
629
395
|
## Docs
|
630
396
|
|
@@ -633,9 +399,7 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
633
399
|
- [Webpack-dev-server](./docs/webpack-dev-server.md)
|
634
400
|
- [Environment Variables](./docs/env.md)
|
635
401
|
- [Folder Structure](./docs/folder-structure.md)
|
636
|
-
- [Assets](./docs/assets.md)
|
637
|
-
- [CSS, Sass and SCSS](./docs/css.md)
|
638
|
-
- [ES6](./docs/es6.md)
|
402
|
+
- [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
|
639
403
|
- [Props](./docs/props.md)
|
640
404
|
- [Typescript](./docs/typescript.md)
|
641
405
|
- [Yarn](./docs/yarn.md)
|
@@ -648,12 +412,12 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
648
412
|
- [Troubleshooting](./docs/troubleshooting.md)
|
649
413
|
- [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
|
650
414
|
|
651
|
-
|
652
415
|
## Contributing
|
416
|
+
|
653
417
|
[![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)
|
654
418
|
|
655
419
|
We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
|
656
420
|
|
657
|
-
|
658
421
|
## License
|
422
|
+
|
659
423
|
Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
|