jetpacker 0.4.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) 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 +58 -0
  7. data/.gitignore +1 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +113 -13
  10. data/.travis.yml +8 -21
  11. data/CHANGELOG.jetpacker.md +5 -0
  12. data/CHANGELOG.md +68 -2
  13. data/Gemfile +1 -0
  14. data/README.md +23 -649
  15. data/docs/css.md +58 -3
  16. data/docs/deployment.md +2 -2
  17. data/docs/docker.md +17 -17
  18. data/docs/engines.md +13 -0
  19. data/docs/env.md +0 -2
  20. data/docs/integrations.md +220 -0
  21. data/docs/target.md +22 -0
  22. data/docs/testing.md +2 -3
  23. data/docs/troubleshooting.md +3 -1
  24. data/docs/typescript.md +92 -28
  25. data/docs/webpack-dev-server.md +1 -1
  26. data/gemfiles/Gemfile-rails-edge +1 -1
  27. data/jetpacker.gemspec +4 -3
  28. data/lib/install/config/babel.config.js +13 -3
  29. data/lib/install/config/webpacker.yml +1 -4
  30. data/lib/install/examples/react/babel.config.js +12 -0
  31. data/lib/install/examples/react/tsconfig.json +2 -1
  32. data/lib/install/examples/typescript/tsconfig.json +2 -1
  33. data/lib/install/loaders/svelte.js +2 -2
  34. data/lib/install/template.rb +11 -3
  35. data/lib/install/typescript.rb +6 -2
  36. data/lib/jetpacker/version.rb +1 -1
  37. data/lib/tasks/webpacker/check_node.rake +15 -8
  38. data/lib/tasks/webpacker/check_yarn.rake +16 -10
  39. data/lib/tasks/webpacker/clean.rake +12 -8
  40. data/lib/tasks/webpacker/clobber.rake +8 -4
  41. data/lib/tasks/webpacker/yarn_install.rake +11 -16
  42. data/lib/webpacker/commands.rb +33 -9
  43. data/lib/webpacker/compiler.rb +9 -5
  44. data/lib/webpacker/configuration.rb +28 -13
  45. data/lib/webpacker/dev_server_proxy.rb +3 -1
  46. data/lib/webpacker/dev_server_runner.rb +2 -2
  47. data/lib/webpacker/env.rb +5 -1
  48. data/lib/webpacker/helper.rb +37 -18
  49. data/lib/webpacker/manifest.rb +4 -4
  50. data/lib/webpacker/railtie.rb +0 -43
  51. data/lib/webpacker/runner.rb +1 -0
  52. data/lib/webpacker/turbine.rb +0 -41
  53. data/lib/webpacker/version.rb +1 -1
  54. data/lib/webpacker/webpack_runner.rb +2 -2
  55. data/package/__tests__/config.js +12 -1
  56. data/package/__tests__/dev_server.js +2 -0
  57. data/package/__tests__/development.js +14 -1
  58. data/package/config.js +4 -1
  59. data/package/configPath.js +3 -0
  60. data/package/dev_server.js +1 -1
  61. data/package/env.js +1 -2
  62. data/package/environments/__tests__/base.js +29 -2
  63. data/package/environments/base.js +17 -7
  64. data/package/environments/development.js +39 -37
  65. data/package/environments/production.js +1 -3
  66. data/package/rules/babel.js +12 -5
  67. data/package/rules/file.js +3 -2
  68. data/package/rules/node_modules.js +1 -3
  69. data/package/rules/sass.js +10 -1
  70. data/package/utils/helpers.js +1 -1
  71. data/package.json +41 -41
  72. data/test/compiler_test.rb +8 -3
  73. data/test/configuration_test.rb +8 -7
  74. data/test/dev_server_runner_test.rb +1 -1
  75. data/test/helper_test.rb +24 -9
  76. data/test/manifest_test.rb +37 -6
  77. data/test/rake_tasks_test.rb +11 -0
  78. data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
  79. data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
  80. data/test/test_app/config/application.rb +0 -1
  81. data/test/test_app/config/webpacker.yml +7 -1
  82. data/test/test_app/public/packs/manifest.json +1 -0
  83. data/test/webpack_runner_test.rb +1 -1
  84. data/yarn.lock +3895 -3945
  85. metadata +35 -15
  86. data/Gemfile.lock +0 -171
  87. data/gemfiles/Gemfile-rails.4.2.x +0 -9
  88. data/gemfiles/Gemfile-rails.5.0.x +0 -9
  89. data/gemfiles/Gemfile-rails.5.1.x +0 -9
  90. data/lib/install/loaders/typescript.js +0 -11
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/app.js file:
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/app.sass file:
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/deployment.md CHANGED
@@ -13,8 +13,8 @@ By default the output will look like this in different environments:
13
13
  <script src="http://localhost:8080/calendar-0bd141f6d9360cf4a7f5.js"></script>
