jetpacker 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) 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/.node-version +1 -1
  8. data/.travis.yml +8 -21
  9. data/CHANGELOG.jetpacker.md +5 -0
  10. data/CHANGELOG.md +44 -2
  11. data/Gemfile +1 -0
  12. data/Gemfile.lock +115 -101
  13. data/README.md +23 -649
  14. data/docs/css.md +58 -3
  15. data/docs/deployment.md +2 -2
  16. data/docs/docker.md +17 -17
  17. data/docs/engines.md +13 -0
  18. data/docs/env.md +0 -2
  19. data/docs/integrations.md +220 -0
  20. data/docs/target.md +22 -0
  21. data/docs/testing.md +2 -3
  22. data/docs/troubleshooting.md +3 -1
  23. data/docs/typescript.md +92 -28
  24. data/docs/webpack-dev-server.md +1 -1
  25. data/jetpacker.gemspec +4 -3
  26. data/lib/install/config/babel.config.js +1 -3
  27. data/lib/install/config/webpacker.yml +1 -4
  28. data/lib/install/examples/react/tsconfig.json +2 -1
  29. data/lib/install/examples/typescript/tsconfig.json +2 -1
  30. data/lib/install/loaders/svelte.js +2 -2
  31. data/lib/install/template.rb +1 -1
  32. data/lib/install/typescript.rb +5 -1
  33. data/lib/jetpacker/version.rb +1 -1
  34. data/lib/tasks/webpacker/check_node.rake +15 -8
  35. data/lib/tasks/webpacker/check_yarn.rake +17 -10
  36. data/lib/tasks/webpacker/clean.rake +12 -8
  37. data/lib/tasks/webpacker/clobber.rake +8 -4
  38. data/lib/tasks/webpacker/yarn_install.rake +5 -16
  39. data/lib/webpacker/commands.rb +33 -9
  40. data/lib/webpacker/compiler.rb +9 -5
  41. data/lib/webpacker/configuration.rb +13 -9
  42. data/lib/webpacker/dev_server_proxy.rb +3 -1
  43. data/lib/webpacker/dev_server_runner.rb +2 -2
  44. data/lib/webpacker/helper.rb +37 -18
  45. data/lib/webpacker/manifest.rb +4 -4
  46. data/lib/webpacker/railtie.rb +0 -43
  47. data/lib/webpacker/runner.rb +1 -0
  48. data/lib/webpacker/turbine.rb +0 -41
  49. data/lib/webpacker/version.rb +1 -1
  50. data/lib/webpacker/webpack_runner.rb +2 -2
  51. data/package.json +39 -39
  52. data/package/__tests__/config.js +12 -1
  53. data/package/__tests__/dev_server.js +2 -0
  54. data/package/__tests__/development.js +14 -1
  55. data/package/config.js +4 -1
  56. data/package/configPath.js +3 -0
  57. data/package/dev_server.js +1 -1
  58. data/package/env.js +1 -2
  59. data/package/environments/__tests__/base.js +29 -2
  60. data/package/environments/base.js +17 -7
  61. data/package/environments/development.js +39 -37
  62. data/package/environments/production.js +1 -3
  63. data/package/rules/babel.js +12 -5
  64. data/package/rules/file.js +1 -0
  65. data/package/rules/node_modules.js +1 -3
  66. data/package/rules/sass.js +7 -1
  67. data/package/utils/helpers.js +1 -1
  68. data/test/compiler_test.rb +8 -3
  69. data/test/configuration_test.rb +8 -7
  70. data/test/dev_server_runner_test.rb +1 -1
  71. data/test/helper_test.rb +3 -0
  72. data/test/manifest_test.rb +37 -6
  73. data/test/rake_tasks_test.rb +11 -0
  74. data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
  75. data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
  76. data/test/test_app/config/application.rb +0 -1
  77. data/test/test_app/config/webpacker.yml +7 -1
  78. data/test/test_app/public/packs/manifest.json +1 -0
  79. data/test/webpack_runner_test.rb +1 -1
  80. data/yarn.lock +3405 -2836
  81. metadata +35 -14
  82. data/gemfiles/Gemfile-rails.4.2.x +0 -9
  83. data/gemfiles/Gemfile-rails.5.0.x +0 -9
  84. data/gemfiles/Gemfile-rails.5.1.x +0 -9
  85. data/lib/install/loaders/typescript.js +0 -11
