webpacker 5.0.0 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +8 -8
- data/.github/workflows/jest.yml +38 -0
- data/.github/workflows/js-lint.yml +39 -0
- data/.github/workflows/rubocop.yml +39 -0
- data/.github/workflows/ruby.yml +70 -0
- data/.node-version +1 -1
- data/CHANGELOG.md +27 -2
- data/Gemfile.lock +76 -76
- data/README.md +47 -79
- data/docs/css.md +58 -3
- data/docs/env.md +0 -2
- data/docs/integrations.md +1 -1
- data/docs/target.md +22 -0
- data/docs/testing.md +2 -3
- data/docs/troubleshooting.md +3 -1
- data/docs/typescript.md +92 -27
- data/docs/webpack-dev-server.md +1 -1
- data/lib/install/config/babel.config.js +1 -3
- data/lib/install/config/webpacker.yml +1 -5
- data/lib/install/examples/react/tsconfig.json +2 -1
- data/lib/install/examples/typescript/tsconfig.json +2 -1
- data/lib/install/typescript.rb +5 -12
- data/lib/tasks/webpacker/check_node.rake +1 -1
- data/lib/tasks/webpacker/check_yarn.rake +1 -1
- data/lib/webpacker/compiler.rb +9 -5
- data/lib/webpacker/configuration.rb +13 -9
- data/lib/webpacker/dev_server_proxy.rb +3 -1
- data/lib/webpacker/dev_server_runner.rb +2 -2
- data/lib/webpacker/helper.rb +37 -18
- data/lib/webpacker/railtie.rb +0 -43
- data/lib/webpacker/runner.rb +1 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +2 -2
- data/package.json +35 -35
- data/package/__tests__/config.js +12 -1
- data/package/__tests__/dev_server.js +2 -0
- data/package/__tests__/development.js +14 -1
- data/package/config.js +4 -1
- data/package/configPath.js +3 -0
- data/package/dev_server.js +1 -1
- data/package/env.js +1 -2
- data/package/environments/__tests__/base.js +25 -8
- data/package/environments/base.js +5 -6
- data/package/environments/development.js +39 -33
- data/package/environments/production.js +1 -3
- data/package/rules/babel.js +12 -5
- data/package/rules/file.js +1 -0
- data/package/rules/node_modules.js +1 -3
- data/package/rules/sass.js +7 -2
- data/package/utils/helpers.js +1 -1
- data/test/compiler_test.rb +8 -3
- data/test/configuration_test.rb +8 -7
- data/test/dev_server_runner_test.rb +1 -1
- data/test/helper_test.rb +3 -0
- data/test/test_app/config/application.rb +0 -1
- data/test/test_app/config/webpacker.yml +7 -1
- data/test/test_app/public/packs/manifest.json +1 -0
- data/test/webpack_runner_test.rb +1 -1
- data/yarn.lock +3198 -3166
- metadata +10 -5
- data/lib/install/loaders/typescript.js +0 -11
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Webpacker
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/rails/webpacker.svg?branch=master)](https://travis-ci.org/rails/webpacker)
|
4
|
-
[![node.js](https://img.shields.io/badge/node-%3E%3D%2010.
|
4
|
+
[![node.js](https://img.shields.io/badge/node-%3E%3D%2010.17.0-brightgreen.svg)](https://www.npmjs.com/package/@rails/webpacker)
|
5
5
|
[![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://rubygems.org/gems/webpacker)
|
6
6
|
|
7
7
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
@@ -13,10 +13,11 @@ even JavaScript Sprinkles (that all continues to live in app/assets).
|
|
13
13
|
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
|
14
14
|
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
|
15
15
|
|
16
|
-
**NOTE:** The master branch now hosts the code for
|
16
|
+
**NOTE:** The master branch now hosts the code for v5.x.x. Please refer to [4-x-stable](https://github.com/rails/webpacker/tree/4-x-stable) branch for 4.x documentation.
|
17
17
|
|
18
18
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
19
19
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
20
|
+
|
20
21
|
## Table of Contents
|
21
22
|
|
22
23
|
- [Prerequisites](#prerequisites)
|
@@ -27,7 +28,6 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
27
28
|
- [Webpack Configuration](#webpack-configuration)
|
28
29
|
- [Custom Rails environments](#custom-rails-environments)
|
29
30
|
- [Upgrading](#upgrading)
|
30
|
-
- [Yarn Integrity](#yarn-integrity)
|
31
31
|
- [Integrations](#integrations)
|
32
32
|
- [React](./docs/integrations.md#react)
|
33
33
|
- [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
|
@@ -35,6 +35,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
35
35
|
- [Elm](./docs/integrations.md#elm)
|
36
36
|
- [Stimulus](./docs/integrations.md#stimulus)
|
37
37
|
- [Svelte](./docs/integrations.md#svelte)
|
38
|
+
- [Typescript](./docs/typescript.md)
|
38
39
|
- [CoffeeScript](./docs/integrations.md#coffeescript)
|
39
40
|
- [Erb](./docs/integrations.md#erb)
|
40
41
|
- [Paths](#paths)
|
@@ -47,29 +48,26 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
47
48
|
|
48
49
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
49
50
|
|
50
|
-
|
51
51
|
## Prerequisites
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
- Ruby 2.4+
|
54
|
+
- Rails 5.2+
|
55
|
+
- Node.js 10.17.0+
|
56
|
+
- Yarn 1.x+
|
58
57
|
|
59
58
|
## Features
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
60
|
+
- [webpack 4.x.x](https://webpack.js.org/)
|
61
|
+
- ES6 with [babel](https://babeljs.io/)
|
62
|
+
- Automatic code splitting using multiple entry points
|
63
|
+
- Stylesheets - Sass and CSS
|
64
|
+
- Images and fonts
|
65
|
+
- PostCSS - Auto-Prefixer
|
66
|
+
- Asset compression, source-maps, and minification
|
67
|
+
- CDN support
|
68
|
+
- React, Angular, Elm and Vue support out-of-the-box
|
69
|
+
- Rails view helpers
|
70
|
+
- Extensible and configurable
|
73
71
|
|
74
72
|
## Installation
|
75
73
|
|
@@ -85,7 +83,7 @@ Or add it to your `Gemfile`:
|
|
85
83
|
|
86
84
|
```ruby
|
87
85
|
# Gemfile
|
88
|
-
gem 'webpacker', '~>
|
86
|
+
gem 'webpacker', '~> 5.x'
|
89
87
|
|
90
88
|
# OR if you prefer to use master
|
91
89
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
@@ -109,6 +107,12 @@ Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/web
|
|
109
107
|
yarn upgrade
|
110
108
|
```
|
111
109
|
|
110
|
+
When `package.json` and/or `yarn.lock` changes, such as when pulling down changes to your local environment in a team settings, be sure to keep your NPM packages up-to-date:
|
111
|
+
|
112
|
+
```bash
|
113
|
+
yarn install
|
114
|
+
```
|
115
|
+
|
112
116
|
### Usage
|
113
117
|
|
114
118
|
Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
|
@@ -118,8 +122,11 @@ app/javascript:
|
|
118
122
|
├── packs:
|
119
123
|
│ # only webpack entry files here
|
120
124
|
│ └── application.js
|
121
|
-
└── src:
|
122
125
|
│ └── application.css
|
126
|
+
└── src:
|
127
|
+
│ └── my_component.js
|
128
|
+
└── stylesheets:
|
129
|
+
│ └── my_styles.css
|
123
130
|
└── images:
|
124
131
|
└── logo.svg
|
125
132
|
```
|
@@ -127,8 +134,8 @@ app/javascript:
|
|
127
134
|
In `/packs/application.js`, include this at the top of the file:
|
128
135
|
|
129
136
|
```js
|
130
|
-
import
|
131
|
-
import
|
137
|
+
import 'core-js/stable'
|
138
|
+
import 'regenerator-runtime/runtime'
|
132
139
|
```
|
133
140
|
|
134
141
|
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
|
@@ -175,7 +182,6 @@ helper otherwise you will get duplicated chunks on the page.
|
|
175
182
|
**Note:** In order for your styles or static assets files to be available in your view,
|
176
183
|
you would need to link them in your "pack" or entry file.
|
177
184
|
|
178
|
-
|
179
185
|
### Development
|
180
186
|
|
181
187
|
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
|
@@ -240,7 +246,6 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
240
246
|
|
241
247
|
See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
|
242
248
|
|
243
|
-
|
244
249
|
### Custom Rails environments
|
245
250
|
|
246
251
|
Out of the box Webpacker ships with - development, test and production environments in `config/webpacker.yml` however, in most production apps extra environments are needed as part of deployment workflow. Webpacker supports this out of the box from version 3.4.0+ onwards.
|
@@ -290,7 +295,6 @@ bundle exec rails assets:precompile
|
|
290
295
|
bundle exec rails webpacker:compile
|
291
296
|
```
|
292
297
|
|
293
|
-
|
294
298
|
### Upgrading
|
295
299
|
|
296
300
|
You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
|
@@ -305,41 +309,21 @@ yarn upgrade webpack-dev-server --latest
|
|
305
309
|
yarn add @rails/webpacker@next
|
306
310
|
```
|
307
311
|
|
308
|
-
### Yarn Integrity
|
309
|
-
|
310
|
-
By default, in development, webpacker runs a yarn integrity check to ensure that all local JavaScript packages are up-to-date. This is similar to what bundler does currently in Rails, but for JavaScript packages. If your system is out of date, then Rails will not initialize. You will be asked to upgrade your local JavaScript packages by running `yarn install`.
|
311
|
-
|
312
|
-
To turn off this option, you will need to change the default setting in `config/webpacker.yml`:
|
313
|
-
|
314
|
-
```yaml
|
315
|
-
# config/webpacker.yml
|
316
|
-
development:
|
317
|
-
...
|
318
|
-
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
|
319
|
-
check_yarn_integrity: false
|
320
|
-
```
|
321
|
-
|
322
|
-
You may also turn on this feature by adding the config option for any Rails environment in `config/webpacker.yml`:
|
323
|
-
|
324
|
-
```yaml
|
325
|
-
check_yarn_integrity: true
|
326
|
-
```
|
327
|
-
|
328
312
|
## Integrations
|
329
313
|
|
330
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`.
|
331
315
|
|
332
316
|
Included install integrations:
|
333
317
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
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)
|
343
327
|
|
344
328
|
See [Integrations](./docs/integrations.md) for further details.
|
345
329
|
|
@@ -378,17 +362,16 @@ development:
|
|
378
362
|
|
379
363
|
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output, as you will want to configure your styles to be inlined in your JavaScript for hot reloading. During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
|
380
364
|
|
381
|
-
|
382
365
|
### Resolved
|
383
366
|
|
384
367
|
If you are adding Webpacker to an existing app that has most of the assets inside
|
385
368
|
`app/assets` or inside an engine, and you want to share that
|
386
|
-
with webpack modules, you can use the `
|
369
|
+
with webpack modules, you can use the `additional_paths`
|
387
370
|
option available in `config/webpacker.yml`. This lets you
|
388
371
|
add additional paths that webpack should lookup when resolving modules:
|
389
372
|
|
390
373
|
```yml
|
391
|
-
|
374
|
+
additional_paths: ['app/assets']
|
392
375
|
```
|
393
376
|
|
394
377
|
You can then import these items inside your modules like so:
|
@@ -403,24 +386,11 @@ import 'images/rails.png'
|
|
403
386
|
will make the compilation slow, consider adding specific paths instead of
|
404
387
|
whole parent directory if you just need to reference one or two modules
|
405
388
|
|
406
|
-
|
407
|
-
### Watched
|
408
|
-
|
409
|
-
By default, the lazy compilation is cached until a file is changed under your
|
410
|
-
tracked paths. You can configure which paths are tracked
|
411
|
-
by adding new paths to `watched_paths` array. This is much like Rails' `autoload_paths`:
|
412
|
-
|
413
|
-
```rb
|
414
|
-
# config/initializers/webpacker.rb
|
415
|
-
# or config/application.rb
|
416
|
-
Webpacker::Compiler.watched_paths << 'bower_components'
|
417
|
-
```
|
418
|
-
|
419
|
-
|
420
389
|
## Deployment
|
421
390
|
|
422
391
|
Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets, `webpacker:compile` is automatically aliased to `assets:precompile`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/webpacker.yml` (if available).
|
423
392
|
|
393
|
+
When compiling assets for production on a remote server, such as a continuous integration environment, it's recommended to use `yarn install --frozen-lockfile` to install NPM packages on the remote host to ensure that the installed packages match the `yarn.lock` file.
|
424
394
|
|
425
395
|
## Docs
|
426
396
|
|
@@ -429,9 +399,7 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
429
399
|
- [Webpack-dev-server](./docs/webpack-dev-server.md)
|
430
400
|
- [Environment Variables](./docs/env.md)
|
431
401
|
- [Folder Structure](./docs/folder-structure.md)
|
432
|
-
- [Assets](./docs/assets.md)
|
433
|
-
- [CSS, Sass and SCSS](./docs/css.md)
|
434
|
-
- [ES6](./docs/es6.md)
|
402
|
+
- [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
|
435
403
|
- [Props](./docs/props.md)
|
436
404
|
- [Typescript](./docs/typescript.md)
|
437
405
|
- [Yarn](./docs/yarn.md)
|
@@ -444,12 +412,12 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
444
412
|
- [Troubleshooting](./docs/troubleshooting.md)
|
445
413
|
- [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
|
446
414
|
|
447
|
-
|
448
415
|
## Contributing
|
416
|
+
|
449
417
|
[![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)
|
450
418
|
|
451
419
|
We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
|
452
420
|
|
453
|
-
|
454
421
|
## License
|
422
|
+
|
455
423
|
Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
|
data/docs/css.md
CHANGED
@@ -6,7 +6,7 @@ Webpacker supports importing CSS, Sass and SCSS files directly into your JavaScr
|
|
6
6
|
Importing and loading styles is a two step process:
|
7
7
|
|
8
8
|
1. You need to tell webpack which file(s) it has to compile and know how to load
|
9
|
-
|
9
|
+
|
10
10
|
When you do `import '../scss/application.scss'`, you're telling webpack to include `application.scss` in the build. This does not mean it's going to be compiled into your javascript, only that webpack now compiles and knows how to load this file. (How that file compilation is handled is depending on how your loaders (`css-loader`, `sass-loader`, `file-loader`, etc.) are configured.)
|
11
11
|
|
12
12
|
2. You need to load those files in your views
|
@@ -18,6 +18,51 @@ Importing and loading styles is a two step process:
|
|
18
18
|
|
19
19
|
## Import global styles into your JS app
|
20
20
|
|
21
|
+
### Importing CSS as a multi-file pack (Webpacker v5)
|
22
|
+
|
23
|
+
When you add a CSS/SCSS/SASS file to `app/javascript/packs/` directory, make sure to use the same pack name as its complementary JavaScript pack, e.g. `application.js` and `application.css`. By Webpacker convention (as of Webpacker v5), this will bundle `application.js` and `application.scss` as part of the same entry point (also described as [a multi-file entry point in the webpack docs](https://webpack.js.org/concepts/entry-points/#single-entry-shorthand-syntax)). With this approach, you can avoid importing CSS from JS, if desired.
|
24
|
+
|
25
|
+
```
|
26
|
+
app/
|
27
|
+
javascript/
|
28
|
+
packs/
|
29
|
+
application.js
|
30
|
+
application.scss
|
31
|
+
```
|
32
|
+
|
33
|
+
### Importing CSS from CSS
|
34
|
+
|
35
|
+
You can import additional CSS/SCSS/SASS files from within a CSS file:
|
36
|
+
|
37
|
+
```
|
38
|
+
app/
|
39
|
+
javascript/
|
40
|
+
stylesheets/
|
41
|
+
application.scss
|
42
|
+
posts.scss
|
43
|
+
comments.scss
|
44
|
+
```
|
45
|
+
|
46
|
+
```css
|
47
|
+
/* app/javascript/stylesheets/application.scss */
|
48
|
+
|
49
|
+
@import './posts';
|
50
|
+
@import './comments';
|
51
|
+
```
|
52
|
+
|
53
|
+
### Importing CSS provided by an NPM package from SCSS/CSS
|
54
|
+
|
55
|
+
Given your application installs an NPM package that provides CSS, such as `flatpickr`, you can import the CSS file(s) by path from the package directory within `node_modules/`:
|
56
|
+
|
57
|
+
```js
|
58
|
+
/* app/javascript/stylesheets/application.scss */
|
59
|
+
|
60
|
+
@import "flatpickr/dist/flatpickr.css"
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
### Importing CSS from JS
|
65
|
+
|
21
66
|
```sass
|
22
67
|
// app/javascript/hello_react/styles/hello-react.sass
|
23
68
|
|
@@ -42,6 +87,16 @@ const Hello = props => (
|
|
42
87
|
)
|
43
88
|
```
|
44
89
|
|
90
|
+
### Importing CSS provided by an NPM package from JS
|
91
|
+
|
92
|
+
Given your application installs an NPM package that provides CSS, such as `flatpickr`, you can import the CSS file(s) by path from the package directory within `node_modules/`. This is an alternative to importing from within a CSS file, as above:
|
93
|
+
|
94
|
+
```js
|
95
|
+
// app/javascript/packs/application.js
|
96
|
+
|
97
|
+
import "flatpickr/dist/flatpickr.css"
|
98
|
+
```
|
99
|
+
|
45
100
|
## Import scoped styles into your JS app
|
46
101
|
|
47
102
|
Stylesheets that end with `.module.*` are treated as [CSS Modules](https://github.com/css-modules/css-modules).
|
@@ -147,14 +202,14 @@ You can use Yarn to add bootstrap or any other modules available on npm:
|
|
147
202
|
yarn add bootstrap
|
148
203
|
```
|
149
204
|
|
150
|
-
Import Bootstrap and theme (optional) CSS in your app/javascript/packs/
|
205
|
+
Import Bootstrap and theme (optional) CSS in your app/javascript/packs/application.js file:
|
151
206
|
|
152
207
|
```js
|
153
208
|
import 'bootstrap/dist/css/bootstrap'
|
154
209
|
import 'bootstrap/dist/css/bootstrap-theme'
|
155
210
|
```
|
156
211
|
|
157
|
-
Or in your app/javascript/
|
212
|
+
Or in your app/javascript/packs/application.sass file:
|
158
213
|
|
159
214
|
```sass
|
160
215
|
// ~ to tell that this is not a relative import
|
data/docs/env.md
CHANGED
@@ -49,8 +49,6 @@ dotenvFiles.forEach((dotenvFile) => {
|
|
49
49
|
dotenv.config({ path: dotenvFile, silent: true })
|
50
50
|
})
|
51
51
|
|
52
|
-
environment.plugins.prepend('Environment', new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(process.env))))
|
53
|
-
|
54
52
|
module.exports = environment
|
55
53
|
```
|
56
54
|
|
data/docs/integrations.md
CHANGED
@@ -91,7 +91,7 @@ You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/instal
|
|
91
91
|
|
92
92
|
### Lazy loading integration
|
93
93
|
|
94
|
-
See [docs/es6](
|
94
|
+
See [docs/es6](es6.md) to know more about Webpack and Webpacker configuration.
|
95
95
|
|
96
96
|
For instance, you can lazy load Vue JS components:
|
97
97
|
|
data/docs/target.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Target browsers
|
2
|
+
|
3
|
+
By default webpacker provides these front-end tools:
|
4
|
+
- [@babel/preset-env](https://github.com/babel/babel/tree/master/packages/babel-preset-env)
|
5
|
+
- [Autoprefixer](https://github.com/postcss/autoprefixer)
|
6
|
+
- [postcss-preset-env](https://github.com/csstools/postcss-preset-env)
|
7
|
+
|
8
|
+
All these tools use [Browserslist](https://github.com/browserslist/browserslist) to detect which environment your users have
|
9
|
+
|
10
|
+
Webpacker browserslist default target:
|
11
|
+
```
|
12
|
+
defaults
|
13
|
+
```
|
14
|
+
|
15
|
+
`defaults`: `(> 0.5%, last 2 versions, Firefox ESR, not dead)`, [browserl.ist](https://browserl.ist/) is an online tool to check what browsers will be selected by some query.
|
16
|
+
|
17
|
+
To keep browsers data up to date, you need to run:
|
18
|
+
```bash
|
19
|
+
yarn upgrade caniuse-lite
|
20
|
+
```
|
21
|
+
|
22
|
+
at least once every few months, to prevent such [problems](https://github.com/browserslist/browserslist/issues/492)
|
data/docs/testing.md
CHANGED
@@ -10,8 +10,7 @@ Webpacker does not setup `Karma` by default, so you've to manually install it al
|
|
10
10
|
"test": "NODE_ENV=test karma start"
|
11
11
|
},
|
12
12
|
"dependencies": {
|
13
|
-
"typescript": "^2.5.2"
|
14
|
-
"ts-loader": "^2.3.7"
|
13
|
+
"typescript": "^2.5.2"
|
15
14
|
},
|
16
15
|
"devDependencies": {
|
17
16
|
"karma": "^1.7.1",
|
@@ -33,7 +32,7 @@ It is beneficial to use the same webpack configuration file (generated by webpac
|
|
33
32
|
```js
|
34
33
|
// config/webpack/test.js
|
35
34
|
const environment = require('./environment')
|
36
|
-
environment.plugins.get('Manifest').
|
35
|
+
environment.plugins.get('Manifest').options.writeToFileEmit = process.env.NODE_ENV !== 'test'
|
37
36
|
environment.loaders.append('istanbul-instrumenter', {
|
38
37
|
test: /\.ts$/,
|
39
38
|
enforce: "post",
|
data/docs/troubleshooting.md
CHANGED
@@ -4,11 +4,13 @@
|
|
4
4
|
|
5
5
|
1. Read the error message carefully. The error message will tell you the precise key value
|
6
6
|
that is not matching what Webpack expects.
|
7
|
-
2. Put a `debugger` statement in your Webpack configuration and run `bin/webpack --debug`.
|
7
|
+
2. Put a `debugger` statement in your Webpack configuration and run `bin/webpack --debug-webpacker`.
|
8
8
|
If you have a node debugger installed, you'll see the Chrome debugger for your webpack
|
9
9
|
config. For example, install the Chrome extension [NiM](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj) and
|
10
10
|
set the option for the dev tools to open automatically. For more details on debugging,
|
11
11
|
see the official [Webpack docs on debugging](https://webpack.js.org/contribute/debugging/#devtools)
|
12
|
+
3. Any arguments that you add to bin/webpack get sent to webpack. For example, you can pass `--debug` to switch loaders to debug mode. See [webpack CLI debug options](https://webpack.js.org/api/cli/#debug-options) for more information on the available options.
|
13
|
+
4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-webpacker`
|
12
14
|
|
13
15
|
## ENOENT: no such file or directory - node-sass
|
14
16
|
|
data/docs/typescript.md
CHANGED
@@ -1,18 +1,98 @@
|
|
1
|
-
#
|
1
|
+
# TypeScript
|
2
2
|
|
3
|
+
## Installation
|
3
4
|
|
4
|
-
|
5
|
+
1. Run the TypeScript installer
|
5
6
|
|
6
|
-
|
7
|
+
```bash
|
8
|
+
bundle exec rails webpacker:install:typescript
|
9
|
+
```
|
10
|
+
|
11
|
+
After that, a new file called `hello_typescript.ts` will be present in your `packs` directory (or rather the `source_entry_path` of your `webpacker.yml` configuration). You're now ready to write TypeScript.
|
12
|
+
|
13
|
+
## (Optional) Adding Compile-Time Type Checking
|
14
|
+
|
15
|
+
The default installation only transpiles your TypeScript code using Babel. If you would like to enable type checking as part of the Webpack compilation process (i.e. fail the build if there are TS errors), you can do the following:
|
16
|
+
|
17
|
+
1. Install the Fork TS Checker Webpack Plugin
|
18
|
+
|
19
|
+
```sh
|
20
|
+
yarn add --dev fork-ts-checker-webpack-plugin
|
21
|
+
```
|
22
|
+
|
23
|
+
2. Then add it to your development environment config in `config/webpack/development.js`
|
24
|
+
|
25
|
+
```js
|
26
|
+
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
27
|
+
const path = require("path");
|
28
|
+
|
29
|
+
environment.plugins.append(
|
30
|
+
"ForkTsCheckerWebpackPlugin",
|
31
|
+
new ForkTsCheckerWebpackPlugin({
|
32
|
+
typescript: {
|
33
|
+
configFile: path.resolve(__dirname, "../../tsconfig.json"),
|
34
|
+
},
|
35
|
+
async: false,
|
36
|
+
})
|
37
|
+
);
|
38
|
+
```
|
39
|
+
|
40
|
+
If you are `fork-ts-checker-webpack-plugin` older than 5.0, the `tsconfig` option also needs to be specified:
|
41
|
+
|
42
|
+
```js
|
43
|
+
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
44
|
+
const path = require("path");
|
45
|
+
|
46
|
+
environment.plugins.append(
|
47
|
+
"ForkTsCheckerWebpackPlugin",
|
48
|
+
new ForkTsCheckerWebpackPlugin({
|
49
|
+
// this is a relative path to your project's TypeScript config
|
50
|
+
tsconfig: path.resolve(__dirname, "../../tsconfig.json"),
|
51
|
+
// non-async so type checking will block compilation
|
52
|
+
async: false,
|
53
|
+
})
|
54
|
+
);
|
55
|
+
```
|
56
|
+
|
57
|
+
## Upgrading to 5.1
|
58
|
+
|
59
|
+
If you update your App to `webpacker >= 5.1` and had TypeScript installed before, you need to add some new/remove some old configurations:
|
60
|
+
|
61
|
+
1. Remove old packages:
|
62
|
+
- `yarn remove ts-loader`
|
63
|
+
|
64
|
+
2. Add new packages:
|
65
|
+
- `yarn add @babel/preset-typescript`
|
66
|
+
|
67
|
+
3. Remove old configuration files:
|
68
|
+
- Delete this file: `config/webpack/loaders/typescript.js`
|
69
|
+
|
70
|
+
4. Remove the following lines from `config/webpack/environment.js`:
|
71
|
+
- `const typescript = require('./loaders/typescript')`
|
72
|
+
- `environment.loaders.prepend('typescript', typescript)`
|
73
|
+
|
74
|
+
5. Add the TypeScript preset to your `babel.config.js`:
|
75
|
+
- This line `['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]` has to be added as the last item to the `presets` array in your `babel.config.js`
|
76
|
+
|
77
|
+
### Upgrading to 5.1 for Vue users
|
78
|
+
|
79
|
+
1. Remove old packages:
|
80
|
+
- `yarn remove ts-loader pnp-webpack-plugin`
|
81
|
+
|
82
|
+
2. Follow point 3 and 4 from the `TypeScript with Vue components` section
|
83
|
+
|
84
|
+
## TypeScript with React
|
85
|
+
|
86
|
+
1. Setup react using Webpacker [react installer](../README.md#react). Then run the TypeScript installer
|
7
87
|
|
8
88
|
```bash
|
9
89
|
bundle exec rails webpacker:install:typescript
|
10
90
|
```
|
11
91
|
|
12
|
-
2. Rename the generated `hello_react.js` to `hello_react.tsx`. Make the file valid
|
13
|
-
now you can use
|
92
|
+
2. Rename the generated `hello_react.js` to `hello_react.tsx`. Make the file valid TypeScript and
|
93
|
+
now you can use TypeScript, JSX with React.
|
14
94
|
|
15
|
-
##
|
95
|
+
## TypeScript with Vue components
|
16
96
|
|
17
97
|
1. Setup Vue using the Webpacker [Vue installer](../README.md#vue). Then run the TypeScript installer
|
18
98
|
|
@@ -21,37 +101,22 @@ bundle exec rails webpacker:install:typescript
|
|
21
101
|
```
|
22
102
|
|
23
103
|
2. Rename generated `hello_vue.js` to `hello_vue.ts`.
|
24
|
-
3.
|
25
|
-
4. Change the generated `config
|
104
|
+
3. Install the right Babel preset: `yarn add babel-preset-typescript-vue`
|
105
|
+
4. Change the generated `babel.config.js` from
|
26
106
|
|
27
107
|
```js
|
28
|
-
|
29
|
-
test: /\.tsx?(\.erb)?$/,
|
30
|
-
use: [{
|
31
|
-
loader: 'ts-loader'
|
32
|
-
}]
|
33
|
-
}
|
108
|
+
["@babel/preset-typescript", { "allExtensions": true, "isTSX": true }]
|
34
109
|
```
|
35
110
|
|
36
111
|
to
|
37
112
|
|
38
113
|
```js
|
39
|
-
|
40
|
-
|
41
|
-
module.exports = {
|
42
|
-
test: /\.tsx?(\.erb)?$/,
|
43
|
-
use: [{
|
44
|
-
loader: 'ts-loader',
|
45
|
-
options: PnpWebpackPlugin.tsLoaderOptions({
|
46
|
-
appendTsSuffixTo: [/\.vue$/]
|
47
|
-
})
|
48
|
-
}]
|
49
|
-
}
|
114
|
+
["babel-preset-typescript-vue", { "allExtensions": true, "isTSX": true }]
|
50
115
|
```
|
51
116
|
|
52
|
-
and now you can use `<script lang="ts">` in your `.vue` component files. See [the
|
117
|
+
and now you can use `<script lang="ts">` in your `.vue` component files. See [the babel-preset-typescript-vue docs](https://www.npmjs.com/package/babel-preset-typescript-vue) for more info.
|
53
118
|
|
54
|
-
## HTML templates with
|
119
|
+
## HTML templates with TypeScript and Angular
|
55
120
|
|
56
121
|
After you have installed Angular using `bundle exec rails webpacker:install:angular`
|
57
122
|
you would need to follow these steps to add HTML templates support:
|