webpacker 5.4.3 → 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 +12 -0
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +3 -108
- data/6_0_upgrade.md +43 -0
- data/CHANGELOG.md +19 -18
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +91 -94
- data/README.md +220 -99
- 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 +32 -26
- 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 +41 -87
- data/.travis.yml +0 -43
- data/docs/assets.md +0 -119
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -308
- data/docs/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
@@ -1,11 +1,15 @@
|
|
1
1
|
# Webpacker
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Ruby specs](https://github.com/rails/webpacker/workflows/Ruby%20specs/badge.svg)](https://github.com/rails/webpacker/actions)
|
4
|
+
[![Jest specs](https://github.com/rails/webpacker/workflows/Jest%20specs/badge.svg)](https://github.com/rails/webpacker/actions)
|
5
|
+
[![Rubocop](https://github.com/rails/webpacker/workflows/Rubocop/badge.svg)](https://github.com/rails/webpacker/actions)
|
6
|
+
[![JS lint](https://github.com/rails/webpacker/workflows/JS%20lint/badge.svg)](https://github.com/rails/webpacker/actions)
|
7
|
+
|
4
8
|
[![node.js](https://img.shields.io/badge/node-%3E%3D%2010.17.0-brightgreen.svg)](https://www.npmjs.com/package/@rails/webpacker)
|
5
9
|
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://rubygems.org/gems/webpacker)
|
6
10
|
|
7
11
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
8
|
-
[webpack
|
12
|
+
[webpack 5.x.x+](https://webpack.js.org/)
|
9
13
|
to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
|
10
14
|
as the primary purpose for webpack is app-like JavaScript, not images, CSS, or
|
11
15
|
even JavaScript Sprinkles (that all continues to live in app/assets).
|
@@ -13,7 +17,7 @@ even JavaScript Sprinkles (that all continues to live in app/assets).
|
|
13
17
|
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
|
14
18
|
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
|
15
19
|
|
16
|
-
**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.
|
17
21
|
|
18
22
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
19
23
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
@@ -28,16 +32,6 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
28
32
|
- [Webpack Configuration](#webpack-configuration)
|
29
33
|
- [Custom Rails environments](#custom-rails-environments)
|
30
34
|
- [Upgrading](#upgrading)
|
31
|
-
- [Integrations](#integrations)
|
32
|
-
- [React](./docs/integrations.md#react)
|
33
|
-
- [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
|
34
|
-
- [Vue](./docs/integrations.md#vue)
|
35
|
-
- [Elm](./docs/integrations.md#elm)
|
36
|
-
- [Stimulus](./docs/integrations.md#stimulus)
|
37
|
-
- [Svelte](./docs/integrations.md#svelte)
|
38
|
-
- [Typescript](./docs/typescript.md)
|
39
|
-
- [CoffeeScript](./docs/integrations.md#coffeescript)
|
40
|
-
- [Erb](./docs/integrations.md#erb)
|
41
35
|
- [Paths](#paths)
|
42
36
|
- [Resolved](#resolved)
|
43
37
|
- [Watched](#watched)
|
@@ -52,23 +46,28 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
52
46
|
|
53
47
|
- Ruby 2.4+
|
54
48
|
- Rails 5.2+
|
55
|
-
- Node.js 10.
|
49
|
+
- Node.js 10.22.1+ || 12+ || 14+
|
56
50
|
- Yarn 1.x+
|
57
51
|
|
58
52
|
## Features
|
59
53
|
|
60
|
-
- [webpack
|
54
|
+
- [webpack 5.x.x](https://webpack.js.org/)
|
61
55
|
- ES6 with [babel](https://babeljs.io/)
|
62
56
|
- Automatic code splitting using multiple entry points
|
63
|
-
- Stylesheets - Sass and CSS
|
64
|
-
- Images and fonts
|
65
|
-
- PostCSS - Auto-Prefixer
|
66
57
|
- Asset compression, source-maps, and minification
|
67
58
|
- CDN support
|
68
|
-
- React, Angular, Elm and Vue support out-of-the-box
|
69
59
|
- Rails view helpers
|
70
60
|
- Extensible and configurable
|
71
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
|
+
|
72
71
|
## Installation
|
73
72
|
|
74
73
|
You can either add Webpacker during setup of a new Rails 5.1+ application
|
@@ -83,12 +82,11 @@ Or add it to your `Gemfile`:
|
|
83
82
|
|
84
83
|
```ruby
|
85
84
|
# Gemfile
|
86
|
-
gem 'webpacker', '~>
|
85
|
+
gem 'webpacker', '~> 6.x'
|
87
86
|
|
88
87
|
# OR if you prefer to use master
|
89
88
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
90
89
|
yarn add https://github.com/rails/webpacker.git
|
91
|
-
yarn add core-js regenerator-runtime
|
92
90
|
```
|
93
91
|
|
94
92
|
Finally, run the following to install Webpacker:
|
@@ -131,19 +129,11 @@ app/javascript:
|
|
131
129
|
└── logo.svg
|
132
130
|
```
|
133
131
|
|
134
|
-
|
135
|
-
|
136
|
-
```js
|
137
|
-
import 'core-js/stable'
|
138
|
-
import 'regenerator-runtime/runtime'
|
139
|
-
```
|
140
|
-
|
141
|
-
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
|
142
|
-
If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
|
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`:
|
143
133
|
|
144
134
|
```erb
|
145
|
-
<%=
|
146
|
-
<%=
|
135
|
+
<%= javascript_packs_with_chunks_tag 'application' %>
|
136
|
+
<%= stylesheet_packs_with_chunks_tag 'application' %>
|
147
137
|
```
|
148
138
|
|
149
139
|
If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
|
@@ -154,31 +144,6 @@ can use the `asset_pack_path` helper:
|
|
154
144
|
<img src="<%= asset_pack_path 'images/logo.svg' %>" />
|
155
145
|
```
|
156
146
|
|
157
|
-
If you are using new webpack 4 split chunks API, then consider using `javascript_packs_with_chunks_tag` helper, which creates html
|
158
|
-
tags for a pack and all the dependent chunks.
|
159
|
-
|
160
|
-
```erb
|
161
|
-
<%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
|
162
|
-
|
163
|
-
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
164
|
-
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
165
|
-
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
166
|
-
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
167
|
-
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
168
|
-
```
|
169
|
-
|
170
|
-
**Important:** Pass all your pack names when using `javascript_packs_with_chunks_tag`
|
171
|
-
helper otherwise you will get duplicated chunks on the page.
|
172
|
-
|
173
|
-
```erb
|
174
|
-
<%# DO %>
|
175
|
-
<%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
|
176
|
-
|
177
|
-
<%# DON'T %>
|
178
|
-
<%= javascript_packs_with_chunks_tag 'calendar' %>
|
179
|
-
<%= javascript_packs_with_chunks_tag 'map' %>
|
180
|
-
```
|
181
|
-
|
182
147
|
**Note:** In order for your styles or static assets files to be available in your view,
|
183
148
|
you would need to link them in your "pack" or entry file.
|
184
149
|
|
@@ -244,7 +209,201 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
244
209
|
|
245
210
|
### Webpack Configuration
|
246
211
|
|
247
|
-
|
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
|
+
```
|
248
407
|
|
249
408
|
### Custom Rails environments
|
250
409
|
|
@@ -301,7 +460,7 @@ You can run following commands to upgrade Webpacker to the latest stable version
|
|
301
460
|
|
302
461
|
```bash
|
303
462
|
bundle update webpacker
|
304
|
-
rails webpacker:
|
463
|
+
rails webpacker:install
|
305
464
|
yarn upgrade @rails/webpacker --latest
|
306
465
|
yarn upgrade webpack-dev-server --latest
|
307
466
|
|
@@ -309,24 +468,6 @@ yarn upgrade webpack-dev-server --latest
|
|
309
468
|
yarn add @rails/webpacker@next
|
310
469
|
```
|
311
470
|
|
312
|
-
## Integrations
|
313
|
-
|
314
|
-
Webpacker ships with basic out-of-the-box integration. You can see a list of available commands/tasks by running `bundle exec rails webpacker`.
|
315
|
-
|
316
|
-
Included install integrations:
|
317
|
-
|
318
|
-
- [React](./docs/integrations.md#React)
|
319
|
-
- [Angular with TypeScript](./docs/integrations.md#Angular-with-TypeScript)
|
320
|
-
- [Vue](./docs/integrations.md#Vue)
|
321
|
-
- [Elm](./docs/integrations.md#Elm)
|
322
|
-
- [Svelte](./docs/integrations.md#Svelte)
|
323
|
-
- [Stimulus](./docs/integrations.md#Stimulus)
|
324
|
-
- [CoffeeScript](./docs/integrations.md#CoffeeScript)
|
325
|
-
- [Typescript](./docs/typescript.md)
|
326
|
-
- [Erb](./docs/integrations.md#Erb)
|
327
|
-
|
328
|
-
See [Integrations](./docs/integrations.md) for further details.
|
329
|
-
|
330
471
|
## Paths
|
331
472
|
|
332
473
|
By default, Webpacker ships with simple conventions for where the JavaScript
|
@@ -362,7 +503,7 @@ development:
|
|
362
503
|
|
363
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.
|
364
505
|
|
365
|
-
###
|
506
|
+
### Additional paths
|
366
507
|
|
367
508
|
If you are adding Webpacker to an existing app that has most of the assets inside
|
368
509
|
`app/assets` or inside an engine, and you want to share that
|
@@ -371,7 +512,7 @@ option available in `config/webpacker.yml`. This lets you
|
|
371
512
|
add additional paths that webpack should lookup when resolving modules:
|
372
513
|
|
373
514
|
```yml
|
374
|
-
additional_paths: ['app/assets']
|
515
|
+
additional_paths: ['app/assets/**/*', 'vendor/assets/**/*.css', 'Gemfile']
|
375
516
|
```
|
376
517
|
|
377
518
|
You can then import these items inside your modules like so:
|
@@ -392,26 +533,6 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
392
533
|
|
393
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.
|
394
535
|
|
395
|
-
## Docs
|
396
|
-
|
397
|
-
- [Development](https://github.com/rails/webpacker#development)
|
398
|
-
- [Webpack](./docs/webpack.md)
|
399
|
-
- [Webpack-dev-server](./docs/webpack-dev-server.md)
|
400
|
-
- [Environment Variables](./docs/env.md)
|
401
|
-
- [Folder Structure](./docs/folder-structure.md)
|
402
|
-
- [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
|
403
|
-
- [Props](./docs/props.md)
|
404
|
-
- [Typescript](./docs/typescript.md)
|
405
|
-
- [Yarn](./docs/yarn.md)
|
406
|
-
- [Misc](./docs/misc.md)
|
407
|
-
- [Deployment](./docs/deployment.md)
|
408
|
-
- [Docker](./docs/docker.md)
|
409
|
-
- [Using in Rails engines](./docs/engines.md)
|
410
|
-
- [Webpacker on Cloud9](./docs/cloud9.md)
|
411
|
-
- [Testing](./docs/testing.md)
|
412
|
-
- [Troubleshooting](./docs/troubleshooting.md)
|
413
|
-
- [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
|
414
|
-
|
415
536
|
## Contributing
|
416
537
|
|
417
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,15 +4,6 @@ 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
|
-
say "Copying postcss.config.js to app root directory"
|
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
7
|
if Dir.exists?(Webpacker.config.source_path)
|
17
8
|
say "The JavaScript app source directory already exists"
|
18
9
|
else
|
@@ -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.exists?(".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
|