webpacker 5.1.0 → 6.0.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +38 -0
  4. data/.github/workflows/js-lint.yml +39 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +70 -0
  7. data/.gitignore +2 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +11 -16
  10. data/CHANGELOG.md +26 -0
  11. data/CONTRIBUTING.md +1 -1
  12. data/Gemfile.lock +91 -85
  13. data/README.md +18 -22
  14. data/docs/assets.md +21 -5
  15. data/docs/css.md +80 -30
  16. data/docs/deployment.md +18 -0
  17. data/docs/docker.md +2 -2
  18. data/docs/engines.md +1 -1
  19. data/docs/env.md +5 -0
  20. data/docs/es6.md +1 -1
  21. data/docs/integrations.md +2 -2
  22. data/docs/props.md +2 -38
  23. data/docs/react.md +183 -0
  24. data/docs/target.md +22 -0
  25. data/docs/testing.md +12 -1
  26. data/docs/troubleshooting.md +3 -1
  27. data/docs/typescript.md +89 -8
  28. data/docs/webpack-dev-server.md +17 -15
  29. data/docs/webpack.md +58 -107
  30. data/lib/install/config/webpack/base.js +3 -0
  31. data/lib/install/config/webpack/development.js +2 -2
  32. data/lib/install/config/webpack/production.js +2 -2
  33. data/lib/install/config/webpack/test.js +2 -2
  34. data/lib/install/config/webpacker.yml +9 -38
  35. data/lib/install/examples/{vue → vue3}/app.vue +10 -5
  36. data/lib/install/examples/vue3/hello_vue.js +15 -0
  37. data/lib/install/javascript/packs/application.css +9 -0
  38. data/lib/install/template.rb +33 -19
  39. data/lib/tasks/webpacker.rake +2 -11
  40. data/lib/tasks/webpacker/binstubs.rake +6 -4
  41. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  42. data/lib/tasks/webpacker/check_node.rake +1 -1
  43. data/lib/tasks/webpacker/check_yarn.rake +2 -3
  44. data/lib/tasks/webpacker/compile.rake +4 -2
  45. data/lib/tasks/webpacker/info.rake +12 -10
  46. data/lib/tasks/webpacker/install.rake +6 -4
  47. data/lib/tasks/webpacker/verify_install.rake +2 -1
  48. data/lib/tasks/webpacker/yarn_install.rake +9 -1
  49. data/lib/webpacker/commands.rb +1 -1
  50. data/lib/webpacker/compiler.rb +12 -6
  51. data/lib/webpacker/configuration.rb +7 -23
  52. data/lib/webpacker/dev_server_runner.rb +23 -4
  53. data/lib/webpacker/helper.rb +51 -42
  54. data/lib/webpacker/manifest.rb +1 -1
  55. data/lib/webpacker/runner.rb +1 -0
  56. data/lib/webpacker/version.rb +1 -1
  57. data/lib/webpacker/webpack_runner.rb +7 -2
  58. data/package.json +27 -43
  59. data/package/__tests__/config.js +6 -27
  60. data/package/__tests__/development.js +18 -7
  61. data/package/__tests__/env.js +12 -4
  62. data/package/__tests__/production.js +6 -6
  63. data/package/__tests__/staging.js +7 -6
  64. data/package/__tests__/test.js +4 -5
  65. data/package/babel/preset-react.js +62 -0
  66. data/package/babel/preset.js +44 -0
  67. data/package/config.js +4 -9
  68. data/package/configPath.js +3 -0
  69. data/package/env.js +9 -4
  70. data/package/environments/__tests__/base.js +21 -36
  71. data/package/environments/base.js +67 -128
  72. data/package/environments/development.js +46 -39
  73. data/package/environments/production.js +69 -67
  74. data/package/environments/test.js +2 -2
  75. data/package/index.js +6 -6
  76. data/package/rules/babel.js +19 -10
  77. data/package/rules/coffee.js +6 -0
  78. data/package/rules/erb.js +13 -0
  79. data/package/rules/file.js +19 -18
  80. data/package/rules/index.js +24 -18
  81. data/package/rules/less.js +18 -0
  82. data/package/rules/sass.js +6 -7
  83. data/package/rules/svg.js +23 -0
  84. data/package/utils/get_style_rule.js +22 -28
  85. data/package/utils/helpers.js +3 -35
  86. data/test/compiler_test.rb +4 -11
  87. data/test/configuration_test.rb +2 -32
  88. data/test/dev_server_runner_test.rb +25 -6
  89. data/test/engine_rake_tasks_test.rb +39 -0
  90. data/test/helper_test.rb +18 -9
  91. data/test/mounted_app/Rakefile +4 -0
  92. data/test/mounted_app/test/dummy/Rakefile +3 -0
  93. data/test/mounted_app/test/dummy/bin/rails +3 -0
  94. data/test/mounted_app/test/dummy/bin/rake +3 -0
  95. data/test/mounted_app/test/dummy/config.ru +5 -0
  96. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  97. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  98. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  99. data/test/mounted_app/test/dummy/package.json +7 -0
  100. data/test/rake_tasks_test.rb +1 -10
  101. data/test/test_app/config/webpacker.yml +3 -21
  102. data/test/test_app/config/webpacker_public_root.yml +0 -1
  103. data/test/test_app/public/packs/manifest.json +18 -13
  104. data/test/test_app/some.config.js +0 -0
  105. data/test/webpack_runner_test.rb +10 -4
  106. data/webpacker.gemspec +1 -1
  107. data/yarn.lock +2657 -6224
  108. metadata +53 -70
  109. data/.travis.yml +0 -43
  110. data/lib/install/angular.rb +0 -23
  111. data/lib/install/coffee.rb +0 -25
  112. data/lib/install/config/.browserslistrc +0 -1
  113. data/lib/install/config/babel.config.js +0 -72
  114. data/lib/install/config/postcss.config.js +0 -12
  115. data/lib/install/config/webpack/environment.js +0 -3
  116. data/lib/install/elm.rb +0 -39
  117. data/lib/install/erb.rb +0 -25
  118. data/lib/install/examples/angular/hello_angular.js +0 -7
  119. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  120. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  121. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  122. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  123. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  124. data/lib/install/examples/elm/Main.elm +0 -55
  125. data/lib/install/examples/elm/hello_elm.js +0 -16
  126. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  127. data/lib/install/examples/react/babel.config.js +0 -87
  128. data/lib/install/examples/react/hello_react.jsx +0 -26
  129. data/lib/install/examples/react/tsconfig.json +0 -21
  130. data/lib/install/examples/stimulus/application.js +0 -1
  131. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  132. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  133. data/lib/install/examples/svelte/app.svelte +0 -11
  134. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  135. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  136. data/lib/install/examples/typescript/tsconfig.json +0 -24
  137. data/lib/install/examples/vue/hello_vue.js +0 -72
  138. data/lib/install/loaders/coffee.js +0 -6
  139. data/lib/install/loaders/elm.js +0 -25
  140. data/lib/install/loaders/erb.js +0 -11
  141. data/lib/install/loaders/svelte.js +0 -9
  142. data/lib/install/loaders/vue.js +0 -6
  143. data/lib/install/react.rb +0 -18
  144. data/lib/install/stimulus.rb +0 -12
  145. data/lib/install/svelte.rb +0 -29
  146. data/lib/install/typescript.rb +0 -42
  147. data/lib/install/vue.rb +0 -49
  148. data/lib/tasks/installers.rake +0 -42
  149. data/package/config_types/__tests__/config_list.js +0 -118
  150. data/package/config_types/__tests__/config_object.js +0 -43
  151. data/package/config_types/config_list.js +0 -75
  152. data/package/config_types/config_object.js +0 -55
  153. data/package/config_types/index.js +0 -7
  154. data/package/rules/module.css.js +0 -3
  155. data/package/rules/module.sass.js +0 -8
  156. data/package/rules/node_modules.js +0 -24
  157. data/package/utils/__tests__/deep_assign.js +0 -32
  158. data/package/utils/__tests__/deep_merge.js +0 -10
  159. data/package/utils/__tests__/get_style_rule.js +0 -65
  160. data/package/utils/__tests__/objectify.js +0 -9
  161. data/package/utils/deep_assign.js +0 -22
  162. data/package/utils/deep_merge.js +0 -22
  163. data/package/utils/objectify.js +0 -3
