webpacker 4.0.7 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.node-version +1 -1
  3. data/.rubocop.yml +2 -1
  4. data/.travis.yml +7 -4
  5. data/CHANGELOG.md +212 -137
  6. data/Gemfile.lock +78 -59
  7. data/README.md +110 -3
  8. data/docs/css.md +12 -0
  9. data/docs/deployment.md +38 -9
  10. data/docs/docker.md +25 -6
  11. data/docs/engines.md +40 -3
  12. data/docs/es6.md +19 -1
  13. data/docs/troubleshooting.md +37 -9
  14. data/docs/typescript.md +8 -5
  15. data/docs/webpack-dev-server.md +1 -1
  16. data/docs/webpack.md +18 -3
  17. data/gemfiles/Gemfile-rails.6.0.x +9 -0
  18. data/lib/install/bin/webpack +0 -1
  19. data/lib/install/bin/webpack-dev-server +0 -1
  20. data/lib/install/coffee.rb +1 -1
  21. data/lib/install/config/babel.config.js +10 -10
  22. data/lib/install/config/webpacker.yml +2 -1
  23. data/lib/install/elm.rb +1 -1
  24. data/lib/install/erb.rb +2 -2
  25. data/lib/install/examples/angular/hello_angular/polyfills.ts +2 -2
  26. data/lib/install/examples/react/babel.config.js +16 -14
  27. data/lib/install/examples/svelte/app.svelte +11 -0
  28. data/lib/install/examples/svelte/hello_svelte.js +20 -0
  29. data/lib/install/loaders/elm.js +9 -6
  30. data/lib/install/loaders/svelte.js +9 -0
  31. data/lib/install/loaders/typescript.js +1 -1
  32. data/lib/install/svelte.rb +29 -0
  33. data/lib/install/typescript.rb +1 -1
  34. data/lib/install/vue.rb +1 -1
  35. data/lib/tasks/installers.rake +1 -0
  36. data/lib/tasks/webpacker.rake +2 -0
  37. data/lib/tasks/webpacker/clean.rake +15 -0
  38. data/lib/tasks/webpacker/compile.rake +1 -1
  39. data/lib/tasks/webpacker/yarn_install.rake +15 -0
  40. data/lib/webpacker.rb +1 -1
  41. data/lib/webpacker/commands.rb +26 -0
  42. data/lib/webpacker/compiler.rb +15 -8
  43. data/lib/webpacker/configuration.rb +9 -1
  44. data/lib/webpacker/dev_server.rb +1 -1
  45. data/lib/webpacker/dev_server_proxy.rb +2 -8
  46. data/lib/webpacker/helper.rb +39 -13
  47. data/lib/webpacker/railtie.rb +4 -0
  48. data/lib/webpacker/version.rb +1 -1
  49. data/package.json +36 -36
  50. data/package/__tests__/config.js +0 -23
  51. data/package/config.js +2 -10
  52. data/package/config_types/config_list.js +3 -3
  53. data/package/config_types/config_object.js +1 -1
  54. data/package/environments/base.js +2 -2
  55. data/package/environments/development.js +1 -1
  56. data/package/environments/production.js +12 -0
  57. data/package/rules/babel.js +1 -1
  58. data/package/rules/node_modules.js +2 -2
  59. data/package/rules/sass.js +1 -1
  60. data/package/utils/__tests__/get_style_rule.js +9 -0
  61. data/package/utils/deep_merge.js +5 -5
  62. data/package/utils/get_style_rule.js +7 -12
  63. data/package/utils/helpers.js +9 -9
  64. data/test/command_test.rb +6 -0
  65. data/test/compiler_test.rb +5 -6
  66. data/test/configuration_test.rb +36 -27
  67. data/test/dev_server_test.rb +22 -0
  68. data/test/helper_test.rb +34 -0
  69. data/test/rake_tasks_test.rb +6 -0
  70. data/test/test_app/bin/webpack +0 -1
  71. data/test/test_app/bin/webpack-dev-server +0 -1
  72. data/test/test_app/config/webpacker.yml +1 -0
  73. data/test/test_app/public/packs/manifest.json +3 -0
  74. data/webpacker.gemspec +1 -0
  75. data/yarn.lock +1934 -1634
  76. metadata +24 -4