14
14
  <link rel="stylesheet" media="screen" href="http://localhost:8080/calendar-dc02976b5f94b507e3b6.css">
15
15
  <!-- In production or development mode -->
16
- <script src="/packs/calendar-0bd141f6d9360cf4a7f5.js"></script>
17
- <link rel="stylesheet" media="screen" href="/packs/calendar-dc02976b5f94b507e3b6.css">
16
+ <script src="/packs/js/calendar-0bd141f6d9360cf4a7f5.js"></script>
17
+ <link rel="stylesheet" media="screen" href="/packs/css/calendar-dc02976b5f94b507e3b6.css">
18
18
  ```
19
19
 
20
20
 
data/docs/docker.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Docker
2
2
 
3
- To setup webpacker with a dockerized Rails application is trivial.
3
+ To setup webpacker with a dockerized Rails application.
4
4
 
5
5
  First, add a new service for webpacker in docker-compose.yml:
6
6
 
@@ -9,8 +9,10 @@ version: '3'
9
9
  services:
10
10
  webpacker:
11
11
  build: .
12
- env_file:
13
- - '.env.docker'
12
+ environment:
13
+ - NODE_ENV=development
14
+ - RAILS_ENV=development
15
+ - WEBPACKER_DEV_SERVER_HOST=0.0.0.0
14
16
  command: ./bin/webpack-dev-server
15
17
  volumes:
16
18
  - .:/webpacker-example-app
@@ -18,15 +20,6 @@ services:
18
20
  - '3035:3035'
19
21
  ```
20
22
 
21
- Second, change the webpack-dev-server host to the service name of the docker-compose in config/webpacker.yml:
22
-
23
- ```yaml
24
- development:
25
- <<: *default
26
- dev_server:
27
- host: webpacker
28
- ```
29
-
30
23
  add nodejs and yarn as dependencies in Dockerfile,
31
24
 
32
25
  ```dockerfile
@@ -53,12 +46,19 @@ RUN curl -sL https://deb.nodesource.com/setup_8.x | bash \
53
46
  # Rest of the commands....
54
47
  ```
55
48
 
56
- and create an env file to load environment variables from:
49
+ then add the webpacker host name environment variable to the web/app service:
57
50
 
58
- ```env
59
- NODE_ENV=development
60
- RAILS_ENV=development
61
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
51
+ ```Dockerfile
52
+ web:
53
+ build:
54
+ context: .
55
+ command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
56
+ volumes:
57
+ - .:/usr/src/app
58
+ ports:
59
+ - "3000:3000"
60
+ environment:
61
+ - WEBPACKER_DEV_SERVER_HOST=webpacker
62
62
  ```
63
63
 
64
64
  Lastly, rebuild your container:
data/docs/engines.md CHANGED
@@ -196,5 +196,18 @@ config.middleware.use(
196
196
  urls: ["/my-engine-packs"], root: "my_engine/public"
197
197
  )
198
198
  ```
199
+ or if you prefer to keep your engine-related configuration within the engine itself
200
+
201
+ ```ruby
202
+ # my-engine-root/lib/my-engine/engine.rb
203
+ module MyEngine
204
+ class Engine < ::Rails:Engine
205
+ config.app_middleware.use(
206
+ Rack::Static,
207
+ urls: ["/my-engine-packs"], root: "my_engine/public"
208
+ )
209
+ end
210
+ end
211
+ ```
199
212
 
200
213
  **NOTE:** in the example above we assume that your `public_output_path` is set to `my-engine-packs` in your engine's `webpacker.yml`.
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
 
