webpacker 3.6.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.node-version +1 -0
  3. data/.travis.yml +12 -4
  4. data/CHANGELOG.md +240 -28
  5. data/CONTRIBUTING.md +33 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +78 -71
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +75 -16
  10. data/docs/assets.md +7 -4
  11. data/docs/css.md +47 -14
  12. data/docs/deployment.md +11 -0
  13. data/docs/engines.md +155 -0
  14. data/docs/es6.md +5 -5
  15. data/docs/testing.md +1 -1
  16. data/docs/troubleshooting.md +4 -4
  17. data/docs/v4-upgrade.md +132 -0
  18. data/docs/webpack.md +56 -3
  19. data/docs/yarn.md +12 -1
  20. data/gemfiles/Gemfile-rails-edge +1 -1
  21. data/gemfiles/Gemfile-rails.4.2.x +2 -2
  22. data/gemfiles/Gemfile-rails.5.0.x +2 -2
  23. data/gemfiles/Gemfile-rails.5.1.x +2 -2
  24. data/gemfiles/Gemfile-rails.5.2.x +10 -0
  25. data/lib/install/bin/webpack +5 -1
  26. data/lib/install/bin/webpack-dev-server +5 -1
  27. data/lib/install/coffee.rb +2 -2
  28. data/lib/install/config/.browserslistrc +1 -0
  29. data/lib/install/config/babel.config.js +70 -0
  30. data/lib/install/config/postcss.config.js +12 -0
  31. data/lib/install/config/webpacker.yml +26 -0
  32. data/lib/install/elm.rb +2 -2
  33. data/lib/install/erb.rb +2 -2
  34. data/lib/install/examples/react/babel.config.js +83 -0
  35. data/lib/install/examples/stimulus/application.js +1 -6
  36. data/lib/install/examples/stimulus/controllers/index.js +9 -0
  37. data/lib/install/examples/typescript/tsconfig.json +4 -0
  38. data/lib/install/examples/vue/hello_vue.js +6 -4
  39. data/lib/install/javascript/packs/application.js +8 -0
  40. data/lib/install/loaders/typescript.js +8 -3
  41. data/lib/install/loaders/vue.js +1 -8
  42. data/lib/install/react.rb +6 -19
  43. data/lib/install/template.rb +29 -30
  44. data/lib/install/typescript.rb +4 -4
  45. data/lib/install/vue.rb +14 -5
  46. data/lib/tasks/installers.rake +4 -2
  47. data/lib/tasks/webpacker/binstubs.rake +3 -2
  48. data/lib/tasks/webpacker/compile.rake +10 -5
  49. data/lib/tasks/webpacker/install.rake +3 -2
  50. data/lib/tasks/webpacker/verify_install.rake +1 -4
  51. data/lib/tasks/webpacker/yarn_install.rake +1 -1
  52. data/lib/webpacker/commands.rb +0 -1
  53. data/lib/webpacker/compiler.rb +17 -13
  54. data/lib/webpacker/configuration.rb +13 -5
  55. data/lib/webpacker/dev_server.rb +7 -10
  56. data/lib/webpacker/dev_server_proxy.rb +13 -6
  57. data/lib/webpacker/dev_server_runner.rb +13 -6
  58. data/lib/webpacker/helper.rb +78 -20
  59. data/lib/webpacker/manifest.rb +64 -21
  60. data/lib/webpacker/railtie.rb +16 -7
  61. data/lib/webpacker/runner.rb +3 -3
  62. data/lib/webpacker/version.rb +1 -1
  63. data/lib/webpacker/webpack_runner.rb +14 -3
  64. data/package.json +46 -34
  65. data/package/__tests__/config.js +37 -3
  66. data/package/__tests__/dev_server.js +15 -0
  67. data/package/__tests__/production.js +2 -2
  68. data/package/__tests__/staging.js +3 -3
  69. data/package/__tests__/test.js +2 -1
  70. data/package/config.js +21 -9
  71. data/package/config_types/config_list.js +5 -6
  72. data/package/dev_server.js +3 -1
  73. data/package/environments/__tests__/base.js +7 -5
  74. data/package/environments/base.js +84 -31
  75. data/package/environments/development.js +6 -2
  76. data/package/environments/production.js +46 -36
  77. data/package/rules/babel.js +10 -4
  78. data/package/rules/file.js +8 -3
  79. data/package/rules/index.js +7 -2
  80. data/package/rules/node_modules.js +23 -0
  81. data/package/utils/__tests__/get_style_rule.js +20 -0
  82. data/package/utils/deep_merge.js +5 -6
  83. data/package/utils/get_style_rule.js +29 -42
  84. data/package/utils/helpers.js +18 -6
  85. data/package/utils/objectify.js +1 -2
  86. data/test/compiler_test.rb +15 -3
  87. data/test/configuration_test.rb +9 -0
  88. data/test/dev_server_runner_test.rb +51 -0
  89. data/test/helper_test.rb +48 -5
  90. data/test/manifest_test.rb +14 -0
  91. data/test/rake_tasks_test.rb +34 -0
  92. data/test/test_app/config.ru +5 -0
  93. data/test/test_app/config/application.rb +1 -0
  94. data/test/test_app/config/webpack/development.js +0 -0
  95. data/test/test_app/config/webpacker.yml +20 -0
  96. data/test/test_app/config/webpacker_public_root.yml +19 -0
  97. data/test/test_app/package.json +13 -0
  98. data/test/test_app/public/packs/manifest.json +22 -1
  99. data/test/test_app/yarn.lock +11 -0
  100. data/test/test_helper.rb +1 -3
  101. data/test/webpack_runner_test.rb +51 -0
  102. data/yarn.lock +4077 -2816
  103. metadata +28 -6
  104. data/lib/install/config/.babelrc +0 -18
  105. data/lib/install/config/.postcssrc.yml +0 -3
  106. data/lib/install/examples/react/.babelrc +0 -6