@@ -18,18 +18,37 @@ services:
18
18
  - '3035:3035'
19
19
  ```
20
20
 
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
+
21
30
  add nodejs and yarn as dependencies in Dockerfile,
22
31
 
23
32
  ```dockerfile
24
33
  FROM ruby:2.4.1
25
- RUN apt-get update -qq
26
34
 
27
- RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
28
- RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
29
- RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
35
+ RUN apt-get update -qq && apt-get install -y build-essential nodejs \
36
+ && rm -rf /var/lib/apt/lists/* \
37
+ && curl -o- -L https://yarnpkg.com/install.sh | bash
38
+
39
+ # Rest of the commands....
40
+ ```
41
+
42
+ Please note: if using `assets:precompile` in the Dockerfile or have issues with the snippet above then try:
43
+
44
+ ```dockerfile
45
+ FROM ruby:2.4.1
30
46
 
31
- RUN apt-get install -y nodejs
32
- RUN apt-get update && apt-get install -y yarn
47
+ RUN curl -sL https://deb.nodesource.com/setup_8.x | bash \
48
+ && apt-get update && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/* \
49
+ && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
50
+ && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
51
+ && apt-get update && apt-get install -y yarn && rm -rf /var/lib/apt/lists/*
33
52
 
34
53
  # Rest of the commands....
35
54
  ```
@@ -9,7 +9,7 @@ This guide describes how to do that using [Rails engines](https://guides.rubyonr
9
9
 
10
10
  ## Step 1: create Rails engine.
11
11
 
12
- First, you create a Rails engine (say, `MyEngine`). See the offical [Rails guide](https://guides.rubyonrails.org/engines.html).
12
+ First, you create a Rails engine (say, `MyEngine`). See the official [Rails guide](https://guides.rubyonrails.org/engines.html).
13
13
 
14
14
  ## Step 2: install Webpacker within the engine.
15
15
 
@@ -99,9 +99,18 @@ Now you can use `stylesheet_pack_tag` and `javascript_pack_tag` from within your
99
99
 
100
100
  Add Rake task to compile assets in production (`rake my_engine:webpacker:compile`)
101
101
 
102
- - File `lib/tasks/my_engine_tasks.rake`
102
+ - File `my_engine_rootlib/tasks/my_engine_tasks.rake`
103
103
 
104
104
  ```ruby
105
+ def ensure_log_goes_to_stdout
106
+ old_logger = Webpacker.logger
107
+ Webpacker.logger = ActiveSupport::Logger.new(STDOUT)
108
+ yield
109
+ ensure
110
+ Webpacker.logger = old_logger
111
+ end
112
+
113
+
105
114
  namespace :my_engine do
106
115
  namespace :webpacker do
107
116
  desc "Install deps with yarn"
@@ -114,16 +123,44 @@ namespace :my_engine do
114
123
  desc "Compile JavaScript packs using webpack for production with digests"
115
124
  task compile: [:yarn_install, :environment] do
116
125
  Webpacker.with_node_env("production") do
126
+ ensure_log_goes_to_stdout do
117
127
  if MyEngine.webpacker.commands.compile
118
128
  # Successful compilation!
119
129
  else
120
130
  # Failed compilation
121
131
  exit!
122
132
  end
133
+ end
123
134
  end
124
135
  end
125
136
  end
126
137
  end
138
+
139
+ def yarn_install_available?
140
+ rails_major = Rails::VERSION::MAJOR
141
+ rails_minor = Rails::VERSION::MINOR
142
+
143
+ rails_major > 5 || (rails_major == 5 && rails_minor >= 1)
144
+ end
145
+
146
+ def enhance_assets_precompile
147
+ # yarn:install was added in Rails 5.1
148
+ deps = yarn_install_available? ? [] : ["my_engine:webpacker:yarn_install"]
149
+ Rake::Task["assets:precompile"].enhance(deps) do
150
+ Rake::Task["my_engine:webpacker:compile"].invoke
151
+ end
152
+ end
153
+
154
+ # Compile packs after we've compiled all other assets during precompilation
155
+ skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
156
+
157
+ unless skip_webpacker_precompile
158
+ if Rake::Task.task_defined?("assets:precompile")
159
+ enhance_assets_precompile
160
+ else
161
+ Rake::Task.define_task("assets:precompile" => "my_engine:webpacker:compile")
162
+ end
163
+ end
127
164
  ```
128
165
 
129
166
  ## Step 7: serving compiled packs.
@@ -155,7 +192,7 @@ To serve static assets from the engine's `public/` folder you must add a middlew
155
192
  # application.rb
156
193
 
157
194
  config.middleware.use(
158
- "Rack::Static",
195
+ Rack::Static,
159
196
  urls: ["/my-engine-packs"], root: "my_engine/public"
160
197
  )
161
198
  ```
@@ -1,6 +1,5 @@
1
1
  # ES6
2
2
 
3
-
4
3
  ## Babel
5
4
 
6
5
  Webpacker ships with [babel](https://babeljs.io/) - a JavaScript compiler so
@@ -26,6 +25,25 @@ import "core-js/stable";
26
25
  import "regenerator-runtime/runtime";
27
26
  ```
28
27
 
28
+ ## Dynamic/Lazy Chunk Loading
29
+
30
+ For this section, you need Webpack and Webpacker 4. Then enable `SplitChunks` as it is explained in [docs/webpack](webpack.md).
31
+
32
+ [Dynamic code splitting](https://webpack.js.org/guides/code-splitting#dynamic-imports) enables you to conditionally request/run only the JS that you need. For example, if your site has a `searchBarComponent` on every page, you can reduce the page overhead by deferring the request for the `searchBarComponent` code until after the page has loaded, until the user has scrolled it into view, or until the user has clicked on an element.
33
+
34
+ ```js
35
+ function loadSearchBarComponent() {
36
+ return import(/* webpackChunkName: "searchBarComponent" */ './pathTo/searchBarComponent')
37
+ }
38
+ ```
39
+
40
+ The comment you see above (`/* webpackChunkName */`) is not arbitrary, it is one of webpacks [magic comments](https://webpack.js.org/api/module-methods/#magic-comments). They can be used to fine-tune `import()` with settings such as `defer` or `prefetch`.
41
+
42
+ **Warning**: You should not attempt to dynamically load anything from your `packs/` folder. Instead, try to make your `pack` scripts a hub from which you dynamically load `non-pack` scripts.
43
+
44
+ - [Docs for using magic comments](https://webpack.js.org/api/module-methods/#magic-comments)
45
+ - [Docs for configuring `splitChunks` in webpacker](https://github.com/rails/webpacker/blob/master/docs/webpack.md#add-splitchunks-webpack-v4).
46
+ - [Docs for using dynamic `import()`](https://webpack.js.org/guides/code-splitting#dynamic-imports).
29
47
 
30
48
  ## Module import vs require()
31
49
 
@@ -4,22 +4,36 @@
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`.
8
8
  If you have a node debugger installed, you'll see the Chrome debugger for your webpack