@@ -0,0 +1,220 @@
1
+ # Integrations
2
+
3
+ Webpacker ships with basic out-of-the-box integration for React, Angular, Vue and Elm.
4
+ You can see a list of available commands/tasks by running `bundle exec rails webpacker`:
5
+
6
+ ## React
7
+
8
+ To use Webpacker with [React](https://facebook.github.io/react/), create a
9
+ new Rails 5.1+ app using `--webpack=react` option:
10
+
11
+ ```bash
12
+ # Rails 5.1+
13
+ rails new myapp --webpack=react
14
+ ```
15
+
16
+ (or run `bundle exec rails webpacker:install:react` in an existing Rails app already
17
+ setup with Webpacker).
18
+
19
+ The installer will add all relevant dependencies using Yarn, changes
20
+ to the configuration files, and an example React component to your
21
+ project in `app/javascript/packs` so that you can experiment with React right away.
22
+
23
+
24
+ ## Angular with TypeScript
25
+
26
+ To use Webpacker with [Angular](https://angular.io/), create a
27
+ new Rails 5.1+ app using `--webpack=angular` option:
28
+
29
+ ```bash
30
+ # Rails 5.1+
31
+ rails new myapp --webpack=angular
32
+ ```
33
+
34
+ (or run `bundle exec rails webpacker:install:angular` on a Rails app already
35
+ setup with Webpacker).
36
+
37
+ The installer will add the TypeScript and Angular core libraries using Yarn alongside
38
+ a few changes to the configuration files. An example component written in
39
+ TypeScript will also be added to your project in `app/javascript` so that
40
+ you can experiment with Angular right away.
41
+
42
+ By default, Angular uses a JIT compiler for development environment. This
43
+ compiler is not compatible with restrictive CSP (Content Security
44
+ Policy) environments like Rails 5.2+. You can use Angular AOT compiler
45
+ in development with the [@ngtools/webpack](https://www.npmjs.com/package/@ngtools/webpack#usage) plugin.
46
+
47
+ Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for your
48
+ development environment. This can be done in the `config/initializers/content_security_policy.rb`
49
+ with the following code:
50
+
51
+ ```ruby
52
+ Rails.application.config.content_security_policy do |policy|
53
+ if Rails.env.development?
54
+ policy.script_src :self, :https, :unsafe_eval
55
+ else
56
+ policy.script_src :self, :https
57
+ end
58
+ end
59
+ ```
60
+
61
+
62
+ ## Vue
63
+
64
+ To use Webpacker with [Vue](https://vuejs.org/), create a
65
+ new Rails 5.1+ app using `--webpack=vue` option:
66
+
67
+ ```bash
68
+ # Rails 5.1+
69
+ rails new myapp --webpack=vue
70
+ ```
71
+ (or run `bundle exec rails webpacker:install:vue` on a Rails app already setup with Webpacker).
72
+
73
+ The installer will add Vue and its required libraries using Yarn alongside
74
+ automatically applying changes needed to the configuration files. An example component will
75
+ be added to your project in `app/javascript` so that you can experiment with Vue right away.
76
+
77
+ If you're using Rails 5.2+ you'll need to enable `unsafe-eval` rule for your development environment.
78
+ This can be done in the `config/initializers/content_security_policy.rb` with the following
79
+ configuration:
80
+
81
+ ```ruby
82
+ Rails.application.config.content_security_policy do |policy|
83
+ if Rails.env.development?
84
+ policy.script_src :self, :https, :unsafe_eval
85
+ else
86
+ policy.script_src :self, :https
87
+ end
88
+ end
89
+ ```
90
+ You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
91
+
92
+ ### Lazy loading integration
93
+
94
+ See [docs/es6](es6.md) to know more about Webpack and Webpacker configuration.
95
+
96
+ For instance, you can lazy load Vue JS components:
97
+
98
+ Before:
99
+ ```js
100
+ import Vue from 'vue'
101
+ import { VCard } from 'vuetify/lib'
102
+
103
+ Vue.component('VCard', VCard)
104
+ ```
105
+
106
+ After:
107
+ ```js
108
+ import Vue from 'vue'
109
+
110
+ // With destructuring assignment
111
+ Vue.component('VCard', import('vuetify/lib').then(({ VCard }) => VCard)
112
+
113
+ // Or without destructuring assignment
114
+ Vue.component('OtherComponent', () => import('./OtherComponent'))
115
+ ```
116
+
117
+ You can use it in a Single File Component as well:
118
+
119
+ ```html
120
+ <template>
121
+ ...
122
+ </template>
123
+
124
+ <script>
125
+ export default {
126
+ components: {
127
+ OtherComponent: () => import('./OtherComponent')
128
+ }
129
+ }
130
+ </script>
131
+ ```
132
+
133
+ By wrapping the import function into an arrow function, Vue will execute it only when it gets requested, loading the module in that moment.
134
+
135
+ ##### Automatic registration
136
+
137
+ ```js
138
+ /**
139
+ * The following block of code may be used to automatically register your
140
+ * Vue components. It will recursively scan this directory for the Vue
141
+ * components and automatically register them with their "basename".
142
+ *
143
+ * Eg. ./components/OtherComponent.vue -> <other-component></other-component>
144
+ * Eg. ./UI/ButtonComponent.vue -> <button-component></button-component>
145
+ */
146
+
147
+ const files = require.context('./', true, /\.vue$/i)
148
+ files.keys().map(key => {
149
+ const component = key.split('/').pop().split('.')[0]
150
+
151
+ // With Lazy Loading
152
+ Vue.component(component, () => import(`${key}`))
153
+
154
+ // Or without Lazy Loading
155
+ Vue.component(component, files(key).default)
156
+ })
157
+ ```
158
+
159
+ ## Elm
160
+
161
+ To use Webpacker with [Elm](http://elm-lang.org), create a
162
+ new Rails 5.1+ app using `--webpack=elm` option:
163
+
164
+ ```
165
+ # Rails 5.1+
166
+ rails new myapp --webpack=elm
167
+ ```
168
+
169
+ (or run `bundle exec rails webpacker:install:elm` on a Rails app already setup with Webpacker).
170
+
171
+ The Elm library and its core packages will be added via Yarn and Elm.
172
+ An example `Main.elm` app will also be added to your project in `app/javascript`
173
+ so that you can experiment with Elm right away.
174
+
175
+ ## Svelte
176
+
177
+ To use Webpacker with [Svelte](https://svelte.dev), create a
178
+ new Rails 5.1+ app using `--webpack=svelte` option:
179
+
180
+ ```
181
+ # Rails 5.1+
182
+ rails new myapp --webpack=svelte
183
+ ```
184
+
185
+ (or run `bundle exec rails webpacker:install:svelte` on a Rails app already setup with Webpacker).
186
+
187
+ Please play with the [Svelte Tutorial](https://svelte.dev/tutorial/basics) or learn more about its API at https://svelte.dev/docs
188
+
189
+ ## Stimulus
190
+
191
+ To use Webpacker with [Stimulus](http://stimulusjs.org), create a
192
+ new Rails 5.1+ app using `--webpack=stimulus` option:
193
+
194
+ ```
195
+ # Rails 5.1+
196
+ rails new myapp --webpack=stimulus
197
+ ```
198
+
199
+ (or run `bundle exec rails webpacker:install:stimulus` on a Rails app already setup with Webpacker).
200
+
201
+ Please read [The Stimulus Handbook](https://stimulusjs.org/handbook/introduction) or learn more about its source code at https://github.com/stimulusjs/stimulus
202
+
203
+ ## CoffeeScript
204
+
205
+ To add [CoffeeScript](http://coffeescript.org/) support,
206
+ run `bundle exec rails webpacker:install:coffee` on a Rails app already
207
+ setup with Webpacker.
208
+
209
+ An example `hello_coffee.coffee` file will also be added to your project
210
+ in `app/javascript/packs` so that you can experiment with CoffeeScript right away.
211
+
212
+ ## Erb
213
+
214
+ To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates,
215
+ run `bundle exec rails webpacker:install:erb` on a Rails app already
216
+ setup with Webpacker.
217
+
218
+ An example `hello_erb.js.erb` file will also be added to your project
219
+ in `app/javascript/packs` so that you can experiment with Erb-flavoured
220
+ javascript right away.
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').opts.writeToFileEmit = process.env.NODE_ENV !== 'test'
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",
@@ -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,19 +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 `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
- yarn add @types/react @types/react-dom
11
90
  ```
12
91
 
13
- 2. Rename the generated `hello_react.js` to `hello_react.tsx`. Make the file valid typescript and
14
- 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.
15
94
 
16
- ## Typescript with Vue components
95
+ ## TypeScript with Vue components
17
96
 
18
97
  1. Setup Vue using the Webpacker [Vue installer](../README.md#vue). Then run the TypeScript installer
19
98
 
@@ -22,37 +101,22 @@ bundle exec rails webpacker:install:typescript
22
101
  ```
23
102
 
24
103
  2. Rename generated `hello_vue.js` to `hello_vue.ts`.
25
- 3. Add the webpack plug-n-play plugin to your yarn packages with `yarn add pnp-webpack-plugin`.
26
- 4. Change the generated `config/webpack/loaders/typescript.js` from
104
+ 3. Install the right Babel preset: `yarn add babel-preset-typescript-vue`
105
+ 4. Change the generated `babel.config.js` from
27
106
 
28
107
  ```js
29
- module.exports = {
30
- test: /\.(ts|tsx)?(\.erb)?$/,
31
- use: [{
32
- loader: 'ts-loader'
33
- }]
34
- }
108
+ ["@babel/preset-typescript", { "allExtensions": true, "isTSX": true }]
35
109
  ```
36
110
 
37
111
  to
38
112
 
39
113
  ```js
40
- const PnpWebpackPlugin = require('pnp-webpack-plugin');
41
-
42
- module.exports = {
43
- test: /\.(ts|tsx)?(\.erb)?$/,
44
- use: [{
45
- loader: 'ts-loader',
46
- options: PnpWebpackPlugin.tsLoaderOptions({
47
- appendTsSuffixTo: [/\.vue$/]
48
- })
49
- }]
50
- }
114
+ ["babel-preset-typescript-vue", { "allExtensions": true, "isTSX": true }]
51
115
  ```
52
116
 
53
- and now you can use `<script lang="ts">` in your `.vue` component files. See [the pnp-webpack-plugin docs for the `ts-loader` integration](https://github.com/arcanis/pnp-webpack-plugin#ts-loader-integration) for more info.
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.
54
118
 
55
- ## HTML templates with Typescript and Angular
119
+ ## HTML templates with TypeScript and Angular
56
120
 
57
121
  After you have installed Angular using `bundle exec rails webpacker:install:angular`
58
122
  you would need to follow these steps to add HTML templates support:
@@ -19,7 +19,7 @@ Now if you refresh your Rails view everything should work as expected.
19
19
  Webpacker out-of-the-box supports HMR with `webpack-dev-server` and
20
20
  you can toggle it by setting `dev_server/hmr` option inside `webpacker.yml`.
21
21
 
22
- Checkout this guide for more information:
22
+ Check out this guide for more information:
23
23
 
24
24
  - https://webpack.js.org/configuration/dev-server/#devserver-hot
25
25
 
@@ -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", branch: "main"
8
8
  gem "arel", github: "rails/arel"
9
9
  gem "rake", ">= 11.1"
10
10
  gem "rack-proxy", require: false
data/jetpacker.gemspec CHANGED
@@ -19,11 +19,12 @@ Gem::Specification.new do |s|
19
19
  "changelog_uri" => "https://github.com/tongueroo/jetpacker/blob/v#{Jetpacker::VERSION}/CHANGELOG.md"
20
20
  }
21
21
 
22
- s.required_ruby_version = ">= 2.2.0"
22
+ s.required_ruby_version = ">= 2.4.0"
23
23
 
24
- s.add_dependency "activesupport", ">= 4.2"
25
- s.add_dependency "railties", ">= 4.2"
24
+ s.add_dependency "activesupport", ">= 5.2"
25
+ s.add_dependency "railties", ">= 5.2"
26
26
  s.add_dependency "rack-proxy", ">= 0.6.1"
27
+ s.add_dependency "semantic_range", ">= 2.3.0"
27
28
 
28
29
  s.add_development_dependency "bundler", ">= 1.3.0"
29
30
  s.add_development_dependency "rubocop", "< 0.69"