data/README.md CHANGED
@@ -29,667 +29,41 @@ Tung
29
29
 
30
30
  Here's info on the git branch and tags strategy.
31
31
 
32
+ * the latest upstream webpacker version that has been merged back in is v5.2.1
32
33
  * master: jetpacker fork with latest changes
33
- * forkpoint-1: git tag of point at which forked from rails/webpacker and changes were made. For diff: `git diff forkpoint-1..v0.2.0`
34
+ * forkpoint-1: git tag of point at which forked from rails/webpacker and **original** changes were made. For diff: `git diff forkpoint-1..v0.2.0`
34
35
  * rails git origin: upstream origin with rails/webpacker origin
35
36
 
36
- ## Original README Below
37
+ ## Upgrade Notes
37
38
 
38
- [![Build Status](https://travis-ci.org/rails/webpacker.svg?branch=master)](https://travis-ci.org/rails/webpacker)
39
- [![node.js](https://img.shields.io/badge/node-%3E%3D%208.16.0-brightgreen.svg)](https://nodejs.org/en/)
40
- [![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://github.com/rails/webpacker)
39
+ If you run bundle so that jetpacker is updated. IE:
41
40
 
41
+ bundle update
42
+ # or
43
+ bundle update jetpacker
42
44
 
43
- Webpacker makes it easy to use the JavaScript pre-processor and bundler
44
- [webpack 4.x.x+](https://webpack.js.org/)
45
- to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
46
- as the primary purpose for webpack is app-like JavaScript, not images, CSS, or
47
- even JavaScript Sprinkles (that all continues to live in app/assets).
45
+ You can update the webpacker-related files with:
48
46
 
49
- However, it is possible to use Webpacker for CSS, images and fonts assets as well,
50
- in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
47
+ jets webpacker:install
51
48
 
52
- **NOTE:** The master branch now hosts the code for v4.x.x. Please refer to [3-x-stable](https://github.com/rails/webpacker/tree/3-x-stable) branch for 3.x documentation. See the [v4-upgrade guide](docs/v4-upgrade.md) for an overview of the changes.
49
+ Then update the manually the environment.js
53
50
 
54
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
55
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
56
- ## Table of Contents
51
+ config/webpacker/environment.js:
57
52
 
58
- - [Prerequisites](#prerequisites)
59
- - [Features](#features)
60
- - [Installation](#installation)
61
- - [Usage](#usage)
62
- - [Development](#development)
63
- - [Webpack Configuration](#webpack-configuration)
64
- - [Custom Rails environments](#custom-rails-environments)
65
- - [Upgrading](#upgrading)
66
- - [Yarn Integrity](#yarn-integrity)
67
- - [Integrations](#integrations)
68
- - [React](#react)
69
- - [Angular with TypeScript](#angular-with-typescript)
70
- - [Vue](#vue)
71
- - [Elm](#elm)
72
- - [Stimulus](#stimulus)
73
- - [Svelte](#svelte)
74
- - [CoffeeScript](#coffeescript)
75
- - [Erb](#erb)
76
- - [Paths](#paths)
77
- - [Resolved](#resolved)
78
- - [Watched](#watched)
79
- - [Deployment](#deployment)
80
- - [Docs](#docs)
81
- - [Contributing](#contributing)
82
- - [License](#license)
53
+ ```javascript
54
+ const { environment } = require('@rails/webpacker')
55
+ const webpack = require('webpack')
56
+ environment.plugins.prepend('Provide', new webpack.ProvidePlugin({
57
+ $: 'jquery',
58
+ jQuery: 'jquery',
59
+ Popper: ['popper.js', 'default']
60
+ }))
83
61
 
84
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
85
-
86
-
87
- ## Prerequisites
88
-
89
- * Ruby 2.2+
90
- * Rails 4.2+
91
- * Node.js 8.16.0+
92
- * Yarn 1.x+
93
-
94
-
95
- ## Features
96
-
97
- * [webpack 4.x.x](https://webpack.js.org/)
98
- * ES6 with [babel](https://babeljs.io/)
99
- * Automatic code splitting using multiple entry points
100
- * Stylesheets - Sass and CSS
101
- * Images and fonts
102
- * PostCSS - Auto-Prefixer
103
- * Asset compression, source-maps, and minification
104
- * CDN support
105
- * React, Angular, Elm and Vue support out-of-the-box
106
- * Rails view helpers
107
- * Extensible and configurable
108
-
109
-
110
- ## Installation
111
-
112
- You can either add Webpacker during setup of a new Rails 5.1+ application
113
- using new `--webpack` option:
114
-
115
- ```bash
116
- # Available Rails 5.1+
117
- rails new myapp --webpack
118
- ```
119
-
120
- Or add it to your `Gemfile`:
121
-
122
- ```ruby
123
- # Gemfile
124
- gem 'webpacker', '~> 4.x'
125
-
126
- # OR if you prefer to use master
127
- gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
128
- yarn add https://github.com/rails/webpacker.git
129
- yarn add core-js regenerator-runtime
130
- ```
131
-
132
- Finally, run the following to install Webpacker:
133
-
134
- ```bash
135
- bundle
136
- bundle exec rails webpacker:install
137
-
138
- # OR (on rails version < 5.0)
139
- bundle exec rake webpacker:install
140
- ```
141
-
142
- Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/webpacker/issues/1078),
143
-
144
- ```bash
145
- yarn upgrade
146
- ```
147
-
148
- ### Usage
149
-
150
- Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
151
-
152
- ```yml
153
- app/javascript:
154
- ├── packs:
155
- │ # only webpack entry files here
156
- │ └── application.js
157
- └── src:
158
- │ └── application.css
159
- └── images:
160
- └── logo.svg
161
- ```
162
-
163
- In `/packs/application.js`, include this at the top of the file:
164
-
165
- ```js
166
- import "core-js/stable";
167
- import "regenerator-runtime/runtime";
168
- ```
169
-
170
- You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
171
- If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
172
-
173
- ```erb
174
- <%= javascript_pack_tag 'application' %>
175
- <%= stylesheet_pack_tag 'application' %>
176
- ```
177
-
178
- If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
179
- can use the `asset_pack_path` helper:
180
-
181
- ```erb
182
- <link rel="prefetch" href="<%= asset_pack_path 'application.css' %>" />
183
- <img src="<%= asset_pack_path 'images/logo.svg' %>" />
184
- ```
185
-
186
- If you are using new webpack 4 split chunks API, then consider using `javascript_packs_with_chunks_tag` helper, which creates html
187
- tags for a pack and all the dependent chunks.
188
-
189
- ```erb
190
- <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
191
-
192
- <script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
193
- <script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
194
- <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
195
- <script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
196
- <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
197
- ```
198
-
199
- **Important:** Pass all your pack names when using `javascript_packs_with_chunks_tag`
200
- helper otherwise you will get duplicated chunks on the page.
201
-
202
- ```erb
203
- <%# DO %>
204
- <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
205
-
206
- <%# DON'T %>
207
- <%= javascript_packs_with_chunks_tag 'calendar' %>
208
- <%= javascript_packs_with_chunks_tag 'map' %>
209
- ```
210
-
211
- **Note:** In order for your styles or static assets files to be available in your view,
212
- you would need to link them in your "pack" or entry file.
213
-
214
-
215
- ### Development
216
-
217
- Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
218
- Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js`
219
- executables to ensure that the right configuration files and environmental variables
220
- are loaded based on your environment.
221
-
222
- In development, Webpacker compiles on demand rather than upfront by default. This
223
- happens when you refer to any of the pack assets using the Webpacker helper methods.
224
- This means that you don't have to run any separate processes. Compilation errors are logged
225
- to the standard Rails log.
226
-
227
- If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/webpack-dev-server` or `ruby ./bin/webpack-dev-server`. Windows users will need to run these commands
228
- in a terminal separate from `bundle exec rails s`. This process will watch for changes
229
- in the `app/javascript/packs/*.js` files and automatically reload the browser to match.
230
-
231
- ```bash
232
- # webpack dev server
233
- ./bin/webpack-dev-server
234
-
235
- # watcher
236
- ./bin/webpack --watch --colors --progress
237
-
238
- # standalone build
239
- ./bin/webpack
240
- ```
241
-
242
- Once you start this development server, Webpacker will automatically start proxying all
243
- webpack asset requests to this server. When you stop the server, it'll revert back to
244
- on-demand compilation.
245
-
246
- You can use environment variables as options supported by
247
- [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
248
- form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental
249
- variables will always take precedence over the ones already set in the
250
- configuration file, and that the _same_ environmental variables must
251
- be available to the `rails server` process.
252
-
253
- ```bash
254
- WEBPACKER_DEV_SERVER_HOST=example.com WEBPACKER_DEV_SERVER_INLINE=true WEBPACKER_DEV_SERVER_HOT=false ./bin/webpack-dev-server
255
- ```
256
-
257
- By default, the webpack dev server listens on `localhost` in development for security purposes.
258
- However, if you want your app to be available over local LAN IP or a VM instance like vagrant,
259
- you can set the `host` when running `./bin/webpack-dev-server` binstub:
260
-
261
- ```bash
262
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
263
- ```
264
-
265
- **Note:** You need to allow webpack-dev-server host as an allowed origin for `connect-src` if you are running your application in a restrict CSP environment (like Rails 5.2+). This can be done in Rails 5.2+ in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this:
266
-
267
- ```ruby
268
- Rails.application.config.content_security_policy do |policy|
269
- policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?
270
- end
271
- ```
272
-
273
- **Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
274
-
275
- ### Webpack Configuration
276
-
277
- See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
278
-
279
-
280
- ### Custom Rails environments
281
-
282
- 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.
283
-
284
- You can choose to define additional environment configurations in webpacker.yml,
285
-
286
- ```yml
287
- staging:
288
- <<: *default
289
-
290
- # Production depends on precompilation of packs prior to booting for performance.
291
- compile: false
292
-
293
- # Cache manifest.json for performance
294
- cache_manifest: true
295
-
296
- # Compile staging packs to a separate directory
297
- public_output_path: packs-staging
298
- ```
299
-
300
- or, Webpacker will use production environment as a fallback environment for loading configurations. Please note, `NODE_ENV` can either be set to `production`, `development` or `test`.
301
- This means you don't need to create additional environment files inside `config/webpacker/*` and instead use webpacker.yml to load different configurations using `RAILS_ENV`.
302
-
303
- For example, the below command will compile assets in production mode but will use staging configurations from `config/webpacker.yml` if available or use fallback production environment configuration:
304
-
305
- ```bash
306
- RAILS_ENV=staging bundle exec rails assets:precompile
307
- ```
308
-
309
- And, this will compile in development mode and load configuration for cucumber environment
310
- if defined in webpacker.yml or fallback to production configuration
311
-
312
- ```bash
313
- RAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile
314
- ```
315
-
316
- Please note, binstubs compiles in development mode however rake tasks
317
- compiles in production mode.
318
-
319
- ```bash
320
- # Compiles in development mode unless NODE_ENV is specified
321
- ./bin/webpack
322
- ./bin/webpack-dev-server
323
-
324
- # compiles in production mode by default unless NODE_ENV is specified
325
- bundle exec rails assets:precompile
326
- bundle exec rails webpacker:compile
327
- ```
328
-
329
-
330
- ### Upgrading
331
-
332
- You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
333
-
334
- ```bash
335
- bundle update webpacker
336
- rails webpacker:binstubs
337
- yarn upgrade @rails/webpacker --latest
338
- yarn upgrade webpack-dev-server --latest
339
-
340
- # Or to install the latest release (including pre-releases)
341
- yarn add @rails/webpacker@next
342
- ```
343
-
344
- ### Yarn Integrity
345
-
346
- 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`.
347
-
348
- To turn off this option, you will need to change the default setting in `config/webpacker.yml`:
349
-
350
- ```yaml
351
- # config/webpacker.yml
352
- development:
353
- ...
354
- # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
355
- check_yarn_integrity: false
356
- ```
357
-
358
- You may also turn on this feature by adding the config option for any Rails environment in `config/webpacker.yml`:
359
-
360
- ```yaml
361
- check_yarn_integrity: true
362
- ```
363
-
364
- ## Integrations
365
-
366
- Webpacker ships with basic out-of-the-box integration for React, Angular, Vue and Elm.
367
- You can see a list of available commands/tasks by running `bundle exec rails webpacker`:
368
-
369
- ### React
370
-
371
- To use Webpacker with [React](https://facebook.github.io/react/), create a
372
- new Rails 5.1+ app using `--webpack=react` option:
373
-
374
- ```bash
375
- # Rails 5.1+
376
- rails new myapp --webpack=react
377
- ```
378
-
379
- (or run `bundle exec rails webpacker:install:react` in an existing Rails app already
380
- setup with Webpacker).
381
-
382
- The installer will add all relevant dependencies using Yarn, changes
383
- to the configuration files, and an example React component to your
384
- project in `app/javascript/packs` so that you can experiment with React right away.
385
-
386
-
387
- ### Angular with TypeScript
388
-
389
- To use Webpacker with [Angular](https://angular.io/), create a
390
- new Rails 5.1+ app using `--webpack=angular` option:
391
-
392
- ```bash
393
- # Rails 5.1+
394
- rails new myapp --webpack=angular
395
- ```
396
-
397
- (or run `bundle exec rails webpacker:install:angular` on a Rails app already
398
- setup with Webpacker).
399
-
400
- The installer will add the TypeScript and Angular core libraries using Yarn alongside
401
- a few changes to the configuration files. An example component written in
402
- TypeScript will also be added to your project in `app/javascript` so that
403
- you can experiment with Angular right away.
404
-
405
- By default, Angular uses a JIT compiler for development environment. This
406
- compiler is not compatible with restrictive CSP (Content Security
407
- Policy) environments like Rails 5.2+. You can use Angular AOT compiler
408
- in development with the [@ngtools/webpack](https://www.npmjs.com/package/@ngtools/webpack#usage) plugin.
409
-
410
- Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for your
411
- development environment. This can be done in the `config/initializers/content_security_policy.rb`
412
- with the following code:
413
-
414
- ```ruby
415
- Rails.application.config.content_security_policy do |policy|
416
- if Rails.env.development?
417
- policy.script_src :self, :https, :unsafe_eval
418
- else
419
- policy.script_src :self, :https
420
- end
421
- end
422
- ```
423
-
424
-
425
- ### Vue
426
-
427
- To use Webpacker with [Vue](https://vuejs.org/), create a
428
- new Rails 5.1+ app using `--webpack=vue` option:
429
-
430
- ```bash
431
- # Rails 5.1+
432
- rails new myapp --webpack=vue
433
- ```
434
- (or run `bundle exec rails webpacker:install:vue` on a Rails app already setup with Webpacker).
435
-
436
- The installer will add Vue and its required libraries using Yarn alongside
437
- automatically applying changes needed to the configuration files. An example component will
438
- be added to your project in `app/javascript` so that you can experiment with Vue right away.
439
-
440
- If you're using Rails 5.2+ you'll need to enable `unsafe-eval` rule for your development environment.
441
- This can be done in the `config/initializers/content_security_policy.rb` with the following
442
- configuration:
443
-
444
- ```ruby
445
- Rails.application.config.content_security_policy do |policy|
446
- if Rails.env.development?
447
- policy.script_src :self, :https, :unsafe_eval
448
- else
449
- policy.script_src :self, :https
450
- end
451
- end
452
- ```
453
- You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
454
-
455
- #### Lazy loading integration
456
-
457
- See [docs/es6](docs/es6.md) to know more about Webpack and Webpacker configuration.
458
-
459
- For instance, you can lazy load Vue JS components:
460
-
461
- Before:
462
- ```js
463
- import Vue from 'vue'
464
- import { VCard } from 'vuetify/lib'
465
-
466
- Vue.component('VCard', VCard)
467
- ```
468
-
469
- After:
470
- ```js
471
- import Vue from 'vue'
472
-
473
- // With destructuring assignment
474
- Vue.component('VCard', import('vuetify/lib').then(({ VCard }) => VCard)
475
-
476
- // Or without destructuring assignment
477
- Vue.component('OtherComponent', () => import('./OtherComponent'))
478
- ```
479
-
480
- You can use it in a Single File Component as well:
481
-
482
- ```html
483
- <template>
484
- ...
485
- </template>
486
-
487
- <script>
488
- export default {
489
- components: {
490
- OtherComponent: () => import('./OtherComponent')
491
- }
492
- }
493
- </script>
494
- ```
495
-
496
- By wrapping the import function into an arrow function, Vue will execute it only when it gets requested, loading the module in that moment.
497
-
498
- ##### Automatic registration
499
-
500
- ```js
501
- /**
502
- * The following block of code may be used to automatically register your
503
- * Vue components. It will recursively scan this directory for the Vue
504
- * components and automatically register them with their "basename".
505
- *
506
- * Eg. ./components/OtherComponent.vue -> <other-component></other-component>
507
- * Eg. ./UI/ButtonComponent.vue -> <button-component></button-component>
508
- */
509
-
510
- const files = require.context('./', true, /\.vue$/i)
511
- files.keys().map(key => {
512
- const component = key.split('/').pop().split('.')[0]
513
-
514
- // With Lazy Loading
515
- Vue.component(component, () => import(`${key}`))
516
-
517
- // Or without Lazy Loading
518
- Vue.component(component, files(key).default)
519
- })
520
- ```
521
-
522
- ### Elm
523
-
524
- To use Webpacker with [Elm](http://elm-lang.org), create a
525
- new Rails 5.1+ app using `--webpack=elm` option:
526
-
527
- ```
528
- # Rails 5.1+
529
- rails new myapp --webpack=elm
530
- ```
531
-
532
- (or run `bundle exec rails webpacker:install:elm` on a Rails app already setup with Webpacker).
533
-
534
- The Elm library and its core packages will be added via Yarn and Elm.
535
- An example `Main.elm` app will also be added to your project in `app/javascript`
536
- so that you can experiment with Elm right away.
537
-
538
- ### Svelte
539
-
540
- To use Webpacker with [Svelte](https://svelte.dev), create a
541
- new Rails 5.1+ app using `--webpack=svelte` option:
542
-
543
- ```
544
- # Rails 5.1+
545
- rails new myapp --webpack=svelte
546
- ```
547
-
548
- (or run `bundle exec rails webpacker:install:svelte` on a Rails app already setup with Webpacker).
549
-
550
- Please play with the [Svelte Tutorial](https://svelte.dev/tutorial/basics) or learn more about its API at https://svelte.dev/docs
551
-
552
- ### Stimulus
553
-
554
- To use Webpacker with [Stimulus](http://stimulusjs.org), create a
555
- new Rails 5.1+ app using `--webpack=stimulus` option:
556
-
557
- ```
558
- # Rails 5.1+
559
- rails new myapp --webpack=stimulus
560
- ```
561
-
562
- (or run `bundle exec rails webpacker:install:stimulus` on a Rails app already setup with Webpacker).
563
-
564
- Please read [The Stimulus Handbook](https://stimulusjs.org/handbook/introduction) or learn more about its source code at https://github.com/stimulusjs/stimulus
565
-
566
- ### CoffeeScript
567
-
568
- To add [CoffeeScript](http://coffeescript.org/) support,
569
- run `bundle exec rails webpacker:install:coffee` on a Rails app already
570
- setup with Webpacker.
571
-
572
- An example `hello_coffee.coffee` file will also be added to your project
573
- in `app/javascript/packs` so that you can experiment with CoffeeScript right away.
574
-
575
- ### Erb
576
-
577
- To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates,
578
- run `bundle exec rails webpacker:install:erb` on a Rails app already
579
- setup with Webpacker.
580
-
581
- An example `hello_erb.js.erb` file will also be added to your project
582
- in `app/javascript/packs` so that you can experiment with Erb-flavoured
583
- javascript right away.
584
-
585
-
586
- ## Paths
587
-
588
- By default, Webpacker ships with simple conventions for where the JavaScript
589
- app files and compiled webpack bundles will go in your Rails app.
590
- All these options are configurable from `config/webpacker.yml` file.
591
-
592
- The configuration for what webpack is supposed to compile by default rests
593
- on the convention that every file in `app/javascript/packs/*`**(default)**
594
- or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
595
- is turned into their own output files (or entry points, as webpack calls it). Therefore you don't want to put anything inside `packs` directory that you do not want to be
596
- an entry file. As a rule of thumb, put all files you want to link in your views inside
597
- "packs" directory and keep everything else under `app/javascript`.
598
-
599
- Suppose you want to change the source directory from `app/javascript`
600
- to `frontend` and output to `assets/packs`. This is how you would do it:
601
-
602
- ```yml
603
- # config/webpacker.yml
604
- source_path: frontend
605
- source_entry_path: packs
606
- public_output_path: assets/packs # outputs to => public/assets/packs
62
+ module.exports = environment
607
63
  ```
608
64
 
609
- Similarly you can also control and configure `webpack-dev-server` settings from `config/webpacker.yml` file:
610
-
611
- ```yml
612
- # config/webpacker.yml
613
- development:
614
- dev_server:
615
- host: localhost
616
- port: 3035
617
- ```
618
-
619
- 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.
620
-
621
-
622
- ### Resolved
623
-
624
- If you are adding Webpacker to an existing app that has most of the assets inside
625
- `app/assets` or inside an engine, and you want to share that
626
- with webpack modules, you can use the `resolved_paths`
627
- option available in `config/webpacker.yml`. This lets you
628
- add additional paths that webpack should lookup when resolving modules:
629
-
630
- ```yml
631
- resolved_paths: ['app/assets']
632
- ```
633
-
634
- You can then import these items inside your modules like so:
635
-
636
- ```js
637
- // Note it's relative to parent directory i.e. app/assets
638
- import 'stylesheets/main'
639
- import 'images/rails.png'
640
- ```
641
-
642
- **Note:** Please be careful when adding paths here otherwise it
643
- will make the compilation slow, consider adding specific paths instead of
644
- whole parent directory if you just need to reference one or two modules
645
-
646
-
647
- ### Watched
648
-
649
- By default, the lazy compilation is cached until a file is changed under your
650
- tracked paths. You can configure which paths are tracked
651
- by adding new paths to `watched_paths` array. This is much like Rails' `autoload_paths`:
652
-
653
- ```rb
654
- # config/initializers/webpacker.rb
655
- # or config/application.rb
656
- Webpacker::Compiler.watched_paths << 'bower_components'
657
- ```
658
-
659
-
660
- ## Deployment
661
-
662
- 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).
663
-
664
-
665
- ## Docs
666
-
667
- - [Development](https://github.com/rails/webpacker#development)
668
- - [Webpack](./docs/webpack.md)
669
- - [Webpack-dev-server](./docs/webpack-dev-server.md)
670
- - [Environment Variables](./docs/env.md)
671
- - [Folder Structure](./docs/folder-structure.md)
672
- - [Assets](./docs/assets.md)
673
- - [CSS, Sass and SCSS](./docs/css.md)
674
- - [ES6](./docs/es6.md)
675
- - [Props](./docs/props.md)
676
- - [Typescript](./docs/typescript.md)
677
- - [Yarn](./docs/yarn.md)
678
- - [Misc](./docs/misc.md)
679
- - [Deployment](./docs/deployment.md)
680
- - [Docker](./docs/docker.md)
681
- - [Using in Rails engines](./docs/engines.md)
682
- - [Webpacker on Cloud9](./docs/cloud9.md)
683
- - [Testing](./docs/testing.md)
684
- - [Troubleshooting](./docs/troubleshooting.md)
685
- - [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
686
-
687
-
688
- ## Contributing
689
- [![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)
690
-
691
- We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
65
+ This adds jquery so the crud.js works.
692
66
 
67
+ ## Original README
693
68
 
694
- ## License
695
- Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
69
+ https://github.com/rails/webpacker