9
- config. For example, install the Chrome extension [NiM](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj) and
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
12
 
13
13
  ## ENOENT: no such file or directory - node-sass
14
14
 
15
- * If you get this error `ENOENT: no such file or directory - node-sass` on Heroku
16
- or elsewhere during `assets:precompile` or `bundle exec rails webpacker:compile`
17
- then you would need to rebuild node-sass. It's a bit of a weird error;
18
- basically, it can't find the `node-sass` binary.
19
- An easy solution is to create a postinstall hook - `npm rebuild node-sass` in
20
- `package.json` and that will ensure `node-sass` is rebuilt whenever
21
- you install any new modules.
15
+ If you get the error `ENOENT: no such file or directory - node-sass` on deploy with
16
+ `assets:precompile` or `bundle exec rails webpacker:compile` you may need to
17
+ move Sass to production `dependencies`.
22
18
 
19
+ Move any packages that related to Sass (e.g. `node-sass` or `sass-loader`) from
20
+ `devDependencies` to `dependencies` in `package.json`. This is because
21
+ webpacker is running on a production system with the Rails workflow to build
22
+ the assets. Particularly on hosting providers that try to detect and do the right
23
+ thing, like Heroku.
24
+
25
+ However, if you get this on local development, or not during a deploy then you
26
+ may need to rebuild `node-sass`. It's a bit of a weird error; basically, it
27
+ can't find the `node-sass` binary. An easy solution is to create a postinstall
28
+ hook to ensure `node-sass` is rebuilt whenever new modules are installed.
29
+
30
+ In `package.json`:
31
+
32
+ ```json
33
+ "scripts": {
34
+ "postinstall": "npm rebuild node-sass"
35
+ }
36
+ ```
23
37
 
