webpacker 5.4.4 → 6.0.0.beta
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/ruby.yml +28 -4
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +3 -111
- data/6_0_upgrade.md +43 -0
- data/CHANGELOG.md +19 -26
- data/Gemfile.lock +91 -94
- data/README.md +215 -98
- data/gemfiles/Gemfile-rails-edge +1 -1
- 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 +8 -37
- data/lib/install/javascript/packs/application.css +9 -0
- data/lib/install/javascript/packs/application.js +3 -1
- data/lib/install/template.rb +33 -27
- data/lib/tasks/webpacker/binstubs.rake +6 -4
- data/lib/tasks/webpacker/check_binstubs.rake +4 -4
- data/lib/tasks/webpacker/check_yarn.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_install.rake +2 -1
- data/lib/tasks/webpacker/yarn_install.rake +9 -7
- data/lib/tasks/webpacker.rake +2 -11
- data/lib/webpacker/compiler.rb +15 -8
- data/lib/webpacker/configuration.rb +10 -45
- data/lib/webpacker/dev_server_runner.rb +21 -2
- data/lib/webpacker/env.rb +1 -5
- data/lib/webpacker/helper.rb +22 -32
- data/lib/webpacker/manifest.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +5 -0
- data/package/__tests__/config.js +5 -37
- data/package/__tests__/development.js +9 -11
- data/package/__tests__/env.js +12 -4
- 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 +55 -0
- data/package/config.js +3 -11
- data/package/env.js +8 -2
- data/package/environments/__tests__/base.js +15 -47
- data/package/environments/base.js +62 -125
- data/package/environments/development.js +45 -44
- data/package/environments/production.js +63 -68
- data/package/environments/test.js +2 -2
- data/package/index.js +13 -8
- data/package/rules/babel.js +9 -7
- data/package/rules/coffee.js +6 -0
- data/package/rules/erb.js +15 -0
- data/package/rules/file.js +19 -19
- data/package/rules/index.js +15 -18
- data/package/rules/less.js +22 -0
- data/package/rules/sass.js +10 -10
- data/package/rules/svg.js +20 -0
- data/package/utils/get_style_rule.js +26 -36
- data/package/utils/helpers.js +26 -35
- data/package.json +29 -45
- data/test/compiler_test.rb +0 -12
- data/test/configuration_test.rb +1 -32
- data/test/dev_server_runner_test.rb +24 -5
- data/test/engine_rake_tasks_test.rb +39 -0
- data/test/helper_test.rb +24 -30
- 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/config/webpacker.yml +1 -25
- data/test/test_app/config/webpacker_public_root.yml +0 -1
- data/test/test_app/public/packs/manifest.json +17 -13
- data/test/test_app/some.config.js +0 -0
- data/test/webpack_runner_test.rb +9 -3
- data/yarn.lock +2505 -4943
- metadata +37 -82
- data/docs/assets.md +0 -119
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -308
- data/docs/deployment.md +0 -130
- 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/troubleshooting.md +0 -158
- 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 -82
- 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 -99
- 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/README.md
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](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 5.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).
|
@@ -17,7 +17,7 @@ even JavaScript Sprinkles (that all continues to live in app/assets).
|
|
17
17
|
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
|
18
18
|
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
|
19
19
|
|
20
|
-
**NOTE:** The master branch now hosts the code for
|
20
|
+
**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.
|
21
21
|
|
22
22
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
23
23
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
@@ -32,16 +32,6 @@ 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)
|
45
35
|
- [Paths](#paths)
|
46
36
|
- [Resolved](#resolved)
|
47
37
|
- [Watched](#watched)
|
@@ -56,23 +46,28 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
56
46
|
|
57
47
|
- Ruby 2.4+
|
58
48
|
- Rails 5.2+
|
59
|
-
- Node.js 10.
|
49
|
+
- Node.js 10.22.1+ || 12+ || 14+
|
60
50
|
- Yarn 1.x+
|
61
51
|
|
62
52
|
## Features
|
63
53
|
|
64
|
-
- [webpack
|
54
|
+
- [webpack 5.x.x](https://webpack.js.org/)
|
65
55
|
- ES6 with [babel](https://babeljs.io/)
|
66
56
|
- Automatic code splitting using multiple entry points
|
67
|
-
- Stylesheets - Sass and CSS
|
68
|
-
- Images and fonts
|
69
|
-
- PostCSS - Auto-Prefixer
|
70
57
|
- Asset compression, source-maps, and minification
|
71
58
|
- CDN support
|
72
|
-
- React, Angular, Elm and Vue support out-of-the-box
|
73
59
|
- Rails view helpers
|
74
60
|
- Extensible and configurable
|
75
61
|
|
62
|
+
### Optional support\*
|
63
|
+
|
64
|
+
_requires extra packages to be installed_
|
65
|
+
|
66
|
+
- Stylesheets - SASS, LESS and CSS, PostCSS
|
67
|
+
- Coffeescript
|
68
|
+
- Typescript
|
69
|
+
- React
|
70
|
+
|
76
71
|
## Installation
|
77
72
|
|
78
73
|
You can either add Webpacker during setup of a new Rails 5.1+ application
|
@@ -87,12 +82,11 @@ Or add it to your `Gemfile`:
|
|
87
82
|
|
88
83
|
```ruby
|
89
84
|
# Gemfile
|
90
|
-
gem 'webpacker', '~>
|
85
|
+
gem 'webpacker', '~> 6.x'
|
91
86
|
|
92
87
|
# OR if you prefer to use master
|
93
88
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
94
89
|
yarn add https://github.com/rails/webpacker.git
|
95
|
-
yarn add core-js regenerator-runtime
|
96
90
|
```
|
97
91
|
|
98
92
|
Finally, run the following to install Webpacker:
|
@@ -135,19 +129,11 @@ app/javascript:
|
|
135
129
|
└── logo.svg
|
136
130
|
```
|
137
131
|
|
138
|
-
|
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
|
+
You can then link the JavaScript pack in Rails views using the `javascript_packs_with_chunks_tag` helper. If you have styles imported in your pack file, you can link them by using `stylesheet_packs_with_chunks_tag`:
|
147
133
|
|
148
134
|
```erb
|
149
|
-
<%=
|
150
|
-
<%=
|
135
|
+
<%= javascript_packs_with_chunks_tag 'application' %>
|
136
|
+
<%= stylesheet_packs_with_chunks_tag 'application' %>
|
151
137
|
```
|
152
138
|
|
153
139
|
If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
|
@@ -158,31 +144,6 @@ can use the `asset_pack_path` helper:
|
|
158
144
|
<img src="<%= asset_pack_path 'images/logo.svg' %>" />
|
159
145
|
```
|
160
146
|
|
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.
|
163
|
-
|
164
|
-
```erb
|
165
|
-
<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
|
166
|
-
|
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>
|
172
|
-
```
|
173
|
-
|
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.
|
176
|
-
|
177
|
-
```erb
|
178
|
-
<%# DO %>
|
179
|
-
<%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
|
180
|
-
|
181
|
-
<%# DON'T %>
|
182
|
-
<%= javascript_packs_with_chunks_tag 'calendar' %>
|
183
|
-
<%= javascript_packs_with_chunks_tag 'map' %>
|
184
|
-
```
|
185
|
-
|
186
147
|
**Note:** In order for your styles or static assets files to be available in your view,
|
187
148
|
you would need to link them in your "pack" or entry file.
|
188
149
|
|
@@ -248,7 +209,201 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
248
209
|
|
249
210
|
### Webpack Configuration
|
250
211
|
|
251
|
-
|
212
|
+
Webpacker gives you a default set of configuration files for test, development and
|
213
|
+
production environments in `config/webpack/*.js`. You can configure each individual
|
214
|
+
environment in their respective files or configure them all in the base
|
215
|
+
`config/webpack/environment.js` file.
|
216
|
+
|
217
|
+
By default, you don't need to make any changes to `config/webpack/*.js`
|
218
|
+
files since it's all standard production-ready configuration. However,
|
219
|
+
if you do need to customize or add a new loader, this is where you would go.
|
220
|
+
|
221
|
+
Here is how you can modify webpack configuration:
|
222
|
+
|
223
|
+
You might add separate files to keep your code more organized.
|
224
|
+
|
225
|
+
```js
|
226
|
+
// config/webpack/custom.js
|
227
|
+
module.exports = {
|
228
|
+
resolve: {
|
229
|
+
alias: {
|
230
|
+
jquery: 'jquery/src/jquery',
|
231
|
+
vue: 'vue/dist/vue.js',
|
232
|
+
React: 'react',
|
233
|
+
ReactDOM: 'react-dom',
|
234
|
+
vue_resource: 'vue-resource/dist/vue-resource'
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
238
|
+
```
|
239
|
+
|
240
|
+
Then `require` this file in your `config/webpack/base.js`:
|
241
|
+
|
242
|
+
```js
|
243
|
+
// config/webpack/base.js
|
244
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
245
|
+
const customConfig = require('./custom')
|
246
|
+
|
247
|
+
module.exports = merge(webpackConfig, customConfig)
|
248
|
+
```
|
249
|
+
|
250
|
+
If you need access to configs within Webpacker's configuration,
|
251
|
+
you can import them like so:
|
252
|
+
|
253
|
+
```js
|
254
|
+
// config/webpack/base.js
|
255
|
+
const { webpackConfig } = require('@rails/webpacker')
|
256
|
+
|
257
|
+
console.log(webpackConfig.output_path)
|
258
|
+
console.log(webpackConfig.source_path)
|
259
|
+
```
|
260
|
+
|
261
|
+
### Integrations
|
262
|
+
|
263
|
+
Webpacker out of the box supports JS and static assets (fonts, images etc.)
|
264
|
+
compilation. To enable support for Coffeescript or Typescript install
|
265
|
+
relevant packages,
|
266
|
+
|
267
|
+
**Coffeescript**
|
268
|
+
|
269
|
+
```
|
270
|
+
yarn add coffeescript coffee-loader
|
271
|
+
```
|
272
|
+
|
273
|
+
**Typescript**
|
274
|
+
|
275
|
+
```
|
276
|
+
yarn add typescript @babel/preset-typescript
|
277
|
+
```
|
278
|
+
|
279
|
+
Add tsconfig.json
|
280
|
+
|
281
|
+
```json
|
282
|
+
{
|
283
|
+
"compilerOptions": {
|
284
|
+
"declaration": false,
|
285
|
+
"emitDecoratorMetadata": true,
|
286
|
+
"experimentalDecorators": true,
|
287
|
+
"lib": ["es6", "dom"],
|
288
|
+
"module": "es6",
|
289
|
+
"moduleResolution": "node",
|
290
|
+
"baseUrl": ".",
|
291
|
+
"paths": {
|
292
|
+
"*": ["node_modules/*", "app/javascript/*"]
|
293
|
+
},
|
294
|
+
"sourceMap": true,
|
295
|
+
"target": "es5",
|
296
|
+
"noEmit": true
|
297
|
+
},
|
298
|
+
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
299
|
+
"compileOnSave": false
|
300
|
+
}
|
301
|
+
```
|
302
|
+
|
303
|
+
#### CSS
|
304
|
+
|
305
|
+
To enable CSS support in your application, add following packages,
|
306
|
+
|
307
|
+
```
|
308
|
+
yarn add css-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
309
|
+
```
|
310
|
+
|
311
|
+
optionally, add css extension to webpack config for easy resolution
|
312
|
+
|
313
|
+
```js
|
314
|
+
// config/webpack/base.js
|
315
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
316
|
+
const customConfig = {
|
317
|
+
resolve: {
|
318
|
+
extensions: ['.css']
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
module.exports = merge(webpackConfig, customConfig)
|
323
|
+
```
|
324
|
+
|
325
|
+
To enable postcss, sass or less support, add css support first and
|
326
|
+
then add the relevant pre-processors:
|
327
|
+
|
328
|
+
#### Postcss
|
329
|
+
|
330
|
+
```
|
331
|
+
yarn add postcss-loader
|
332
|
+
```
|
333
|
+
|
334
|
+
#### Sass
|
335
|
+
|
336
|
+
```
|
337
|
+
yarn add sass-loader
|
338
|
+
```
|
339
|
+
|
340
|
+
#### Less
|
341
|
+
|
342
|
+
```
|
343
|
+
yarn add less-loader
|
344
|
+
```
|
345
|
+
|
346
|
+
#### React
|
347
|
+
|
348
|
+
React is supported and you just need to add relevant packages,
|
349
|
+
|
350
|
+
```
|
351
|
+
yarn add react react-dom @babel/preset-react
|
352
|
+
```
|
353
|
+
|
354
|
+
if you are using typescript, update your `tsconfig.json`
|
355
|
+
|
356
|
+
```json
|
357
|
+
{
|
358
|
+
"compilerOptions": {
|
359
|
+
"declaration": false,
|
360
|
+
"emitDecoratorMetadata": true,
|
361
|
+
"experimentalDecorators": true,
|
362
|
+
"lib": ["es6", "dom"],
|
363
|
+
"module": "es6",
|
364
|
+
"moduleResolution": "node",
|
365
|
+
"sourceMap": true,
|
366
|
+
"target": "es5",
|
367
|
+
"jsx": "react",
|
368
|
+
"noEmit": true
|
369
|
+
},
|
370
|
+
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
371
|
+
"compileOnSave": false
|
372
|
+
}
|
373
|
+
```
|
374
|
+
|
375
|
+
#### Other frameworks
|
376
|
+
|
377
|
+
Please follow webpack integration guide for relevant framework or library,
|
378
|
+
|
379
|
+
1. Svelte - https://github.com/sveltejs/svelte-loader#install
|
380
|
+
2. Angular - https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack
|
381
|
+
3. Vue - https://vue-loader.vuejs.org/guide/
|
382
|
+
|
383
|
+
For example to add Vue support,
|
384
|
+
|
385
|
+
```js
|
386
|
+
// config/webpack/rules/vue.js
|
387
|
+
const VueLoaderPlugin = require('vue-loader/lib/plugin')
|
388
|
+
|
389
|
+
module.exports = {
|
390
|
+
module: {
|
391
|
+
rules: [
|
392
|
+
{
|
393
|
+
test: /\.vue$/,
|
394
|
+
loader: 'vue-loader'
|
395
|
+
}
|
396
|
+
]
|
397
|
+
},
|
398
|
+
plugins: [new VueLoaderPlugin()]
|
399
|
+
}
|
400
|
+
|
401
|
+
// config/webpack/base.js
|
402
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
403
|
+
const vueConfig = require('./rules/vue')
|
404
|
+
|
405
|
+
module.exports = merge(webpackConfig, vueConfig)
|
406
|
+
```
|
252
407
|
|
253
408
|
### Custom Rails environments
|
254
409
|
|
@@ -305,7 +460,7 @@ You can run following commands to upgrade Webpacker to the latest stable version
|
|
305
460
|
|
306
461
|
```bash
|
307
462
|
bundle update webpacker
|
308
|
-
rails webpacker:
|
463
|
+
rails webpacker:install
|
309
464
|
yarn upgrade @rails/webpacker --latest
|
310
465
|
yarn upgrade webpack-dev-server --latest
|
311
466
|
|
@@ -313,24 +468,6 @@ yarn upgrade webpack-dev-server --latest
|
|
313
468
|
yarn add @rails/webpacker@next
|
314
469
|
```
|
315
470
|
|
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.
|
333
|
-
|
334
471
|
## Paths
|
335
472
|
|
336
473
|
By default, Webpacker ships with simple conventions for where the JavaScript
|
@@ -366,7 +503,7 @@ development:
|
|
366
503
|
|
367
504
|
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.
|
368
505
|
|
369
|
-
###
|
506
|
+
### Additional paths
|
370
507
|
|
371
508
|
If you are adding Webpacker to an existing app that has most of the assets inside
|
372
509
|
`app/assets` or inside an engine, and you want to share that
|
@@ -375,7 +512,7 @@ option available in `config/webpacker.yml`. This lets you
|
|
375
512
|
add additional paths that webpack should lookup when resolving modules:
|
376
513
|
|
377
514
|
```yml
|
378
|
-
additional_paths: ['app/assets']
|
515
|
+
additional_paths: ['app/assets/**/*', 'vendor/assets/**/*.css', 'Gemfile']
|
379
516
|
```
|
380
517
|
|
381
518
|
You can then import these items inside your modules like so:
|
@@ -396,26 +533,6 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
396
533
|
|
397
534
|
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.
|
398
535
|
|
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)
|
418
|
-
|
419
536
|
## Contributing
|
420
537
|
|
421
538
|
[![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)
|
data/gemfiles/Gemfile-rails-edge
CHANGED
@@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
4
4
|
|
5
5
|
gemspec path: "../"
|
6
6
|
|
7
|
-
gem "rails", github: "rails/rails"
|
7
|
+
gem "rails", github: "rails/rails"
|
8
8
|
gem "arel", github: "rails/arel"
|
9
9
|
gem "rake", ">= 11.1"
|
10
10
|
gem "rack-proxy", require: false
|
@@ -15,38 +15,6 @@ default: &default
|
|
15
15
|
# Reload manifest.json on all requests so we reload latest compiled packs
|
16
16
|
cache_manifest: false
|
17
17
|
|
18
|
-
# Extract and emit a css file
|
19
|
-
extract_css: false
|
20
|
-
|
21
|
-
static_assets_extensions:
|
22
|
-
- .jpg
|
23
|
-
- .jpeg
|
24
|
-
- .png
|
25
|
-
- .gif
|
26
|
-
- .tiff
|
27
|
-
- .ico
|
28
|
-
- .svg
|
29
|
-
- .eot
|
30
|
-
- .otf
|
31
|
-
- .ttf
|
32
|
-
- .woff
|
33
|
-
- .woff2
|
34
|
-
|
35
|
-
extensions:
|
36
|
-
- .mjs
|
37
|
-
- .js
|
38
|
-
- .sass
|
39
|
-
- .scss
|
40
|
-
- .css
|
41
|
-
- .module.sass
|
42
|
-
- .module.scss
|
43
|
-
- .module.css
|
44
|
-
- .png
|
45
|
-
- .svg
|
46
|
-
- .gif
|
47
|
-
- .jpeg
|
48
|
-
- .jpg
|
49
|
-
|
50
18
|
development:
|
51
19
|
<<: *default
|
52
20
|
compile: true
|
@@ -57,13 +25,20 @@ development:
|
|
57
25
|
host: localhost
|
58
26
|
port: 3035
|
59
27
|
public: localhost:3035
|
28
|
+
# Hot Module Replacement updates modules while the application is running without a full reload
|
60
29
|
hmr: false
|
61
|
-
# Inline should be set to true if using HMR
|
30
|
+
# Inline should be set to true if using HMR; it inserts a script to take care of live reloading
|
62
31
|
inline: true
|
32
|
+
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
|
63
33
|
overlay: true
|
34
|
+
# Should we use gzip compression?
|
64
35
|
compress: true
|
36
|
+
# Note that apps that do not check the host are vulnerable to DNS rebinding attacks
|
65
37
|
disable_host_check: true
|
38
|
+
# This option lets the browser open with your local IP
|
66
39
|
use_local_ip: false
|
40
|
+
# When enabled, nothing except the initial startup information will be written to the console.
|
41
|
+
# This also means that errors or warnings from webpack are not visible.
|
67
42
|
quiet: false
|
68
43
|
pretty: false
|
69
44
|
headers:
|
@@ -71,7 +46,6 @@ development:
|
|
71
46
|
watch_options:
|
72
47
|
ignored: '**/node_modules/**'
|
73
48
|
|
74
|
-
|
75
49
|
test:
|
76
50
|
<<: *default
|
77
51
|
compile: true
|
@@ -85,8 +59,5 @@ production:
|
|
85
59
|
# Production depends on precompilation of packs prior to booting for performance.
|
86
60
|
compile: false
|
87
61
|
|
88
|
-
# Extract and emit a css file
|
89
|
-
extract_css: true
|
90
|
-
|
91
62
|
# Cache manifest.json for performance
|
92
63
|
cache_manifest: true
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/*
|
2
|
+
Any CSS added to this file or imported from this file, e.g. `@import '../stylesheets/my-css.css'`,
|
3
|
+
will be included in the "application" pack. Any CSS imported from application.js or as part of the
|
4
|
+
application.js dependency graph, e.g. `import '../stylesheets/my-css.css'` will also be included
|
5
|
+
in the "application" pack.
|
6
|
+
|
7
|
+
To reference this file, add <%= stylesheet_pack_tag 'application' %> to the appropriate
|
8
|
+
layout file, like app/views/layouts/application.html.erb
|
9
|
+
*/
|
@@ -7,7 +7,6 @@
|
|
7
7
|
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
8
8
|
// layout file, like app/views/layouts/application.html.erb
|
9
9
|
|
10
|
-
|
11
10
|
// Uncomment to copy all static images under ../images to the output folder and reference
|
12
11
|
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
|
13
12
|
// or the `imagePath` JavaScript helper below.
|
@@ -15,4 +14,7 @@
|
|
15
14
|
// const images = require.context('../images', true)
|
16
15
|
// const imagePath = (name) => images(name, true)
|
17
16
|
|
17
|
+
import 'core-js/stable'
|
18
|
+
import 'regenerator-runtime/runtime'
|
19
|
+
|
18
20
|
console.log('Hello World from Webpacker')
|
data/lib/install/template.rb
CHANGED
@@ -4,16 +4,7 @@ copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
|
|
4
4
|
say "Copying webpack core config"
|
5
5
|
directory "#{__dir__}/config/webpack", "config/webpack"
|
6
6
|
|
7
|
-
|
8
|
-
copy_file "#{__dir__}/config/postcss.config.js", "postcss.config.js"
|
9
|
-
|
10
|
-
say "Copying babel.config.js to app root directory"
|
11
|
-
copy_file "#{__dir__}/config/babel.config.js", "babel.config.js"
|
12
|
-
|
13
|
-
say "Copying .browserslistrc to app root directory"
|
14
|
-
copy_file "#{__dir__}/config/.browserslistrc", ".browserslistrc"
|
15
|
-
|
16
|
-
if Dir.exist?(Webpacker.config.source_path)
|
7
|
+
if Dir.exists?(Webpacker.config.source_path)
|
17
8
|
say "The JavaScript app source directory already exists"
|
18
9
|
else
|
19
10
|
say "Creating JavaScript app source directory"
|
@@ -22,8 +13,9 @@ end
|
|
22
13
|
|
23
14
|
apply "#{__dir__}/binstubs.rb"
|
24
15
|
|
25
|
-
|
26
|
-
|
16
|
+
git_ignore_path = Rails.root.join(".gitignore")
|
17
|
+
if File.exists?(git_ignore_path)
|
18
|
+
append_to_file git_ignore_path do
|
27
19
|
"\n" +
|
28
20
|
"/public/packs\n" +
|
29
21
|
"/public/packs-test\n" +
|
@@ -34,24 +26,38 @@ if File.exist?(".gitignore")
|
|
34
26
|
end
|
35
27
|
end
|
36
28
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
29
|
+
Dir.chdir(Rails.root) do
|
30
|
+
if Webpacker::VERSION =~ /^[0-9]+\.[0-9]+\.[0-9]+$/
|
31
|
+
say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
|
32
|
+
run "yarn add @rails/webpacker@#{Webpacker::VERSION}"
|
33
|
+
else
|
34
|
+
say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
|
35
|
+
run "yarn add @rails/webpacker@next"
|
36
|
+
end
|
37
|
+
|
38
|
+
package_json = File.read("#{__dir__}/../../package.json")
|
39
|
+
webpack_version = package_json.match(/"webpack": "(.*)"/)[1]
|
40
|
+
webpack_cli_version = package_json.match(/"webpack-cli": "(.*)"/)[1]
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
# needed for experimental Yarn 2 support and should not harm Yarn 1
|
43
|
+
say "Installing webpack and webpack-cli as direct dependencies"
|
44
|
+
run "yarn add webpack@#{webpack_version} webpack-cli@#{webpack_cli_version}"
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
say "Installing dev server for live reloading"
|
47
|
+
run "yarn add --dev webpack-dev-server @webpack-cli/serve"
|
48
|
+
end
|
52
49
|
|
53
|
-
|
54
|
-
|
50
|
+
insert_into_file Rails.root.join("package.json").to_s, before: /\n}\n*$/ do
|
51
|
+
<<~JSON.chomp
|
52
|
+
,
|
53
|
+
"babel": {
|
54
|
+
"presets": ["./node_modules/@rails/webpacker/package/babel/preset.js"]
|
55
|
+
},
|
56
|
+
"browserslist": [
|
57
|
+
"defaults"
|
58
|
+
]
|
59
|
+
JSON
|
60
|
+
end
|
55
61
|
|
56
62
|
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
|
57
63
|
say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
|
@@ -1,13 +1,15 @@
|
|
1
1
|
binstubs_template_path = File.expand_path("../../install/binstubs.rb", __dir__).freeze
|
2
|
-
bin_path = ENV["BUNDLE_BIN"] || "
|
2
|
+
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
|
3
3
|
|
4
4
|
namespace :webpacker do
|
5
5
|
desc "Installs Webpacker binstubs in this application"
|
6
|
-
task binstubs: [:check_node, :check_yarn] do
|
6
|
+
task binstubs: [:check_node, :check_yarn] do |task|
|
7
|
+
prefix = task.name.split(/#|webpacker:binstubs/).first
|
8
|
+
|
7
9
|
if Rails::VERSION::MAJOR >= 5
|
8
|
-
exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{binstubs_template_path}"
|
10
|
+
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION=#{binstubs_template_path}"
|
9
11
|
else
|
10
|
-
exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION=#{binstubs_template_path}"
|
12
|
+
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION=#{binstubs_template_path}"
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
namespace :webpacker do
|
2
|
-
desc "Verifies that webpack
|
2
|
+
desc "Verifies that bin/webpack is present"
|
3
3
|
task :check_binstubs do
|
4
|
-
unless File.exist?("bin/webpack")
|
5
|
-
$stderr.puts "webpack
|
4
|
+
unless File.exist?(Rails.root.join("bin/webpack"))
|
5
|
+
$stderr.puts "webpack binstub not found.\n"\
|
6
6
|
"Have you run rails webpacker:install ?\n"\
|
7
|
-
"Make sure the bin directory
|
7
|
+
"Make sure the bin directory and bin/webpack are not included in .gitignore\n"\
|
8
8
|
"Exiting!"
|
9
9
|
exit!
|
10
10
|
end
|