@@ -5,8 +5,8 @@
5
5
 
6
6
  Webpacker ships with [babel](https://babeljs.io/) - a JavaScript compiler so
7
7
  you can use next generation JavaScript, today. The Webpacker installer sets up a
8
- standard `.babelrc` file in your app root, which will work great in most cases
9
- because of [babel-env-preset](https://github.com/babel/babel-preset-env).
8
+ standard `babel.config.js` file in your app root, which will work great in most cases
9
+ because of [@babel/preset-env](https://github.com/babel/babel/tree/master/packages/babel-preset-env).
10
10
 
11
11
  Following ES6/7 features are supported out of the box:
12
12
 
@@ -19,14 +19,14 @@ Following ES6/7 features are supported out of the box:
19
19
  We have also included [babel polyfill](https://babeljs.io/docs/usage/polyfill/)
20
20
  that includes a custom regenerator runtime and core-js.
21
21
 
22
- Don't forget to import `babel-polyfill` in your main entry point like so:
22
+ Don't forget to import `@babel/polyfill` in your main entry point like so:
23
23
 
24
24
  ```js
25
- import "babel-polyfill"
25
+ import "@babel/polyfill"
26
26
  ```
27
27
 
28
28
 
29
- ## Module import() vs require()
29
+ ## Module import vs require()
30
30
 
31
31
  While you are free to use `require()` and `module.exports`, we encourage you
32
32
  to use `import` and `export` instead since it reads and looks much better.
@@ -34,7 +34,7 @@ It is beneficial to use the same webpack configuration file (generated by webpac
34
34
  // config/webpack/test.js
35
35
  const environment = require('./environment')
36
36
  environment.plugins.get('Manifest').opts.writeToFileEmit = process.env.NODE_ENV !== 'test'
37
- environment.loaders.set('istanbul-instrumenter', {
37
+ environment.loaders.append('istanbul-instrumenter', {
38
38
  test: /\.ts$/,
39
39
  enforce: "post",
40
40
  loader: "istanbul-instrumenter-loader",
@@ -86,7 +86,7 @@ chmod +x $HOME/your_rails_app/node_modules/.bin/elm-make
86
86
  ```
87
87
 
88
88
  ## Rake assets:precompile fails. ExecJS::RuntimeError
89
- This error occurs because you are trying to uglify a pack that's already been minified by Webpacker. To avoid this conflict and prevent appearing of ExecJS::RuntimeError error, you will need to disable uglifier from Rails config:
89
+ This error occurs because you are trying to minify by terser a pack that's already been minified by Webpacker. To avoid this conflict and prevent appearing of ExecJS::RuntimeError error, you will need to disable uglifier from Rails config:
90
90
 
91
91
  ```ruby
92
92
  // production.rb
@@ -96,13 +96,13 @@ Rails.application.config.assets.js_compressor = :uglifier
96
96
 
97
97
  # To
98
98
 
99
- #Rails.application.config.assets.js_compressor = :uglifier
99
+ Rails.application.config.assets.js_compressor = Uglifier.new(harmony: true)
100
100
 
101
101
  ```
102
102
 
103
- ## Angular: WARNING in ./node_modules/@angular/core/esm5/core.js, Critical dependency: the request of a dependency is an expression
103
+ ### Angular: WARNING in ./node_modules/@angular/core/esm5/core.js, Critical dependency: the request of a dependency is an expression
104
104
 
105
- To silence these warnings, please update `config/webpack/environment.js`
105
+ To silent these warnings, please update `config/webpack/environment.js`
106
106
 
107
107
  ```js
108
108
  // environment.js
@@ -0,0 +1,132 @@
1
+ # Webpacker Upgrade Guide
2
+
3
+
4
+ To update a Webpacker v3.5 app to v4, follow these steps:
5
+
6
+ 1. Update the `webpacker` gem and the `@rails/webpacker` package to v4. This will upgrade Webpack itself from 3.x to 4.x, make sure you're aware of [any deprecations which might effect you](https://webpack.js.org/migrate/4/). Also make sure any other packages you depend on support Webpack 4 and don't require any changes, e.g. if you explicitly include `webpack` you need to upgrade it to 4.x, and if you use `webpack-dev-server` you need to upgrade it to 3.x.
7
+
8
+ 2. Browser support definitions have been moved to [`.browserslistrc`](../lib/install/config/.browserslistrc) to `/`.
9
+
10
+ 3. Merge any differences between [`config/webpacker.yml`](../lib/install/config/webpacker.yml) and your `config/webpacker.yml`.
11
+
12
+ 4. Webpacker v4 upgrades Babel to [v7](https://babeljs.io/docs/en/v7-migration), see also [the release blog post](https://babeljs.io/blog/2018/08/27/7.0.0). Many packages were moved to the `@babel/` namespace, any babel plugins you have will need to be updated. It may be worth checking out [babel-upgrade](https://github.com/babel/babel-upgrade) if you have problems. ([#1564](https://github.com/rails/webpacker/pull/1564))
13
+
14
+ 5. `.babelrc` should be replaced with `babel.config.js` and `.postcssrc.yml` should be replaced with `postcss.config.js` ([#1822](https://github.com/rails/webpacker/pull/1822)). If you never changed these files from their defaults, the versions of [babel.config.js](../lib/install/config/babel.config.js) and [postcss.config.js](../lib/install/config/postcss.config.js) in the webpacker repository should be usable.
15
+
16
+ 6. Due to the change in [#1625](https://github.com/rails/webpacker/pull/1625), you'll want to make sure that `extract_css` is set to true for the `default` environment in `webpacker.yml` if you want to have Webpacker supply your CSS.
17
+
18
+ ## SplitChunks Configuration
19
+
20
+ If you used the `CommonsChunkPlugin` you'll need to upgrade to using the new `splitChunks`.
21
+
22
+ Originally, chunks (and modules imported inside them) were connected by a parent-child relationship in the internal Webpack graph. The `CommonsChunkPlugin` was used to avoid duplicated dependencies across them, but further optimizations were not possible.
23
+
24
+ In Webpack v4, the `CommonsChunkPlugin` was removed in favor of `optimization.splitChunks`.
25
+
26
+ For the full configuration options of `splitChunks`, see the [Webpack documentation](https://webpack.js.org/plugins/split-chunks-plugin/).
27
+
28
+ ```js
29
+ // config/webpack/environment.js
30
+ const WebpackAssetsManifest = require('webpack-assets-manifest');
31
+
32
+ // Enable the default config
33
+ environment.splitChunks()
34
+
35
+ // or using custom config
36
+ environment.splitChunks((config) => Object.assign({}, config, { optimization: { splitChunks: false }}))
37
+ ```
38
+
39
+ Then use the `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` helpers to include all the transpiled
40
+ packs with the chunks in your view, which creates html tags for all the chunks.
41
+
42
+ ```erb
43
+ <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
44
+
45
+ <!-- Creates the following: -->
46
+ <script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
47
+ <script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
48
+ <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
49
+ <script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
50
+ <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
51
+ ```
52
+
53
+ **Important:** Pass all your pack names to the helper otherwise you will get duplicated chunks on the page.
54
+
55
+ ```erb
56
+ <%# DO %>
57
+ <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
58
+
59
+ <%# DON'T %>
60
+ <%= javascript_packs_with_chunks_tag 'calendar' %>
61
+ <%= javascript_packs_with_chunks_tag 'map' %>
62
+ ```
63
+
64
+ ## Package-Specific Notes
65
+
66
+ - If you're using React, you need to add `"@babel/preset-react"`, to the list of `presets` in your babel config.
67
+ - If you're using Vue Loader, you'll need to upgrade to [v15](https://vue-loader.vuejs.org/migrating.html) for Webpack 4.
68
+ - To see what Webpacker generates for a given framework with v4, you may want to re-run `bundle exec rake webpacker:install:FRAMEWORK` and let it override the files for your given JavaScript framework, and then compare them to see what changes you'll need to make.
69
+
70
+ ## Excluding node_modules From Being Transpiled By Babel-Loader
71
+
72
+ One change to take into consideration, is that Webpacker 4 transpiles the
73
+ `node_modules` folder with the `babel-loader`. This folder used to be ignored by
74
+ Webpacker 3. The new behavior helps in case some library contains ES6 code, but in
75
+ some cases it can lead to issues. To avoid running `babel-loader` in the
76
+ `node_modules` folder, replicating the same behavior as Webpacker 3, the
77
+ following code can be added to `config/webpack/environment.js`:
78
+
79
+ ```javascript
80
+ environment.loaders.delete('nodeModules')
81
+ ```
82
+
83
+ Alternatively, in order to skip only a specific library in the `node_modules`
84
+ folder, this code can be added:
85
+
86
+ ```javascript
87
+ const nodeModulesLoader = environment.loaders.get('nodeModules')
88
+ if (!Array.isArray(nodeModulesLoader.exclude)) {
89
+ nodeModulesLoader.exclude = (nodeModulesLoader.exclude == null)
90
+ ? []
91
+ : [nodeModulesLoader.exclude]
92
+ }
93
+ nodeModulesLoader.exclude.push(/some-library/) // replace `some-library` with
94
+ // the actual path to exclude
95
+ ```
96
+
97
+ ## Source Maps Enabled By Default
98
+
99
+ Source maps are now enabled in production to make debugging in production easier. Enabling source maps doesn't have drawbacks for most of the applications since maps are compressed by default and aren't loaded by browsers unless Dev Tools are opened.
100
+
101
+ If you want to keep the old behavior source maps can be disabled in any environment configuration, e.g:
102
+
103
+ ```js
104
+ // config/webpack/production.js
105
+
106
+ const environment = require('./environment')
107
+ environment.config.merge({ devtool: 'none' })
108
+
109
+ module.exports = environment.toWebpackConfig()
110
+ ```
111
+
112
+ ## Namespaces
113
+
114
+ The compiled packs in the public directory are now stored under namespaces:
115
+
116
+ - JavaScripts are stored under `js`
117
+ - Stylesheets are stored under `css`
118
+ - Other resources are stored under `media`
119
+
120
+ ```rb
121
+ # Before
122
+ "runtime~hello_react" => "/packs/runtime~hello_react-da2baf7fd07b0e8b6d17.js"
123
+
124
+ # After
125
+ "runtime~hello_react" => "/packs/js/runtime~hello_react-da2baf7fd07b0e8b6d17.js"
126
+ ```
127
+
128
+ ## Example Upgrades
129
+
130
+ This is what an upgrade to Webpacker 4 looked like for existing Rails apps (please contribute yours!):
131
+
132
+ - https://github.com/connorshea/ContinueFromCheckpoint/pull/77
@@ -38,6 +38,7 @@ environment.config.set('output.filename', '[name].js')
38
38
 
39
39
  // Merge custom config
40
40
  environment.config.merge(customConfig)
41
+ environment.config.merge({ devtool: 'none' })
41
42
 
42
43
  // Delete a property
43
44
  environment.config.delete('output.chunkFilename')
@@ -68,10 +69,13 @@ yarn add json-loader
68
69
  // config/webpack/environment.js
69
70
  const { environment } = require('@rails/webpacker')
70
71
 
71
- environment.loaders.append('json', {
72
+ const jsonLoader = {
72
73
  test: /\.json$/,
73
74
  use: 'json-loader'
74
- })
75
+ }
76
+
77
+ // Insert json loader at the end of list
78
+ environment.loaders.append('json', jsonLoader)
75
79
 
76
80
  // Insert json loader at the top of list
77
81
  environment.loaders.prepend('json', jsonLoader)
@@ -168,8 +172,12 @@ module.exports = {
168
172
  // config/webpack/environment.js
169
173
 
170
174
  const { environment } = require('@rails/webpacker')
175
+ const url = require('./loaders/url')
171
176
 
172
177
  environment.loaders.prepend('url', url)
178
+
179
+ // avoid using both file and url loaders
180
+ environment.loaders.get('file').test = /\.(tiff|ico|svg|eot|otf|ttf|woff|woff2)$/i
173
181
  ```
174
182
 
175
183
  ### Overriding Loader Options in webpack 3+ (for CSS Modules etc.)
@@ -252,7 +260,52 @@ const { environment } = require('@rails/webpacker')
252
260
  environment.resolvedModules.append('vendor', 'vendor')
253
261
  ```
254
262
 
255
- ### Add common chunks
263
+ ### Add SplitChunks (Webpack V4)
264
+ Originally, chunks (and modules imported inside them) were connected by a parent-child relationship in the internal webpack graph. The CommonsChunkPlugin was used to avoid duplicated dependencies across them, but further optimizations were not possible
265
+
266
+ Since webpack v4, the CommonsChunkPlugin was removed in favor of optimization.splitChunks.
267
+
268
+ For the full configuration options of SplitChunks, see the [Webpack documentation](https://webpack.js.org/plugins/split-chunks-plugin/).
269
+
270
+ ```js
271
+ // config/webpack/environment.js
272
+ const WebpackAssetsManifest = require('webpack-assets-manifest');
273
+
274
+ // Enable the default config
275
+ environment.splitChunks()
276
+
277
+ // or using custom config
278
+ environment.splitChunks((config) => Object.assign({}, config, { optimization: { splitChunks: false }}))
279
+ ```
280
+
281
+ Then use, `javascript_packs_with_chunks_tag` helper to include all the transpiled
282
+ packs with the chunks in your view, which creates html tags for all the chunks.
283
+
284
+ ```erb
285
+ <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
286
+
287
+ <script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
288
+ <script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
289
+ <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
290
+ <script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
291
+ <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
292
+ ```
293
+
294
+ **Important:** Pass all your pack names when using this helper otherwise you will
295
+ get duplicated chunks on the page.
296
+
297
+ ```erb
298
+ <%# DO %>
299
+ <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
300
+
301
+ <%# DON'T %>
302
+ <%= javascript_packs_with_chunks_tag 'calendar' %>
303
+ <%= javascript_packs_with_chunks_tag 'map' %>
304
+ ```
305
+
306
+ For the old configuration with the CommonsChunkPlugin see below. **Note** that this functionality is deprecated in Webpack V4.
307
+
308
+ ### Add common chunks (deprecated in Webpack V4)
256
309
 
257
310
  The CommonsChunkPlugin is an opt-in feature that creates a separate file (known as a chunk), consisting of common modules shared between multiple entry points. By separating common modules from bundles, the resulting chunked file can be loaded once initially, and stored in the cache for later use. This results in page speed optimizations as the browser can quickly serve the shared code from the cache, rather than being forced to load a larger bundle whenever a new page is visited.
258
311
 
@@ -1,6 +1,6 @@
1
1
  # Yarn
2
2
 
3
- Webpacker by default uses `yarn` as package manager for node modules
3
+ Webpacker by default uses `yarn` as a package manager for `node_modules`
4
4
 
5
5
 
6
6
  ## Add a new npm module
@@ -10,3 +10,14 @@ To add any new JS module you can use `yarn`:
10
10
  ```bash
11
11
  yarn add bootstrap material-ui
12
12
  ```
13
+
14
+ ## Add an npm module to `devDependencies`
15
+ To add a new JS module that will only be available to local development:
16
+
17
+ ```bash
18
+ yarn add --dev browser-sync
19
+ ```
20
+
21
+ Be careful not to add any build or app related JS modules in this fashion. Adding JS modules to `devDependencies` [will block them from being installed in **any** production environment](https://yarnpkg.com/lang/en/docs/cli/install/#toc-yarn-install-production-true-false).
22
+
23
+ Docs from JS modules may instruct you to use `--dev` or `devDependencies`, but this is generally under the assumption that you are using a `node.js` workflow.
@@ -7,7 +7,7 @@ gem "webpacker", path: ".."
7
7
  gem "rails", github: "rails/rails"
8
8
  gem "arel", github: "rails/arel"
9
9
  gem "rake", ">= 11.1"
10
- gem "rubocop", ">= 0.49", require: false
10
+ gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
11
11
  gem "rack-proxy", require: false
12
12
  gem "minitest", "~> 5.0"
13
13
  gem "byebug"
@@ -2,9 +2,9 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "webpacker", path: ".."
4
4
 
5
- gem "rails", "~> 4.2"
5
+ gem "rails", "~> 4.2.0"
6
6
  gem "rake", ">= 11.1"
7
- gem "rubocop", ">= 0.49", require: false
7
+ gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
8
8
  gem "rack-proxy", require: false
9
9
  gem "minitest", "~> 5.0"
10
10
  gem "byebug"
@@ -2,9 +2,9 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "webpacker", path: ".."
4
4
 
5
- gem "rails", "~> 5.0"
5
+ gem "rails", "~> 5.0.0"
6
6
  gem "rake", ">= 11.1"
7
- gem "rubocop", ">= 0.49", require: false
7
+ gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
8
8
  gem "rack-proxy", require: false
9
9
  gem "minitest", "~> 5.0"
10
10
  gem "byebug"
@@ -2,9 +2,9 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "webpacker", path: ".."
4
4
 
5
- gem "rails", "~> 5.1"
5
+ gem "rails", "~> 5.1.0"
6
6
  gem "rake", ">= 11.1"
7
- gem "rubocop", ">= 0.49", require: false
7
+ gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
8
8
  gem "rack-proxy", require: false
9
9
  gem "minitest", "~> 5.0"
10
10
  gem "byebug"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "webpacker", path: ".."
4
+
5
+ gem "rails", "~> 5.2.0"
6
+ gem "rake", ">= 11.1"
7
+ gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
8
+ gem "rack-proxy", require: false
9
+ gem "minitest", "~> 5.0"
10
+ gem "byebug"
@@ -12,4 +12,8 @@ require "bundler/setup"
12
12
 
13
13
  require "webpacker"
14
14
  require "webpacker/webpack_runner"
15
- Webpacker::WebpackRunner.run(ARGV)
15
+
16
+ APP_ROOT = File.expand_path("..", __dir__)
17
+ Dir.chdir(APP_ROOT) do
18
+ Webpacker::WebpackRunner.run(ARGV)
19
+ end
@@ -12,4 +12,8 @@ require "bundler/setup"
12
12
 
13
13
  require "webpacker"
14
14
  require "webpacker/dev_server_runner"
15
- Webpacker::DevServerRunner.run(ARGV)
15
+
16
+ APP_ROOT = File.expand_path("..", __dir__)
17
+ Dir.chdir(APP_ROOT) do
18
+ Webpacker::DevServerRunner.run(ARGV)
19
+ end
@@ -9,11 +9,11 @@ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
9
9
  after: "require('@rails/webpacker')\n"
10
10
 
11
11
  insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
- "environment.loaders.append('coffee', coffee)\n",
12
+ "environment.loaders.prepend('coffee', coffee)\n",
13
13
  before: "module.exports"
14
14
 
15
15
  say "Updating webpack paths to include .coffee file extension"
16
- insert_into_file Webpacker.config.config_path, " - .coffee\n", after: /extensions:\n/
16
+ insert_into_file Webpacker.config.config_path, "- .coffee\n".indent(4), after: /\s+extensions:\n/
17
17
 
18
18
  say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
19
19
  copy_file "#{__dir__}/examples/coffee/hello_coffee.coffee",
@@ -0,0 +1 @@
1
+ defaults
@@ -0,0 +1,70 @@
1
+ module.exports = function(api) {
2
+ var validEnv = ['development', 'test', 'production']
3
+ var currentEnv = api.env()
4
+ var isDevelopmentEnv = api.env('development')
5
+ var isProductionEnv = api.env('production')
6
+ var isTestEnv = api.env('test')
7
+
8
+ if (!validEnv.includes(currentEnv)) {
9
+ throw new Error(
10
+ 'Please specify a valid `NODE_ENV` or ' +
11
+ '`BABEL_ENV` environment variables. Valid values are "development", ' +
12
+ '"test", and "production". Instead, received: ' +
13
+ JSON.stringify(currentEnv) +
14
+ '.'
15
+ )
16
+ }
17
+
18
+ return {
19
+ presets: [
20
+ isTestEnv && [
21
+ require('@babel/preset-env').default,
22
+ {
23
+ targets: {
24
+ node: 'current'
25
+ }
26
+ }
27
+ ],
28
+ (isProductionEnv || isDevelopmentEnv) && [
29
+ require('@babel/preset-env').default,
30
+ {
31
+ forceAllTransforms: true,
32
+ useBuiltIns: 'entry',
33
+ modules: false,
34
+ exclude: ['transform-typeof-symbol']
35
+ }
36
+ ]
37
+ ].filter(Boolean),
38
+ plugins: [
39
+ require('babel-plugin-macros'),
40
+ require('@babel/plugin-syntax-dynamic-import').default,
41
+ isTestEnv && require('babel-plugin-dynamic-import-node'),
42
+ require('@babel/plugin-transform-destructuring').default,
43
+ [
44
+ require('@babel/plugin-proposal-class-properties').default,
45
+ {
46
+ loose: true
47
+ }
48
+ ],
49
+ [
50
+ require('@babel/plugin-proposal-object-rest-spread').default,
51
+ {
52
+ useBuiltIns: true
53
+ }
54
+ ],
55
+ [
56
+ require('@babel/plugin-transform-runtime').default,
57
+ {
58
+ helpers: false,
59
+ regenerator: true
60
+ }
61
+ ],
62
+ [
63
+ require('@babel/plugin-transform-regenerator').default,
64
+ {
65
+ async: false
66
+ }
67
+ ]
68
+ ].filter(Boolean)
69
+ }
70
+ }