24
38
  ## Can't find hello_react.js in manifest.json
25
39
 
@@ -126,3 +140,17 @@ environment.plugins.append('ContextReplacement',
126
140
  )
127
141
  )
128
142
  ```
143
+
144
+ ### Compilation Fails Silently
145
+
146
+ If compiling is not producing output files and there are no error messages to help troubleshoot. Setting the webpack_compile_output configuration variable to 'true' in webpacker.yml may add some helpful error information to your log file (Rails log/development.log or log/production.log)
147
+
148
+ ```yml
149
+ # webpacker.yml
150
+ default: &default
151
+ source_path: app/javascript
152
+ source_entry_path: packs
153
+ public_root_path: public
154
+ public_output_path: complaints_packs
155
+ webpack_compile_output: true
156
+ ```
@@ -15,14 +15,15 @@ now you can use typescript, JSX with React.
15
15
 
16
16
  ## Typescript with Vue components
17
17
 
18
- 1. Setup vue using Webpacker [vue installer](../README.md#vue). Then run the typescript installer
18
+ 1. Setup Vue using the Webpacker [Vue installer](../README.md#vue). Then run the TypeScript installer
19
19
 
20
20
  ```bash
21
21
  bundle exec rails webpacker:install:typescript
22
22
  ```
23
23
 
24
24
  2. Rename generated `hello_vue.js` to `hello_vue.ts`.
25
- 3. Change generated `config/webpack/loaders/typescript.js` from
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
26
27
 
27
28
  ```js
