webpacker 6.0.0.beta.7 → 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/.rubocop.yml +0 -105
- data/CHANGELOG.md +6 -22
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +90 -93
- data/README.md +110 -308
- data/docs/assets.md +135 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +303 -0
- data/docs/deployment.md +29 -9
- 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 +3 -5
- 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 +9 -16
- data/lib/tasks/webpacker/binstubs.rake +2 -2
- data/lib/tasks/webpacker/check_node.rake +0 -1
- data/lib/tasks/webpacker/check_yarn.rake +0 -1
- data/lib/tasks/webpacker/install.rake +2 -2
- data/lib/webpacker/commands.rb +1 -2
- data/lib/webpacker/compiler.rb +3 -9
- data/lib/webpacker/configuration.rb +4 -4
- 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 +20 -15
- 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 +3 -3
- 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 +3 -3
- data/test/test_app/public/packs/manifest.json +0 -7
- metadata +36 -18
- data/config/README.md +0 -3
- data/config/webpacker.yml +0 -1
- data/docs/v6_upgrade.md +0 -86
- data/package/__tests__/index.js +0 -9
- data/package/rules/raw.js +0 -5
- data/package/rules/stylus.js +0 -26
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
|
-
[
|
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.
|
49
|
-
- Yarn 1.x+
|
59
|
+
- Node.js 10.17.0+ || 12+ || 14+
|
60
|
+
- Yarn 1.x+
|
50
61
|
|
51
62
|
## Features
|
52
63
|
|
53
|
-
- [
|
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:
|
@@ -115,9 +122,9 @@ yarn install
|
|
115
122
|
Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
|
116
123
|
|
117
124
|
```yml
|
118
|
-
app/
|
119
|
-
├──
|
120
|
-
│ #
|
125
|
+
app/javascript:
|
126
|
+
├── packs:
|
127
|
+
│ # only webpack entry files here
|
121
128
|
│ └── application.js
|
122
129
|
│ └── application.css
|
123
130
|
└── src:
|
@@ -128,50 +135,56 @@ app/packs:
|
|
128
135
|
└── logo.svg
|
129
136
|
```
|
130
137
|
|
131
|
-
|
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`:
|
132
147
|
|
133
148
|
```erb
|
134
149
|
<%= javascript_pack_tag 'application' %>
|
135
150
|
<%= stylesheet_pack_tag 'application' %>
|
136
151
|
```
|
137
152
|
|
138
|
-
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
|
+
|
139
156
|
```erb
|
157
|
+
<link rel="prefetch" href="<%= asset_pack_path 'application.css' %>" />
|
140
158
|
<img src="<%= asset_pack_path 'images/logo.svg' %>" />
|
141
159
|
```
|
142
160
|
|
143
|
-
|
144
|
-
|
145
|
-
<%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
|
146
|
-
<%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
|
147
|
-
```
|
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.
|
148
163
|
|
149
|
-
If you want to create a favicon:
|
150
164
|
```erb
|
151
|
-
<%=
|
152
|
-
```
|
165
|
+
<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
|
153
166
|
|
154
|
-
|
155
|
-
|
156
|
-
|
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>
|
157
172
|
```
|
158
173
|
|
159
|
-
|
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.
|
160
176
|
|
161
|
-
```
|
162
|
-
|
163
|
-
|
164
|
-
}
|
165
|
-
```
|
177
|
+
```erb
|
178
|
+
<%# DO %>
|
179
|
+
<%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
|
166
180
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
181
|
+
<%# DON'T %>
|
182
|
+
<%= javascript_packs_with_chunks_tag 'calendar' %>
|
183
|
+
<%= javascript_packs_with_chunks_tag 'map' %>
|
184
|
+
```
|
171
185
|
|
172
186
|
**Note:** In order for your styles or static assets files to be available in your view,
|
173
|
-
you would need to link them in your "pack" or entry file.
|
174
|
-
to package up those files.
|
187
|
+
you would need to link them in your "pack" or entry file.
|
175
188
|
|
176
189
|
### Development
|
177
190
|
|
@@ -183,20 +196,11 @@ are loaded based on your environment.
|
|
183
196
|
In development, Webpacker compiles on demand rather than upfront by default. This
|
184
197
|
happens when you refer to any of the pack assets using the Webpacker helper methods.
|
185
198
|
This means that you don't have to run any separate processes. Compilation errors are logged
|
186
|
-
to the standard Rails log.
|
187
|
-
is made that requires an updated webpack build, not when files change. Thus, that can
|
188
|
-
be painfully slow for front-end development in this default way. Instead, you should either
|
189
|
-
run the `bin/webpack --watch` or run `./bin/webpack-dev-server`
|
190
|
-
|
191
|
-
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`.
|
192
|
-
Windows users will need to run these commands in a terminal separate from `bundle exec rails s`.
|
193
|
-
This process will watch for changes in the `app/packs/entrypoints/*.js` files and automatically
|
194
|
-
reload the browser to match. This feature is also known as
|
195
|
-
[Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
199
|
+
to the standard Rails log.
|
196
200
|
|
197
|
-
|
198
|
-
|
199
|
-
|
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.
|
200
204
|
|
201
205
|
```bash
|
202
206
|
# webpack dev server
|
@@ -209,10 +213,9 @@ on how to configure rails/webpacker for Fast Refresh with React, see article
|
|
209
213
|
./bin/webpack
|
210
214
|
```
|
211
215
|
|
212
|
-
Once you start this
|
213
|
-
webpack asset requests to this server. When you stop
|
214
|
-
|
215
|
-
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.
|
216
219
|
|
217
220
|
You can use environment variables as options supported by
|
218
221
|
[webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
|
@@ -245,233 +248,7 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
245
248
|
|
246
249
|
### Webpack Configuration
|
247
250
|
|
248
|
-
|
249
|
-
production environments in `config/webpack/*.js`. You can configure each individual
|
250
|
-
environment in their respective files or configure them all in the base
|
251
|
-
`config/webpack/base.js` file.
|
252
|
-
|
253
|
-
By default, you don't need to make any changes to `config/webpack/*.js`
|
254
|
-
files since it's all standard production-ready configuration. However,
|
255
|
-
if you do need to customize or add a new loader, this is where you would go.
|
256
|
-
|
257
|
-
Here is how you can modify webpack configuration:
|
258
|
-
|
259
|
-
You might add separate files to keep your code more organized.
|
260
|
-
|
261
|
-
```js
|
262
|
-
// config/webpack/custom.js
|
263
|
-
module.exports = {
|
264
|
-
resolve: {
|
265
|
-
alias: {
|
266
|
-
jquery: 'jquery/src/jquery',
|
267
|
-
vue: 'vue/dist/vue.js',
|
268
|
-
React: 'react',
|
269
|
-
ReactDOM: 'react-dom',
|
270
|
-
vue_resource: 'vue-resource/dist/vue-resource'
|
271
|
-
}
|
272
|
-
}
|
273
|
-
}
|
274
|
-
```
|
275
|
-
|
276
|
-
Then `require` this file in your `config/webpack/base.js`:
|
277
|
-
|
278
|
-
```js
|
279
|
-
// config/webpack/base.js
|
280
|
-
const { webpackConfig, merge } = require('@rails/webpacker')
|
281
|
-
const customConfig = require('./custom')
|
282
|
-
|
283
|
-
module.exports = merge(webpackConfig, customConfig)
|
284
|
-
```
|
285
|
-
|
286
|
-
If you need access to configs within Webpacker's configuration,
|
287
|
-
you can import them like so:
|
288
|
-
|
289
|
-
```js
|
290
|
-
// config/webpack/base.js
|
291
|
-
const { webpackConfig } = require('@rails/webpacker')
|
292
|
-
|
293
|
-
console.log(webpackConfig.output_path)
|
294
|
-
console.log(webpackConfig.source_path)
|
295
|
-
|
296
|
-
// Or to print out your whole webpack configuration
|
297
|
-
console.log(JSON.stringify(webpackConfig, undefined, 2))
|
298
|
-
```
|
299
|
-
|
300
|
-
### Integrations
|
301
|
-
|
302
|
-
Webpacker out of the box supports JS and static assets (fonts, images etc.)
|
303
|
-
compilation. To enable support for CoffeeScript or TypeScript install
|
304
|
-
relevant packages:
|
305
|
-
|
306
|
-
#### CoffeeScript
|
307
|
-
|
308
|
-
```bash
|
309
|
-
yarn add coffeescript coffee-loader
|
310
|
-
```
|
311
|
-
|
312
|
-
#### TypeScript
|
313
|
-
|
314
|
-
```bash
|
315
|
-
yarn add typescript @babel/preset-typescript
|
316
|
-
```
|
317
|
-
|
318
|
-
Add tsconfig.json
|
319
|
-
|
320
|
-
```json
|
321
|
-
{
|
322
|
-
"compilerOptions": {
|
323
|
-
"declaration": false,
|
324
|
-
"emitDecoratorMetadata": true,
|
325
|
-
"experimentalDecorators": true,
|
326
|
-
"lib": ["es6", "dom"],
|
327
|
-
"module": "es6",
|
328
|
-
"moduleResolution": "node",
|
329
|
-
"baseUrl": ".",
|
330
|
-
"paths": {
|
331
|
-
"*": ["node_modules/*", "app/packs/*"]
|
332
|
-
},
|
333
|
-
"sourceMap": true,
|
334
|
-
"target": "es5",
|
335
|
-
"noEmit": true
|
336
|
-
},
|
337
|
-
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
338
|
-
"compileOnSave": false
|
339
|
-
}
|
340
|
-
```
|
341
|
-
|
342
|
-
Babel won’t perform any type-checking on TypeScript code. To optionally use type-checking run:
|
343
|
-
|
344
|
-
```bash
|
345
|
-
yarn add fork-ts-checker-webpack-plugin
|
346
|
-
```
|
347
|
-
|
348
|
-
Then modify the webpack config to use it as a plugin:
|
349
|
-
|
350
|
-
```js
|
351
|
-
// config/webpack/base.js
|
352
|
-
const { webpackConfig, merge } = require("@rails/webpacker");
|
353
|
-
const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
354
|
-
|
355
|
-
module.exports = merge(webpackConfig, {
|
356
|
-
plugins: [new ForkTSCheckerWebpackPlugin()],
|
357
|
-
});
|
358
|
-
```
|
359
|
-
|
360
|
-
#### CSS
|
361
|
-
|
362
|
-
To enable CSS support in your application, add following packages:
|
363
|
-
|
364
|
-
```bash
|
365
|
-
yarn add css-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
366
|
-
```
|
367
|
-
|
368
|
-
optionally, add the css extension to webpack config for easy resolution.
|
369
|
-
|
370
|
-
```js
|
371
|
-
// config/webpack/base.js
|
372
|
-
const { webpackConfig, merge } = require('@rails/webpacker')
|
373
|
-
const customConfig = {
|
374
|
-
resolve: {
|
375
|
-
extensions: ['.css']
|
376
|
-
}
|
377
|
-
}
|
378
|
-
|
379
|
-
module.exports = merge(webpackConfig, customConfig)
|
380
|
-
```
|
381
|
-
|
382
|
-
To enable postcss, sass or less support, add css support first and
|
383
|
-
then add the relevant pre-processors:
|
384
|
-
|
385
|
-
#### Postcss
|
386
|
-
|
387
|
-
```bash
|
388
|
-
yarn add postcss-loader
|
389
|
-
```
|
390
|
-
|
391
|
-
#### Sass
|
392
|
-
|
393
|
-
```bash
|
394
|
-
yarn add sass sass-loader
|
395
|
-
```
|
396
|
-
|
397
|
-
#### Less
|
398
|
-
|
399
|
-
```bash
|
400
|
-
yarn add less less-loader
|
401
|
-
```
|
402
|
-
|
403
|
-
#### Stylus
|
404
|
-
|
405
|
-
```bash
|
406
|
-
yarn add stylus stylus-loader
|
407
|
-
```
|
408
|
-
|
409
|
-
#### React
|
410
|
-
|
411
|
-
React is supported and you just need to add relevant packages,
|
412
|
-
|
413
|
-
```bash
|
414
|
-
yarn add react react-dom @babel/preset-react
|
415
|
-
```
|
416
|
-
|
417
|
-
if you are using typescript, update your `tsconfig.json`
|
418
|
-
|
419
|
-
```json
|
420
|
-
{
|
421
|
-
"compilerOptions": {
|
422
|
-
"declaration": false,
|
423
|
-
"emitDecoratorMetadata": true,
|
424
|
-
"experimentalDecorators": true,
|
425
|
-
"lib": ["es6", "dom"],
|
426
|
-
"module": "es6",
|
427
|
-
"moduleResolution": "node",
|
428
|
-
"sourceMap": true,
|
429
|
-
"target": "es5",
|
430
|
-
"jsx": "react",
|
431
|
-
"noEmit": true
|
432
|
-
},
|
433
|
-
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
434
|
-
"compileOnSave": false
|
435
|
-
}
|
436
|
-
```
|
437
|
-
|
438
|
-
For more information on React props hydration and Server-Side Rendering (SSR), see the article
|
439
|
-
[Rails/Webpacker React Integration Options](https://github.com/shakacode/react_on_rails/blob/master/docs/rails-webpacker-react-integration-options.md)
|
440
|
-
in the [ShakaCode/react_on_rails](https://github.com/shakacode/react_on_rails) repo.
|
441
|
-
|
442
|
-
#### Other frameworks
|
443
|
-
|
444
|
-
Please follow webpack integration guide for relevant framework or library,
|
445
|
-
|
446
|
-
1. [Svelte](https://github.com/sveltejs/svelte-loader#install)
|
447
|
-
2. [Angular](https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack)
|
448
|
-
3. [Vue](https://vue-loader.vuejs.org/guide/)
|
449
|
-
|
450
|
-
For example to add Vue support:
|
451
|
-
```js
|
452
|
-
// config/webpack/rules/vue.js
|
453
|
-
const VueLoaderPlugin = require('vue-loader/lib/plugin')
|
454
|
-
|
455
|
-
module.exports = {
|
456
|
-
module: {
|
457
|
-
rules: [
|
458
|
-
{
|
459
|
-
test: /\.vue$/,
|
460
|
-
loader: 'vue-loader'
|
461
|
-
}
|
462
|
-
]
|
463
|
-
},
|
464
|
-
plugins: [new VueLoaderPlugin()]
|
465
|
-
}
|
466
|
-
```
|
467
|
-
|
468
|
-
```js
|
469
|
-
// config/webpack/base.js
|
470
|
-
const { webpackConfig, merge } = require('@rails/webpacker')
|
471
|
-
const vueConfig = require('./rules/vue')
|
472
|
-
|
473
|
-
module.exports = merge(webpackConfig, vueConfig)
|
474
|
-
```
|
251
|
+
See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
|
475
252
|
|
476
253
|
### Custom Rails environments
|
477
254
|
|
@@ -513,11 +290,11 @@ Please note, binstubs compiles in development mode however rake tasks
|
|
513
290
|
compiles in production mode.
|
514
291
|
|
515
292
|
```bash
|
516
|
-
# Compiles in development mode unless NODE_ENV is specified
|
293
|
+
# Compiles in development mode unless NODE_ENV is specified
|
517
294
|
./bin/webpack
|
518
295
|
./bin/webpack-dev-server
|
519
296
|
|
520
|
-
#
|
297
|
+
# compiles in production mode by default unless NODE_ENV is specified
|
521
298
|
bundle exec rails assets:precompile
|
522
299
|
bundle exec rails webpacker:compile
|
523
300
|
```
|
@@ -527,12 +304,8 @@ bundle exec rails webpacker:compile
|
|
527
304
|
You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
|
528
305
|
|
529
306
|
```bash
|
530
|
-
# check your Gemfile for version restrictions
|
531
307
|
bundle update webpacker
|
532
|
-
|
533
|
-
# overwrite your changes to the default install files and revert any unwanted changes from the install
|
534
308
|
rails webpacker:install
|
535
|
-
|
536
309
|
yarn upgrade @rails/webpacker --latest
|
537
310
|
yarn upgrade webpack-dev-server --latest
|
538
311
|
|
@@ -540,7 +313,23 @@ yarn upgrade webpack-dev-server --latest
|
|
540
313
|
yarn add @rails/webpacker@next
|
541
314
|
```
|
542
315
|
|
543
|
-
|
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.
|
544
333
|
|
545
334
|
## Paths
|
546
335
|
|
@@ -549,18 +338,19 @@ app files and compiled webpack bundles will go in your Rails app.
|
|
549
338
|
All these options are configurable from `config/webpacker.yml` file.
|
550
339
|
|
551
340
|
The configuration for what webpack is supposed to compile by default rests
|
552
|
-
on the convention that every file in `app/packs
|
341
|
+
on the convention that every file in `app/javascript/packs/*`**(default)**
|
553
342
|
or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
|
554
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
|
555
344
|
an entry file. As a rule of thumb, put all files you want to link in your views inside
|
556
|
-
"packs" directory and keep everything else under `app/
|
345
|
+
"packs" directory and keep everything else under `app/javascript`.
|
557
346
|
|
558
|
-
Suppose you want to change the source directory from `app/
|
347
|
+
Suppose you want to change the source directory from `app/javascript`
|
559
348
|
to `frontend` and output to `assets/packs`. This is how you would do it:
|
560
349
|
|
561
350
|
```yml
|
562
351
|
# config/webpacker.yml
|
563
|
-
source_path: frontend
|
352
|
+
source_path: frontend
|
353
|
+
source_entry_path: packs
|
564
354
|
public_output_path: assets/packs # outputs to => public/assets/packs
|
565
355
|
```
|
566
356
|
|
@@ -574,20 +364,18 @@ development:
|
|
574
364
|
port: 3035
|
575
365
|
```
|
576
366
|
|
577
|
-
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output,
|
578
|
-
as you will want to configure your styles to be inlined in your JavaScript for hot reloading.
|
579
|
-
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.
|
580
368
|
|
581
|
-
###
|
369
|
+
### Resolved
|
582
370
|
|
583
371
|
If you are adding Webpacker to an existing app that has most of the assets inside
|
584
372
|
`app/assets` or inside an engine, and you want to share that
|
585
373
|
with webpack modules, you can use the `additional_paths`
|
586
374
|
option available in `config/webpacker.yml`. This lets you
|
587
|
-
add additional paths that webpack should
|
375
|
+
add additional paths that webpack should lookup when resolving modules:
|
588
376
|
|
589
377
|
```yml
|
590
|
-
additional_paths: ['app/assets'
|
378
|
+
additional_paths: ['app/assets']
|
591
379
|
```
|
592
380
|
|
593
381
|
You can then import these items inside your modules like so:
|
@@ -608,11 +396,25 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
608
396
|
|
609
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.
|
610
398
|
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
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)
|
616
418
|
|
617
419
|
## Contributing
|
618
420
|
|