@@ -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](docs/es6.md) to know more about Webpack and Webpacker configuration.
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
 
@@ -213,7 +213,7 @@ in `app/javascript/packs` so that you can experiment with CoffeeScript right awa
213
213
 
214
214
  To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates,
215
215
  run `bundle exec rails webpacker:install:erb` on a Rails app already
216
- setup with Webpacker.
216
+ setup with Webpacker and add extension 'erb' on file `config/webpacker.yml`.
217
217
 
218
218
  An example `hello_erb.js.erb` file will also be added to your project
219
219
  in `app/javascript/packs` so that you can experiment with Erb-flavoured
@@ -1,45 +1,9 @@
1
1
  # Props
2
2
 
3
+ How do you pass props from your view to your JavaScript component? Here you go.
3
4
 
4
5
  ## React
5
-
6
- If you need more advanced React-integration, like server rendering, redux, or react-router, see [shakacode/react_on_rails](https://github.com/shakacode/react_on_rails), [react-rails](https://github.com/reactjs/react-rails), and [webpacker-react](https://github.com/renchap/webpacker-react).
7
-
8
- If you're not concerned with view helpers to pass props or server rendering, can do it yourself:
9
-
10
- ```erb
11
- <%# views/layouts/application.html.erb %>
12
-
13
- <%= content_tag :div,
14
- id: "hello-react",
15
- data: {
16
- message: 'Hello!',
17
- name: 'David'
18
- }.to_json do %>
19
- <% end %>
20
- ```
21
-
22
- ```js
23
- // app/javascript/packs/hello_react.js
24
-
25
- const Hello = props => (
26
- <div className='react-app-wrapper'>
27
- <img src={clockIcon} alt="clock" />
28
- <h5 className='hello-react'>
29
- {props.message} {props.name}!
30
- </h5>
31
- </div>
32
- )
33
-
34
- // Render component with data
35
- document.addEventListener('DOMContentLoaded', () => {
36
- const node = document.getElementById('hello-react')
37
- const data = JSON.parse(node.getAttribute('data'))
38
-
39
- ReactDOM.render(<Hello {...data} />, node)
40
- })
41
- ```
42
-
6
+ See [docs/react.md](./react.md#props-hydration-and-server-side-rendering-ssr).
43
7
 
44
8
  ## Vue
45
9
 
@@ -0,0 +1,183 @@
1
+ # React
2
+
3
+ ## Props Hydration and Server-Side Rendering (SSR)
4
+ You only _need_ props hydration if you need SSR. However, there's no good reason to
5
+ have your app make a second round trip to the Rails server to get initialization props.
6
+
7
+ Server-Side Rendering (SSR) results in Rails rendering HTML for your React components.
8
+ The main reasons to use SSR are better SEO and pages display more quickly.
9
+
10
+ ### Rails and React Integration Gems
11
+ If you desire more advanced React-integration, like server-side rendering, SSR with react-router, SSR with code splitting, then you should consider these gems:
12
+
13
+ | Gem | Props Hydration | Server-Side-Rendering (SSR) | SSR with HMR | SSR with React-Router | SSR with Code Splitting | Node SSR |
14
+ | --- | --------------- | --- | --------------------- | ----------------------| ------------------------|----|
15
+ | [shakacode/react_on_rails](https://github.com/shakacode/react_on_rails) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
16
+ | [react-rails](https://github.com/reactjs/react-rails) | ✅ | ✅ | | | | | |
17
+ | [webpacker-react](https://github.com/renchap/webpacker-react) | ✅ | | | | | | |
18
+
19
+ Note, Node SSR for React on Rails requires [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
20
+
21
+ ### Hydration of Props the Manual Way
22
+
23
+ If you're not concerned with view helpers to pass props or server-side rendering, you can do it like this:
24
+
25
+ ```erb
26
+ <%# views/layouts/application.html.erb %>
27
+
28
+ <%= content_tag :div,
29
+ id: "hello-react",
30
+ data: {
31
+ message: 'Hello!',
32
+ name: 'David'
33
+ }.to_json do %>
34
+ <% end %>
35
+ ```
36
+
37
+ ```js
38
+ // app/javascript/packs/hello_react.js
39
+
40
+ const Hello = props => (
41
+ <div className='react-app-wrapper'>
42
+ <img src={clockIcon} alt="clock" />
43
+ <h5 className='hello-react'>
44
+ {props.message} {props.name}!
45
+ </h5>
46
+ </div>
47
+ )
48
+
49
+ // Render component with data
50
+ document.addEventListener('DOMContentLoaded', () => {
51
+ const node = document.getElementById('hello-react')
52
+ const data = JSON.parse(node.getAttribute('data'))
53
+
54
+ ReactDOM.render(<Hello {...data} />, node)
55
+ })
56
+ ```
57
+
58
+ ----
59
+
60
+ ## HMR and React Hot Reloading
61
+
62
+ Before turning HMR on, consider upgrading to the latest stable gems and packages:
63
+ https://github.com/rails/webpacker#upgrading
64
+
65
+ Configure `config/webpacker.yml` file:
66
+
67
+ ```yaml
68
+ development:
69
+ extract_css: false
70
+ dev_server:
71
+ hmr: true
72
+ inline: true
73
+ ```
74
+
75
+ This basic configuration alone will have HMR working with the default webpacker setup. However, an code saves will trigger a full page refresh each time you save a file.
76
+
77
+ Webpack's HMR allows the replacement of modules for React in-place without reloading the browser. To do this, you have two options:
78
+
79
+ 1. Steps below for the [github.com/pmmmwh/react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin).
80
+ 1. Deprecated steps below for using the [github.com/gaearon/react-hot-loader](https://github.com/gaearon/react-hot-loader).
81
+
82
+ ### React Refresh Webpack Plugin
83
+ [github.com/pmmmwh/react-refresh-webpack-plugin](https://github.com/pmmmwh/react-refresh-webpack-plugin)
84
+
85
+ You can see an example commit of adding this [here](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/commit/7e53803fce7034f5ecff335db1f400a5743a87e7).
86
+
87
+ 1. Add react refresh packages:
88
+ `yarn add @pmmmwh/react-refresh-webpack-plugin react-refresh -D`
89
+ 2. Update `babel.config.js` adding
90
+ ```js
91
+ plugins: [
92
+ process.env.WEBPACK_DEV_SERVER && 'react-refresh/babel',
93
+ // other plugins
94
+ ```
95
+ 3. Update `config/webpack/development.js`, only including the plugin if running the WEBPACK_DEV_SERVER
96
+ ```js
97
+ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
98
+ const environment = require('./environment')
99
+
100
+ const isWebpackDevServer = process.env.WEBPACK_DEV_SERVER;
101
+
102
+ //plugins
103
+ if (isWebpackDevServer) {
104
+ environment.plugins.append(
105
+ 'ReactRefreshWebpackPlugin',
106
+ new ReactRefreshWebpackPlugin({
107
+ overlay: {
108
+ sockPort: 3035
109
+ }
110
+ })
111
+ );
112
+ }
113
+ ```
114
+
115
+ ### React Hot Loader (Deprecated)
116
+
117
+ 1. Add the `react-hot-loader` and ` @hot-loader/react-dom` npm packages.
118
+ ```sh
119
+ yarn add --dev react-hot-loader @hot-loader/react-dom
120
+ ```
121
+
122
+ 2. Update your babel config, `babel.config.js`. Add the plugin `react-hot-loader/babel`
123
+ with option `"safetyNet": false`:
124
+
125
+ ```
126
+ {
127
+ "plugins": [
128
+ [
129
+ "react-hot-loader/babel",
130
+ {
131
+ "safetyNet": false
132
+ }
133
+ ]
134
+ ]
135
+ }
136
+ ```
137
+
138
+ 3. Add changes like this to your entry points:
139
+
140
+ ```diff
141
+ // app/javascript/app.jsx
142
+
143
+ import React from 'react';
144
+ + import { hot } from 'react-hot-loader/root';
145
+
146
+ const App = () => <SomeComponent(s) />
147
+
148
+ - export default App;
149
+ + export default hot(App);
150
+ ```
151
+
152
+ 4. Adjust your webpack configuration for development so that `sourceMapContents` option for the sass
153
+ loader is `false`:
154
+
155
+ ```diff
156
+ // config/webpack/development.js
157
+
158
+ process.env.NODE_ENV = process.env.NODE_ENV || 'development'
159
+
160
+ const environment = require('./environment')
161
+
162
+ // allows for editing sass/scss files directly in browser
163
+ + if (!module.hot) {
164
+ + environment.loaders.get('sass').use.find(item => item.loader === 'sass-loader').options.sourceMapContents = false
165
+ + }
166
+ +
167
+ module.exports = environment.toWebpackConfig()
168
+ ```
169
+
170
+ 5. Adjust your `config/webpack/environment.js` for a
171
+
172
+ ```diff
173
+ // config/webpack/environment.js
174
+
175
+ // ...
176
+
177
+ // Fixes: React-Hot-Loader: react-🔥-dom patch is not detected. React 16.6+ features may not work.
178
+ // https://github.com/gaearon/react-hot-loader/issues/1227#issuecomment-482139583
179
+ + environment.config.merge({ resolve: { alias: { 'react-dom': '@hot-loader/react-dom' } } });
180
+
181
+ module.exports = environment;
182
+ ```
183
+
@@ -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)
@@ -32,7 +32,7 @@ It is beneficial to use the same webpack configuration file (generated by webpac
32
32
  ```js
33
33
  // config/webpack/test.js
34
34
  const environment = require('./environment')
35
- environment.plugins.get('Manifest').opts.writeToFileEmit = process.env.NODE_ENV !== 'test'
35
+ environment.plugins.get('Manifest').options.writeToFileEmit = process.env.NODE_ENV !== 'test'
36
36
  environment.loaders.append('istanbul-instrumenter', {
37
37
  test: /\.ts$/,
38
38
  enforce: "post",
@@ -134,3 +134,14 @@ Make sure you configure Rails to serve static files from the public directory in
134
134
  # Configure public file server for tests with Cache-Control for performance.
135
135
  config.public_file_server.enabled = true
136
136
  ```
137
+
138
+ ## Webpacker Configuration and Rails Tests
139
+
140
+ Webpacker ships with three javascript configuration files: `test.js`,
141
+ `development.js`, and `production.js`. The `NODE_ENV` environment
142
+ variable determines which config will be used. `NODE_ENV` is
143
+ independent of `RAILS_ENV` and is set to `development` by [default](/lib/install/bin/webpack#L4).
144
+ This means that `rails test` or `rspec` will use `development.js`
145
+ by default, _not_ `test.js`.
146
+
147
+ For more information see [Why doesn't Webpacker use my test config when I run Rails tests?](https://rossta.net/blog/why-doesnt-webpacker-use-my-test-config-when-i-run-rails-tests.html)
@@ -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
 
@@ -1,18 +1,98 @@
1
- # Typescript
1
+ # TypeScript
2
2
 
3
+ ## Installation
3
4
 
4
- ## Typescript with React
5
+ 1. Run the TypeScript installer
5
6
 
6
- 1. Setup react using Webpacker [react installer](../README.md#react). Then run the typescript installer
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 using `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](integrations.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 typescript and
13
- now you can use typescript, JSX with React.
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
- ## Typescript with Vue components
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,7 +101,8 @@ bundle exec rails webpacker:install:typescript
21
101
  ```
22
102
 
23
103
  2. Rename generated `hello_vue.js` to `hello_vue.ts`.
24
- 3. Change the generated `babel.config.js` from
104
+ 3. Install the right Babel preset: `yarn add babel-preset-typescript-vue`
105
+ 4. Change the generated `babel.config.js` from
25
106
 
26
107
  ```js
27
108
  ["@babel/preset-typescript", { "allExtensions": true, "isTSX": true }]
@@ -35,7 +116,7 @@ to
35
116
 
36
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.
37
118
 
38
- ## HTML templates with Typescript and Angular
119
+ ## HTML templates with TypeScript and Angular
39
120
 
40
121
  After you have installed Angular using `bundle exec rails webpacker:install:angular`
41
122
  you would need to follow these steps to add HTML templates support:
@@ -1,6 +1,5 @@
1
1
  # webpack-dev-server
2
2
 
3
-
4
3
  ## HTTPS
5
4
 
6
5
  If you're using the `webpack-dev-server` in development, you can serve your packs over HTTPS
@@ -13,24 +12,28 @@ so your web browser will display a warning/exception upon accessing the page. If
13
12
  in your console, simply open the link in your browser and accept the SSL exception.
14
13
  Now if you refresh your Rails view everything should work as expected.
15
14
 
16
-
17
- ## HOT module replacement
15
+ ## Hot Module Replacement
18
16
 
19
17
  Webpacker out-of-the-box supports HMR with `webpack-dev-server` and
20
- you can toggle it by setting `dev_server/hmr` option inside `webpacker.yml`.
21
-
22
- Checkout this guide for more information:
18
+ you can toggle it by setting options in `config/webpacker.yml`:
23
19
 
24
- - https://webpack.js.org/configuration/dev-server/#devserver-hot
20
+ ```yaml
21
+ development:
22
+ # ...
23
+ dev_server:
24
+ # ...
25
+ hmr: true
26
+ inline: true
27
+ # ...
28
+ ```
25
29
 
26
- To support HMR with React you would need to add `react-hot-loader`. Checkout this guide for
27
- more information:
30
+ `dev_server/hmr` option inside `webpacker.yml`.
28
31
 
29
- - https://gaearon.github.io/react-hot-loader/getstarted/
32
+ Check out this guide for more information:
30
33
 
31
- **Note:** Don't forget to disable `HMR` if you are not running `webpack-dev-server`
32
- otherwise you will get not found error for stylesheets.
34
+ - https://webpack.js.org/configuration/dev-server/#devserver-hot
33
35
 
36
+ To support HMR with React, see [docs/react.md](./react.md#hmr-and-react-hot-reloading).
34
37
 
35
38
  ## Nginx
36
39
 
@@ -77,9 +80,8 @@ server {
77
80
  ## Customizing Logging
78
81
 
79
82
  By default, the dev server will display a colored progress notification while
80
- your code is being compiled. (Under the hood, we are using `webpack-dev-server
81
- --progress --color`). However, this might cause issues if you don't use
82
- `foreman` and/or try to log webpack-dev-server's output to a file. You can
83
+ your code is being compiled. (Under the hood, we are using `webpack-dev-server --progress --color`). However, this might cause issues if you don't use
84
+ `foreman` and/or try to log webpack-dev-server's output to a file. You can
83
85
  disable this stylized output by adding `pretty: false` to your `dev_server`
84
86
  config:
85
87