28
29
  module.exports = {
@@ -36,18 +37,20 @@ module.exports = {
36
37
  to
37
38
 
38
39
  ```js
40
+ const PnpWebpackPlugin = require('pnp-webpack-plugin');
41
+
39
42
  module.exports = {
40
43
  test: /\.(ts|tsx)?(\.erb)?$/,
41
44
  use: [{
42
45
  loader: 'ts-loader',
43
- options: {
46
+ options: PnpWebpackPlugin.tsLoaderOptions({
44
47
  appendTsSuffixTo: [/\.vue$/]
45
- }
48
+ })
46
49
  }]
47
50
  }
48
51
  ```
49
52
 
50
- and now you can use `<script lang="ts">` in your `.vue` component files.
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.
51
54
 
52
55
  ## HTML templates with Typescript and Angular
53
56
 
@@ -38,7 +38,7 @@ If you use Nginx in development to proxy requests to your Rails server from
38
38
  another domain, like `myapp.dev`, the Webpacker middleware will be able to
39
39
  forward requests for "packs" to the webpack dev server.
40
40
 
41
- If you're using `inline` mode behing Nginx, you may also need to provide the
41
+ If you're using `inline` mode behind Nginx, you may also need to provide the
42
42
  hostname to webpack dev server so it can initiate the websocket connection for
43
43
  live reloading ([Webpack
44
44
  docs](https://webpack.js.org/configuration/dev-server/#devserver-public)).
@@ -189,9 +189,10 @@ const { environment } = require('@rails/webpacker')
189
189
  const merge = require('webpack-merge')
190
190
 
191
191
  const myCssLoaderOptions = {
192
- modules: true,
192
+ modules: {
193
+ localIdentName: '[name]__[local]___[hash:base64:5]'
194
+ },
193
195
  sourceMap: true,
194
- localIdentName: '[name]__[local]___[hash:base64:5]'
195
196
  }
196
197
 
197
198
  const CSSLoader = environment.loaders.get('sass').use.find(el => el.loader === 'css-loader')
@@ -277,7 +278,7 @@ environment.splitChunks()
277
278
  environment.splitChunks((config) => Object.assign({}, config, { optimization: { splitChunks: false }}))
278
279
  ```
279
280
 
280
- Then use, `javascript_packs_with_chunks_tag` helper to include all the transpiled
281
+ Then use the `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` helpers to include all the transpiled
281
282
  packs with the chunks in your view, which creates html tags for all the chunks.
282
283
 
283
284
  ```erb
@@ -304,6 +305,20 @@ get duplicated chunks on the page.
304
305
 
305
306
  For the old configuration with the CommonsChunkPlugin see below. **Note** that this functionality is deprecated in Webpack V4.
306
307
 
308
+ #### Preloading
309
+
310
+ Before preload or prefetch your assets, please read [https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content](https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content).
311
+
312
+ Webpack also provide it's own methods for preload or prefetch [https://medium.com/webpack/link-rel-prefetch-preload-in-webpack-51a52358f84c](https://medium.com/webpack/link-rel-prefetch-preload-in-webpack-51a52358f84c).
313
+
314
+ You can preload your assets with the `preload_pack_asset` helper if you have Rails >= 5.2.x.
315
+
316
+ ```erb
317
+ <%= preload_pack_asset 'fonts/fa-regular-400.woff2' %>
318
+ ```
319
+
320
+ **Warning:** You don't want to preload the css, you want to preload the fonts and images inside the css so that fonts, css, and images can all be downloaded in parallel instead of waiting for the browser to parse the css.
321
+
307
322
  ### Add common chunks (deprecated in Webpack V4)
308
323
 
309
324
  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.
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "rails", "~> 6.0.0.rc2"
6
+ gem "rake", ">= 11.1"
7
+ gem "rack-proxy", require: false
8
+ gem "minitest", "~> 5.0"
9
+ gem "byebug"
@@ -7,7 +7,6 @@ require "pathname"
7
7
  ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8
8
  Pathname.new(__FILE__).realpath)
9
9
 
10
- require "rubygems"
11
10
  require "bundler/setup"
12
11
 
13
12
  require "webpacker"
@@ -7,7 +7,6 @@ require "pathname"
7
7
  ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8
8
  Pathname.new(__FILE__).realpath)
9
9
 
10
- require "rubygems"
11
10
  require "bundler/setup"
12
11
 
13
12
  require "webpacker"
@@ -6,7 +6,7 @@ copy_file "#{__dir__}/loaders/coffee.js", Rails.root.join("config/webpack/loader
6
6
  say "Adding coffee loader to config/webpack/environment.js"
7
7
  insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8
8
  "const coffee = require('./loaders/coffee')\n",
9
- after: "require('@rails/webpacker')\n"
9
+ after: /require\(('|")@rails\/webpacker\1\);?\n/
10
10
 
11
11
  insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
12
  "environment.loaders.prepend('coffee', coffee)\n",
@@ -18,7 +18,7 @@ module.exports = function(api) {
18
18
  return {
19
19
  presets: [
20
20
  isTestEnv && [
21
- require('@babel/preset-env').default,
21
+ '@babel/preset-env',
22
22
  {
23
23
  targets: {
24
24
  node: 'current'
@@ -26,7 +26,7 @@ module.exports = function(api) {
26
26
  }
27
27
  ],
28
28
  (isProductionEnv || isDevelopmentEnv) && [
29
- require('@babel/preset-env').default,
29
+ '@babel/preset-env',
30
30
  {
31
31
  forceAllTransforms: true,
32
32
  useBuiltIns: 'entry',
@@ -37,24 +37,24 @@ module.exports = function(api) {
37
37
  ]
38
38
  ].filter(Boolean),
39
39
  plugins: [
40
- require('babel-plugin-macros'),
41
- require('@babel/plugin-syntax-dynamic-import').default,
42
- isTestEnv && require('babel-plugin-dynamic-import-node'),
43
- require('@babel/plugin-transform-destructuring').default,
40
+ 'babel-plugin-macros',
41
+ '@babel/plugin-syntax-dynamic-import',
42
+ isTestEnv && 'babel-plugin-dynamic-import-node',
43
+ '@babel/plugin-transform-destructuring',
44
44
  [
45
- require('@babel/plugin-proposal-class-properties').default,
45
+ '@babel/plugin-proposal-class-properties',
46
46
  {
47
47
  loose: true
48
48
  }
49
49
  ],
50
50
  [
51
- require('@babel/plugin-proposal-object-rest-spread').default,
51
+ '@babel/plugin-proposal-object-rest-spread',
52
52
  {
53
53
  useBuiltIns: true
54
54
  }
55
55
  ],
56
56
  [
57
- require('@babel/plugin-transform-runtime').default,
57
+ '@babel/plugin-transform-runtime',
58
58
  {
59
59
  helpers: false,
60
60
  regenerator: true,
@@ -62,7 +62,7 @@ module.exports = function(api) {
62
62
  }
63
63
  ],
64
64
  [
65
- require('@babel/plugin-transform-regenerator').default,
65
+ '@babel/plugin-transform-regenerator',
66
66
  {
67
67
  async: false
68
68
  }
@@ -7,7 +7,7 @@ default: &default
7
7
  public_output_path: packs
8
8
  cache_path: tmp/cache/webpacker
9
9
  check_yarn_integrity: false
10
- webpack_compile_output: false
10
+ webpack_compile_output: true
11
11
 
12
12
  # Additional paths webpack should lookup modules
13
13
  # ['app/assets', 'engine/foo/app/assets']
@@ -69,6 +69,7 @@ development:
69
69
  disable_host_check: true
70
70
  use_local_ip: false
71
71
  quiet: false
72
+ pretty: false
72
73
  headers:
73
74
  'Access-Control-Allow-Origin': '*'
74
75
  watch_options:
@@ -6,7 +6,7 @@ copy_file "#{__dir__}/loaders/elm.js", Rails.root.join("config/webpack/loaders/e
6
6
  say "Adding elm loader to config/webpack/environment.js"
7
7
  insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8
8
  "const elm = require('./loaders/elm')\n",
9
- after: "require('@rails/webpacker')\n"
9
+ after: /require\(('|")@rails\/webpacker\1\);?\n/
10
10
 
11
11
  insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
12
  "environment.loaders.prepend('elm', elm)\n",
@@ -5,8 +5,8 @@ copy_file "#{__dir__}/loaders/erb.js", Rails.root.join("config/webpack/loaders/e
5
5
 
6
6
  say "Adding erb loader to config/webpack/environment.js"
7
7
  insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8
- "const erb = require('./loaders/erb')\n",
9
- after: "require('@rails/webpacker')\n"
8
+ "const erb = require('./loaders/erb')\n",
9
+ after: /require\(('|")@rails\/webpacker\1\);?\n/
10
10
 
11
11
  insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
12
  "environment.loaders.prepend('erb', erb)\n",