webpacker 6.0.0.beta.6 → 6.0.0.pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/jest.yml +1 -1
- data/.github/workflows/js-lint.yml +1 -1
- data/.github/workflows/ruby.yml +6 -9
- data/CHANGELOG.md +4 -20
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +5 -7
- data/README.md +109 -306
- data/docs/assets.md +135 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +303 -0
- data/docs/deployment.md +148 -0
- data/docs/docker.md +68 -0
- data/docs/engines.md +213 -0
- data/docs/env.md +68 -0
- data/docs/es6.md +72 -0
- data/docs/folder-structure.md +66 -0
- data/docs/integrations.md +220 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +187 -0
- data/docs/react.md +183 -0
- data/docs/target.md +22 -0
- data/docs/testing.md +147 -0
- data/docs/troubleshooting.md +3 -5
- data/docs/typescript.md +190 -0
- data/docs/v4-upgrade.md +142 -0
- data/docs/webpack-dev-server.md +94 -0
- data/docs/webpack.md +315 -0
- data/docs/yarn.md +23 -0
- data/lib/install/config/webpacker.yml +2 -4
- data/lib/install/examples/vue3/app.vue +27 -0
- data/lib/install/examples/vue3/hello_vue.js +15 -0
- data/lib/install/javascript/packs/application.css +9 -0
- data/lib/install/{packs/entrypoints → javascript/packs}/application.js +2 -4
- data/lib/install/template.rb +3 -3
- data/lib/webpacker/commands.rb +1 -2
- data/lib/webpacker/compiler.rb +3 -9
- data/lib/webpacker/dev_server_runner.rb +0 -2
- data/lib/webpacker/helper.rb +43 -13
- data/lib/webpacker/manifest.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +0 -1
- data/package.json +1 -1
- data/package/__tests__/development.js +1 -2
- data/package/babel/preset-react.js +62 -0
- data/package/babel/preset.js +13 -24
- data/package/environments/__tests__/base.js +5 -5
- data/package/environments/base.js +19 -19
- data/package/environments/development.js +0 -1
- data/package/environments/production.js +30 -28
- data/package/index.js +2 -7
- data/package/rules/babel.js +1 -1
- data/package/rules/coffee.js +5 -5
- data/package/rules/erb.js +3 -5
- data/package/rules/file.js +3 -5
- data/package/rules/index.js +17 -9
- data/package/rules/less.js +10 -14
- data/package/rules/sass.js +9 -13
- data/package/rules/svg.js +23 -0
- data/package/utils/get_style_rule.js +31 -27
- data/package/utils/helpers.js +0 -25
- data/test/configuration_test.rb +2 -2
- data/test/dev_server_runner_test.rb +2 -10
- data/test/helper_test.rb +39 -33
- data/test/manifest_test.rb +0 -8
- data/test/mounted_app/test/dummy/config/webpacker.yml +2 -2
- data/test/test_app/app/{packs/entrypoints → javascript/packs}/application.js +1 -1
- data/test/test_app/app/{packs/entrypoints → javascript/packs}/multi_entry.css +0 -0
- data/test/test_app/app/{packs/entrypoints → javascript/packs}/multi_entry.js +0 -0
- data/test/test_app/config/webpacker.yml +2 -2
- data/test/test_app/public/packs/manifest.json +0 -7
- metadata +36 -17
- data/6_0_upgrade.md +0 -62
- data/config/README.md +0 -3
- data/config/webpacker.yml +0 -1
- data/package/__tests__/index.js +0 -9
- data/package/rules/raw.js +0 -5
- data/package/rules/stylus.js +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5808c11756423a2f910b9aa3675b5d85c94c5cae43a2db1c5c726588bb70cc7
|
4
|
+
data.tar.gz: f1b92f83b8d9f06a136c2df4116144b5a70bf74c7ab5c426fc90900f18f8de6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8a10749bc365d1be38d214ab5cedc921ba5dc437193d2f0bf6da18a0e17650a7b35887fd340356de6f5476e388279f58324345685bfe848e2bcb26dfccbaf7a
|
7
|
+
data.tar.gz: 4106137abde49ccda533e7441d0e751f1540a4e175b8f392f486a9eea152083114fabd357db03dd57b9a2a2fe5774563a4cc6f7cf04b78c027b052190bd34d04
|
data/.github/workflows/jest.yml
CHANGED
data/.github/workflows/ruby.yml
CHANGED
@@ -18,8 +18,7 @@ jobs:
|
|
18
18
|
2.4,
|
19
19
|
2.5,
|
20
20
|
2.6,
|
21
|
-
2.7
|
22
|
-
3.0
|
21
|
+
2.7
|
23
22
|
]
|
24
23
|
gemfile: [
|
25
24
|
"gemfiles/Gemfile-rails.5.2.x",
|
@@ -28,23 +27,21 @@ jobs:
|
|
28
27
|
exclude:
|
29
28
|
- ruby: "2.4"
|
30
29
|
gemfile: gemfiles/Gemfile-rails.6.0.x
|
31
|
-
- ruby: "3.0"
|
32
|
-
gemfile: gemfiles/Gemfile-rails.5.2.x
|
33
30
|
experimental: [false]
|
34
31
|
include:
|
35
|
-
- ruby:
|
32
|
+
- ruby: head
|
36
33
|
os: ubuntu-latest
|
37
|
-
gemfile: gemfiles/Gemfile-rails
|
34
|
+
gemfile: gemfiles/Gemfile-rails.6.0.x
|
38
35
|
experimental: true
|
39
|
-
- ruby:
|
36
|
+
- ruby: head
|
40
37
|
os: ubuntu-latest
|
41
38
|
gemfile: gemfiles/Gemfile-rails-edge
|
42
39
|
experimental: true
|
43
|
-
- ruby: 2.
|
40
|
+
- ruby: 2.6
|
44
41
|
os: ubuntu-latest
|
45
42
|
gemfile: gemfiles/Gemfile-rails-edge
|
46
43
|
experimental: true
|
47
|
-
- ruby:
|
44
|
+
- ruby: 2.7
|
48
45
|
os: ubuntu-latest
|
49
46
|
gemfile: gemfiles/Gemfile-rails-edge
|
50
47
|
experimental: true
|
data/CHANGELOG.md
CHANGED
@@ -2,33 +2,19 @@
|
|
2
2
|
|
3
3
|
**Please note that Webpacker 4.1.0 has an installer bug. Please use 4.2.0 or above**
|
4
4
|
|
5
|
-
## [[6.0.0]](https://github.com/rails/webpacker/compare/v5.1.1...
|
5
|
+
## [[6.0.0]](https://github.com/rails/webpacker/compare/v5.1.1...v6.0.0) - 2020-TBD
|
6
6
|
|
7
7
|
- `node_modules` will no longer be compiled by default. This primarily fixes [rails issue #35501](https://github.com/rails/rails/issues/35501) as well as [numerous other webpacker issues](https://github.com/rails/webpacker/issues/2131#issuecomment-581618497). The disabled loader can still be required explicitly via:
|
8
|
-
|
9
8
|
```js
|
10
9
|
const nodeModules = require('@rails/webpacker/rules/node_modules.js')
|
11
10
|
environment.loaders.append('nodeModules', nodeModules)
|
12
11
|
```
|
13
|
-
|
14
12
|
- If you have added `environment.loaders.delete('nodeModules')` to your `environment.js`, this must be removed or you will receive an error (`Item nodeModules not found`).
|
15
|
-
- The install task will now set the `extract_css` default to `true` in all environments and generate a separate `application.css` file for the default `application` pack, as supported by multiple files per entry introduced in 5.0.0.
|
13
|
+
- The install task will now set the `extract_css` default to `true` in all environments and generate a separate `application.css` file for the default `application` pack, as supported by multiple files per entry introduced in 5.0.0. [#2608](https://github.com/rails/webpacker/pull/2608)
|
16
14
|
- Webpacker's wrapper to the `splitChunks()` API will now default `runtimeChunk: 'single'` which will help prevent potential issues when using multiple entry points per page [#2708](https://github.com/rails/webpacker/pull/2708).
|
17
15
|
- Changes `@babel/preset-env` modules option to `'auto'` per recommendation in the Babel docs [#2709](https://github.com/rails/webpacker/pull/2709)
|
18
16
|
- Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
|
19
17
|
|
20
|
-
- Fixes dev server issues [#2898](https://github.com/rails/webpacker/pull/2898)
|
21
|
-
|
22
|
-
### Breaking changes
|
23
|
-
|
24
|
-
- Simple webpack config
|
25
|
-
- Removed integration installers
|
26
|
-
- Splitchunks enabled by default
|
27
|
-
- CSS extraction enabled by default
|
28
|
-
- Optional CSS support
|
29
|
-
|
30
|
-
Please see upgrade [guide](./6_0_upgrade.md)
|
31
|
-
|
32
18
|
## [[5.2.1]](https://github.com/rails/webpacker/compare/v5.2.0...5.2.1) - 2020-08-17
|
33
19
|
|
34
20
|
- Revert [#1311](https://github.com/rails/webpacker/pull/1311).
|
@@ -360,7 +346,7 @@ const { environment } = require('@rails/webpacker')
|
|
360
346
|
// Enable with default config
|
361
347
|
environment.splitChunks()
|
362
348
|
// Configure via a callback
|
363
|
-
environment.splitChunks(
|
349
|
+
environment.splitChunks(config =>
|
364
350
|
Object.assign({}, config, { optimization: { splitChunks: false } })
|
365
351
|
)
|
366
352
|
```
|
@@ -684,9 +670,7 @@ environment.resolvedModules.append('vendor', 'vendor')
|
|
684
670
|
```js
|
685
671
|
// Enable css modules with sass loader
|
686
672
|
const sassLoader = environment.loaders.get('sass')
|
687
|
-
const cssLoader = sassLoader.use.find(
|
688
|
-
(loader) => loader.loader === 'css-loader'
|
689
|
-
)
|
673
|
+
const cssLoader = sassLoader.use.find(loader => loader.loader === 'css-loader')
|
690
674
|
|
691
675
|
cssLoader.options = Object.assign({}, cssLoader.options, {
|
692
676
|
modules: true,
|
data/CONTRIBUTING.md
CHANGED
@@ -9,7 +9,7 @@ yarn
|
|
9
9
|
```
|
10
10
|
|
11
11
|
## Making sure your changes pass all tests
|
12
|
-
There are a number of automated checks which run on
|
12
|
+
There are a number of automated checks which run on Github Actions when a pull request is created.
|
13
13
|
You can run those checks on your own locally to make sure that your changes would not break the CI build.
|
14
14
|
|
15
15
|
### 1. Check the code for JavaScript style violations
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
webpacker (6.0.0.
|
4
|
+
webpacker (6.0.0.pre.1)
|
5
5
|
activesupport (>= 5.2)
|
6
6
|
rack-proxy (>= 0.6.1)
|
7
7
|
railties (>= 5.2)
|
@@ -85,16 +85,14 @@ GEM
|
|
85
85
|
method_source (1.0.0)
|
86
86
|
mimemagic (0.3.5)
|
87
87
|
mini_mime (1.0.2)
|
88
|
-
mini_portile2 (2.
|
89
|
-
minitest (5.14.
|
88
|
+
mini_portile2 (2.4.0)
|
89
|
+
minitest (5.14.1)
|
90
90
|
nio4r (2.5.2)
|
91
|
-
nokogiri (1.
|
92
|
-
mini_portile2 (~> 2.
|
93
|
-
racc (~> 1.4)
|
91
|
+
nokogiri (1.10.10)
|
92
|
+
mini_portile2 (~> 2.4.0)
|
94
93
|
parallel (1.19.2)
|
95
94
|
parser (2.7.2.0)
|
96
95
|
ast (~> 2.4.1)
|
97
|
-
racc (1.5.2)
|
98
96
|
rack (2.2.3)
|
99
97
|
rack-proxy (0.6.5)
|
100
98
|
rack
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
[](https://rubygems.org/gems/webpacker)
|
10
10
|
|
11
11
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
12
|
-
[webpack
|
12
|
+
[webpack 4.x.x+](https://webpack.js.org/)
|
13
13
|
to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
|
14
14
|
as the primary purpose for webpack is app-like JavaScript, not images, CSS, or
|
15
15
|
even JavaScript Sprinkles (that all continues to live in app/assets).
|
@@ -32,10 +32,21 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
32
32
|
- [Webpack Configuration](#webpack-configuration)
|
33
33
|
- [Custom Rails environments](#custom-rails-environments)
|
34
34
|
- [Upgrading](#upgrading)
|
35
|
+
- [Integrations](#integrations)
|
36
|
+
- [React](./docs/integrations.md#react)
|
37
|
+
- [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
|
38
|
+
- [Vue](./docs/integrations.md#vue)
|
39
|
+
- [Elm](./docs/integrations.md#elm)
|
40
|
+
- [Stimulus](./docs/integrations.md#stimulus)
|
41
|
+
- [Svelte](./docs/integrations.md#svelte)
|
42
|
+
- [Typescript](./docs/typescript.md)
|
43
|
+
- [CoffeeScript](./docs/integrations.md#coffeescript)
|
44
|
+
- [Erb](./docs/integrations.md#erb)
|
35
45
|
- [Paths](#paths)
|
36
46
|
- [Resolved](#resolved)
|
37
47
|
- [Watched](#watched)
|
38
48
|
- [Deployment](#deployment)
|
49
|
+
- [Docs](#docs)
|
39
50
|
- [Contributing](#contributing)
|
40
51
|
- [License](#license)
|
41
52
|
|
@@ -45,28 +56,23 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
45
56
|
|
46
57
|
- Ruby 2.4+
|
47
58
|
- Rails 5.2+
|
48
|
-
- Node.js 10.
|
59
|
+
- Node.js 10.17.0+ || 12+ || 14+
|
49
60
|
- Yarn 1.x+
|
50
61
|
|
51
62
|
## Features
|
52
63
|
|
53
|
-
- [webpack
|
64
|
+
- [webpack 4.x.x](https://webpack.js.org/)
|
54
65
|
- ES6 with [babel](https://babeljs.io/)
|
55
66
|
- Automatic code splitting using multiple entry points
|
67
|
+
- Stylesheets - Sass and CSS
|
68
|
+
- Images and fonts
|
69
|
+
- PostCSS - Auto-Prefixer
|
56
70
|
- Asset compression, source-maps, and minification
|
57
71
|
- CDN support
|
72
|
+
- React, Angular, Elm and Vue support out-of-the-box
|
58
73
|
- Rails view helpers
|
59
74
|
- Extensible and configurable
|
60
75
|
|
61
|
-
### Optional support
|
62
|
-
|
63
|
-
_requires extra packages to be installed_
|
64
|
-
|
65
|
-
- Stylesheets - Sass, Less, Stylus and Css, PostCSS
|
66
|
-
- CoffeeScript
|
67
|
-
- TypeScript
|
68
|
-
- React
|
69
|
-
|
70
76
|
## Installation
|
71
77
|
|
72
78
|
You can either add Webpacker during setup of a new Rails 5.1+ application
|
@@ -81,11 +87,12 @@ Or add it to your `Gemfile`:
|
|
81
87
|
|
82
88
|
```ruby
|
83
89
|
# Gemfile
|
84
|
-
gem 'webpacker', '~>
|
90
|
+
gem 'webpacker', '~> 5.x'
|
85
91
|
|
86
92
|
# OR if you prefer to use master
|
87
93
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
88
94
|
yarn add https://github.com/rails/webpacker.git
|
95
|
+
yarn add core-js regenerator-runtime
|
89
96
|
```
|
90
97
|
|
91
98
|
Finally, run the following to install Webpacker:
|
@@ -107,8 +114,7 @@ yarn upgrade
|
|
107
114
|
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:
|
108
115
|
|
109
116
|
```bash
|
110
|
-
|
111
|
-
yarn
|
117
|
+
yarn install
|
112
118
|
```
|
113
119
|
|
114
120
|
### Usage
|
@@ -116,9 +122,9 @@ yarn
|
|
116
122
|
Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
|
117
123
|
|
118
124
|
```yml
|
119
|
-
app/
|
120
|
-
├──
|
121
|
-
│ #
|
125
|
+
app/javascript:
|
126
|
+
├── packs:
|
127
|
+
│ # only webpack entry files here
|
122
128
|
│ └── application.js
|
123
129
|
│ └── application.css
|
124
130
|
└── src:
|
@@ -129,50 +135,56 @@ app/packs:
|
|
129
135
|
└── logo.svg
|
130
136
|
```
|
131
137
|
|
132
|
-
|
138
|
+
In `/packs/application.js`, include this at the top of the file:
|
139
|
+
|
140
|
+
```js
|
141
|
+
import 'core-js/stable'
|
142
|
+
import 'regenerator-runtime/runtime'
|
143
|
+
```
|
144
|
+
|
145
|
+
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
|
146
|
+
If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
|
133
147
|
|
134
148
|
```erb
|
135
149
|
<%= javascript_pack_tag 'application' %>
|
136
150
|
<%= stylesheet_pack_tag 'application' %>
|
137
151
|
```
|
138
152
|
|
139
|
-
If you want to link a static asset for `<img />` tag, you
|
153
|
+
If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
|
154
|
+
can use the `asset_pack_path` helper:
|
155
|
+
|
140
156
|
```erb
|
157
|
+
<link rel="prefetch" href="<%= asset_pack_path 'application.css' %>" />
|
141
158
|
<img src="<%= asset_pack_path 'images/logo.svg' %>" />
|
142
159
|
```
|
143
160
|
|
144
|
-
|
145
|
-
|
146
|
-
<%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
|
147
|
-
<%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
|
148
|
-
```
|
161
|
+
If you are using new webpack 4 split chunks API, then consider using `javascript_packs_with_chunks_tag` helper, which creates html
|
162
|
+
tags for a pack and all the dependent chunks.
|
149
163
|
|
150
|
-
If you want to create a favicon:
|
151
164
|
```erb
|
152
|
-
<%=
|
153
|
-
```
|
165
|
+
<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
|
154
166
|
|
155
|
-
|
156
|
-
|
157
|
-
|
167
|
+
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
168
|
+
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
169
|
+
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
170
|
+
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
171
|
+
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
158
172
|
```
|
159
173
|
|
160
|
-
|
174
|
+
**Important:** Pass all your pack names when using `javascript_packs_with_chunks_tag`
|
175
|
+
helper otherwise you will get duplicated chunks on the page.
|
161
176
|
|
162
|
-
```
|
163
|
-
|
164
|
-
|
165
|
-
}
|
166
|
-
```
|
177
|
+
```erb
|
178
|
+
<%# DO %>
|
179
|
+
<%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
|
167
180
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
181
|
+
<%# DON'T %>
|
182
|
+
<%= javascript_packs_with_chunks_tag 'calendar' %>
|
183
|
+
<%= javascript_packs_with_chunks_tag 'map' %>
|
184
|
+
```
|
172
185
|
|
173
186
|
**Note:** In order for your styles or static assets files to be available in your view,
|
174
|
-
you would need to link them in your "pack" or entry file.
|
175
|
-
to package up those files.
|
187
|
+
you would need to link them in your "pack" or entry file.
|
176
188
|
|
177
189
|
### Development
|
178
190
|
|
@@ -184,20 +196,11 @@ are loaded based on your environment.
|
|
184
196
|
In development, Webpacker compiles on demand rather than upfront by default. This
|
185
197
|
happens when you refer to any of the pack assets using the Webpacker helper methods.
|
186
198
|
This means that you don't have to run any separate processes. Compilation errors are logged
|
187
|
-
to the standard Rails log.
|
188
|
-
is made that requires an updated webpack build, not when files change. Thus, that can
|
189
|
-
be painfully slow for front-end development in this default way. Instead, you should either
|
190
|
-
run the `bin/webpack --watch` or run `./bin/webpack-dev-server`
|
191
|
-
|
192
|
-
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`.
|
193
|
-
Windows users will need to run these commands in a terminal separate from `bundle exec rails s`.
|
194
|
-
This process will watch for changes in the `app/packs/entrypoints/*.js` files and automatically
|
195
|
-
reload the browser to match. This feature is also known as
|
196
|
-
[Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
199
|
+
to the standard Rails log.
|
197
200
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
+
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
|
202
|
+
in a terminal separate from `bundle exec rails s`. This process will watch for changes
|
203
|
+
in the `app/javascript/packs/*.js` files and automatically reload the browser to match.
|
201
204
|
|
202
205
|
```bash
|
203
206
|
# webpack dev server
|
@@ -210,10 +213,9 @@ on how to configure rails/webpacker for Fast Refresh with React, see article
|
|
210
213
|
./bin/webpack
|
211
214
|
```
|
212
215
|
|
213
|
-
Once you start this
|
214
|
-
webpack asset requests to this server. When you stop
|
215
|
-
|
216
|
-
the `compile` option set to true in your `config/webpacker.yml`
|
216
|
+
Once you start this development server, Webpacker will automatically start proxying all
|
217
|
+
webpack asset requests to this server. When you stop the server, it'll revert back to
|
218
|
+
on-demand compilation.
|
217
219
|
|
218
220
|
You can use environment variables as options supported by
|
219
221
|
[webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
|
@@ -246,233 +248,7 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
246
248
|
|
247
249
|
### Webpack Configuration
|
248
250
|
|
249
|
-
|
250
|
-
production environments in `config/webpack/*.js`. You can configure each individual
|
251
|
-
environment in their respective files or configure them all in the base
|
252
|
-
`config/webpack/base.js` file.
|
253
|
-
|
254
|
-
By default, you don't need to make any changes to `config/webpack/*.js`
|
255
|
-
files since it's all standard production-ready configuration. However,
|
256
|
-
if you do need to customize or add a new loader, this is where you would go.
|
257
|
-
|
258
|
-
Here is how you can modify webpack configuration:
|
259
|
-
|
260
|
-
You might add separate files to keep your code more organized.
|
261
|
-
|
262
|
-
```js
|
263
|
-
// config/webpack/custom.js
|
264
|
-
module.exports = {
|
265
|
-
resolve: {
|
266
|
-
alias: {
|
267
|
-
jquery: 'jquery/src/jquery',
|
268
|
-
vue: 'vue/dist/vue.js',
|
269
|
-
React: 'react',
|
270
|
-
ReactDOM: 'react-dom',
|
271
|
-
vue_resource: 'vue-resource/dist/vue-resource'
|
272
|
-
}
|
273
|
-
}
|
274
|
-
}
|
275
|
-
```
|
276
|
-
|
277
|
-
Then `require` this file in your `config/webpack/base.js`:
|
278
|
-
|
279
|
-
```js
|
280
|
-
// config/webpack/base.js
|
281
|
-
const { webpackConfig, merge } = require('@rails/webpacker')
|
282
|
-
const customConfig = require('./custom')
|
283
|
-
|
284
|
-
module.exports = merge(webpackConfig, customConfig)
|
285
|
-
```
|
286
|
-
|
287
|
-
If you need access to configs within Webpacker's configuration,
|
288
|
-
you can import them like so:
|
289
|
-
|
290
|
-
```js
|
291
|
-
// config/webpack/base.js
|
292
|
-
const { webpackConfig } = require('@rails/webpacker')
|
293
|
-
|
294
|
-
console.log(webpackConfig.output_path)
|
295
|
-
console.log(webpackConfig.source_path)
|
296
|
-
|
297
|
-
// Or to print out your whole webpack configuration
|
298
|
-
console.log(JSON.stringify(webpackConfig, undefined, 2))
|
299
|
-
```
|
300
|
-
|
301
|
-
### Integrations
|
302
|
-
|
303
|
-
Webpacker out of the box supports JS and static assets (fonts, images etc.)
|
304
|
-
compilation. To enable support for CoffeeScript or TypeScript install
|
305
|
-
relevant packages:
|
306
|
-
|
307
|
-
#### CoffeeScript
|
308
|
-
|
309
|
-
```bash
|
310
|
-
yarn add coffeescript coffee-loader
|
311
|
-
```
|
312
|
-
|
313
|
-
#### TypeScript
|
314
|
-
|
315
|
-
```bash
|
316
|
-
yarn add typescript @babel/preset-typescript
|
317
|
-
```
|
318
|
-
|
319
|
-
Add tsconfig.json
|
320
|
-
|
321
|
-
```json
|
322
|
-
{
|
323
|
-
"compilerOptions": {
|
324
|
-
"declaration": false,
|
325
|
-
"emitDecoratorMetadata": true,
|
326
|
-
"experimentalDecorators": true,
|
327
|
-
"lib": ["es6", "dom"],
|
328
|
-
"module": "es6",
|
329
|
-
"moduleResolution": "node",
|
330
|
-
"baseUrl": ".",
|
331
|
-
"paths": {
|
332
|
-
"*": ["node_modules/*", "app/packs/*"]
|
333
|
-
},
|
334
|
-
"sourceMap": true,
|
335
|
-
"target": "es5",
|
336
|
-
"noEmit": true
|
337
|
-
},
|
338
|
-
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
339
|
-
"compileOnSave": false
|
340
|
-
}
|
341
|
-
```
|
342
|
-
|
343
|
-
Babel won’t perform any type-checking on TypeScript code. To optionally use type-checking run:
|
344
|
-
|
345
|
-
```bash
|
346
|
-
yarn add fork-ts-checker-webpack-plugin
|
347
|
-
```
|
348
|
-
|
349
|
-
Then modify the webpack config to use it as a plugin:
|
350
|
-
|
351
|
-
```js
|
352
|
-
// config/webpack/base.js
|
353
|
-
const { webpackConfig, merge } = require("@rails/webpacker");
|
354
|
-
const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
355
|
-
|
356
|
-
module.exports = merge(webpackConfig, {
|
357
|
-
plugins: [new ForkTSCheckerWebpackPlugin()],
|
358
|
-
});
|
359
|
-
```
|
360
|
-
|
361
|
-
#### CSS
|
362
|
-
|
363
|
-
To enable CSS support in your application, add following packages:
|
364
|
-
|
365
|
-
```bash
|
366
|
-
yarn add css-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
367
|
-
```
|
368
|
-
|
369
|
-
optionally, add the css extension to webpack config for easy resolution.
|
370
|
-
|
371
|
-
```js
|
372
|
-
// config/webpack/base.js
|
373
|
-
const { webpackConfig, merge } = require('@rails/webpacker')
|
374
|
-
const customConfig = {
|
375
|
-
resolve: {
|
376
|
-
extensions: ['.css']
|
377
|
-
}
|
378
|
-
}
|
379
|
-
|
380
|
-
module.exports = merge(webpackConfig, customConfig)
|
381
|
-
```
|
382
|
-
|
383
|
-
To enable postcss, sass or less support, add css support first and
|
384
|
-
then add the relevant pre-processors:
|
385
|
-
|
386
|
-
#### Postcss
|
387
|
-
|
388
|
-
```bash
|
389
|
-
yarn add postcss-loader
|
390
|
-
```
|
391
|
-
|
392
|
-
#### Sass
|
393
|
-
|
394
|
-
```bash
|
395
|
-
yarn add sass sass-loader
|
396
|
-
```
|
397
|
-
|
398
|
-
#### Less
|
399
|
-
|
400
|
-
```bash
|
401
|
-
yarn add less less-loader
|
402
|
-
```
|
403
|
-
|
404
|
-
#### Stylus
|
405
|
-
|
406
|
-
```bash
|
407
|
-
yarn add stylus stylus-loader
|
408
|
-
```
|
409
|
-
|
410
|
-
#### React
|
411
|
-
|
412
|
-
React is supported and you just need to add relevant packages,
|
413
|
-
|
414
|
-
```bash
|
415
|
-
yarn add react react-dom @babel/preset-react
|
416
|
-
```
|
417
|
-
|
418
|
-
if you are using typescript, update your `tsconfig.json`
|
419
|
-
|
420
|
-
```json
|
421
|
-
{
|
422
|
-
"compilerOptions": {
|
423
|
-
"declaration": false,
|
424
|
-
"emitDecoratorMetadata": true,
|
425
|
-
"experimentalDecorators": true,
|
426
|
-
"lib": ["es6", "dom"],
|
427
|
-
"module": "es6",
|
428
|
-
"moduleResolution": "node",
|
429
|
-
"sourceMap": true,
|
430
|
-
"target": "es5",
|
431
|
-
"jsx": "react",
|
432
|
-
"noEmit": true
|
433
|
-
},
|
434
|
-
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
435
|
-
"compileOnSave": false
|
436
|
-
}
|
437
|
-
```
|
438
|
-
|
439
|
-
For more information on React props hydration and Server-Side Rendering (SSR), see the article
|
440
|
-
[Rails/Webpacker React Integration Options](https://github.com/shakacode/react_on_rails/blob/master/docs/rails-webpacker-react-integration-options.md)
|
441
|
-
in the [ShakaCode/react_on_rails](https://github.com/shakacode/react_on_rails) repo.
|
442
|
-
|
443
|
-
#### Other frameworks
|
444
|
-
|
445
|
-
Please follow webpack integration guide for relevant framework or library,
|
446
|
-
|
447
|
-
1. [Svelte](https://github.com/sveltejs/svelte-loader#install)
|
448
|
-
2. [Angular](https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack)
|
449
|
-
3. [Vue](https://vue-loader.vuejs.org/guide/)
|
450
|
-
|
451
|
-
For example to add Vue support:
|
452
|
-
```js
|
453
|
-
// config/webpack/rules/vue.js
|
454
|
-
const VueLoaderPlugin = require('vue-loader/lib/plugin')
|
455
|
-
|
456
|
-
module.exports = {
|
457
|
-
module: {
|
458
|
-
rules: [
|
459
|
-
{
|
460
|
-
test: /\.vue$/,
|
461
|
-
loader: 'vue-loader'
|
462
|
-
}
|
463
|
-
]
|
464
|
-
},
|
465
|
-
plugins: [new VueLoaderPlugin()]
|
466
|
-
}
|
467
|
-
```
|
468
|
-
|
469
|
-
```js
|
470
|
-
// config/webpack/base.js
|
471
|
-
const { webpackConfig, merge } = require('@rails/webpacker')
|
472
|
-
const vueConfig = require('./rules/vue')
|
473
|
-
|
474
|
-
module.exports = merge(webpackConfig, vueConfig)
|
475
|
-
```
|
251
|
+
See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
|
476
252
|
|
477
253
|
### Custom Rails environments
|
478
254
|
|
@@ -514,11 +290,11 @@ Please note, binstubs compiles in development mode however rake tasks
|
|
514
290
|
compiles in production mode.
|
515
291
|
|
516
292
|
```bash
|
517
|
-
# Compiles in development mode unless NODE_ENV is specified
|
293
|
+
# Compiles in development mode unless NODE_ENV is specified
|
518
294
|
./bin/webpack
|
519
295
|
./bin/webpack-dev-server
|
520
296
|
|
521
|
-
#
|
297
|
+
# compiles in production mode by default unless NODE_ENV is specified
|
522
298
|
bundle exec rails assets:precompile
|
523
299
|
bundle exec rails webpacker:compile
|
524
300
|
```
|
@@ -528,12 +304,8 @@ bundle exec rails webpacker:compile
|
|
528
304
|
You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
|
529
305
|
|
530
306
|
```bash
|
531
|
-
# check your Gemfile for version restrictions
|
532
307
|
bundle update webpacker
|
533
|
-
|
534
|
-
# overwrite your changes to the default install files and revert any unwanted changes from the install
|
535
308
|
rails webpacker:install
|
536
|
-
|
537
309
|
yarn upgrade @rails/webpacker --latest
|
538
310
|
yarn upgrade webpack-dev-server --latest
|
539
311
|
|
@@ -541,7 +313,23 @@ yarn upgrade webpack-dev-server --latest
|
|
541
313
|
yarn add @rails/webpacker@next
|
542
314
|
```
|
543
315
|
|
544
|
-
|
316
|
+
## Integrations
|
317
|
+
|
318
|
+
Webpacker ships with basic out-of-the-box integration. You can see a list of available commands/tasks by running `bundle exec rails webpacker`.
|
319
|
+
|
320
|
+
Included install integrations:
|
321
|
+
|
322
|
+
- [React](./docs/integrations.md#React)
|
323
|
+
- [Angular with TypeScript](./docs/integrations.md#Angular-with-TypeScript)
|
324
|
+
- [Vue](./docs/integrations.md#Vue)
|
325
|
+
- [Elm](./docs/integrations.md#Elm)
|
326
|
+
- [Svelte](./docs/integrations.md#Svelte)
|
327
|
+
- [Stimulus](./docs/integrations.md#Stimulus)
|
328
|
+
- [CoffeeScript](./docs/integrations.md#CoffeeScript)
|
329
|
+
- [Typescript](./docs/typescript.md)
|
330
|
+
- [Erb](./docs/integrations.md#Erb)
|
331
|
+
|
332
|
+
See [Integrations](./docs/integrations.md) for further details.
|
545
333
|
|
546
334
|
## Paths
|
547
335
|
|
@@ -550,18 +338,19 @@ app files and compiled webpack bundles will go in your Rails app.
|
|
550
338
|
All these options are configurable from `config/webpacker.yml` file.
|
551
339
|
|
552
340
|
The configuration for what webpack is supposed to compile by default rests
|
553
|
-
on the convention that every file in `app/packs
|
341
|
+
on the convention that every file in `app/javascript/packs/*`**(default)**
|
554
342
|
or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
|
555
343
|
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
|
556
344
|
an entry file. As a rule of thumb, put all files you want to link in your views inside
|
557
|
-
"packs" directory and keep everything else under `app/
|
345
|
+
"packs" directory and keep everything else under `app/javascript`.
|
558
346
|
|
559
|
-
Suppose you want to change the source directory from `app/
|
347
|
+
Suppose you want to change the source directory from `app/javascript`
|
560
348
|
to `frontend` and output to `assets/packs`. This is how you would do it:
|
561
349
|
|
562
350
|
```yml
|
563
351
|
# config/webpacker.yml
|
564
|
-
source_path: frontend
|
352
|
+
source_path: frontend
|
353
|
+
source_entry_path: packs
|
565
354
|
public_output_path: assets/packs # outputs to => public/assets/packs
|
566
355
|
```
|
567
356
|
|
@@ -575,11 +364,9 @@ development:
|
|
575
364
|
port: 3035
|
576
365
|
```
|
577
366
|
|
578
|
-
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output,
|
579
|
-
as you will want to configure your styles to be inlined in your JavaScript for hot reloading.
|
580
|
-
During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
|
367
|
+
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.
|
581
368
|
|
582
|
-
###
|
369
|
+
### Resolved
|
583
370
|
|
584
371
|
If you are adding Webpacker to an existing app that has most of the assets inside
|
585
372
|
`app/assets` or inside an engine, and you want to share that
|
@@ -588,7 +375,7 @@ option available in `config/webpacker.yml`. This lets you
|
|
588
375
|
add additional paths that webpack should lookup when resolving modules:
|
589
376
|
|
590
377
|
```yml
|
591
|
-
additional_paths: ['app/assets'
|
378
|
+
additional_paths: ['app/assets']
|
592
379
|
```
|
593
380
|
|
594
381
|
You can then import these items inside your modules like so:
|
@@ -609,9 +396,25 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
609
396
|
|
610
397
|
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.
|
611
398
|
|
612
|
-
##
|
613
|
-
|
614
|
-
|
399
|
+
## Docs
|
400
|
+
|
401
|
+
- [Development](https://github.com/rails/webpacker#development)
|
402
|
+
- [Webpack](./docs/webpack.md)
|
403
|
+
- [Webpack-dev-server](./docs/webpack-dev-server.md)
|
404
|
+
- [Environment Variables](./docs/env.md)
|
405
|
+
- [Folder Structure](./docs/folder-structure.md)
|
406
|
+
- [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
|
407
|
+
- [Props](./docs/props.md)
|
408
|
+
- [Typescript](./docs/typescript.md)
|
409
|
+
- [Yarn](./docs/yarn.md)
|
410
|
+
- [Misc](./docs/misc.md)
|
411
|
+
- [Deployment](./docs/deployment.md)
|
412
|
+
- [Docker](./docs/docker.md)
|
413
|
+
- [Using in Rails engines](./docs/engines.md)
|
414
|
+
- [Webpacker on Cloud9](./docs/cloud9.md)
|
415
|
+
- [Testing](./docs/testing.md)
|
416
|
+
- [Troubleshooting](./docs/troubleshooting.md)
|
417
|
+
- [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
|
615
418
|
|
616
419
|
## Contributing
|
617
420
|
|