webpacker 6.0.0.rc.2 → 6.0.0.rc.6

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.
data/docs/v6_upgrade.md CHANGED
@@ -10,15 +10,29 @@ Webpacker used to configure Webpack indirectly, which lead to a [complicated sec
10
10
 
11
11
  This means you have to configure integration with frameworks yourself, but webpack-merge helps with this. See this example for [Vue](https://github.com/rails/webpacker#other-frameworks).
12
12
 
13
- ## How to upgrade to Webpacker 6
13
+ ## How to upgrade to Webpacker v6 from v5
14
14
 
15
- 1. If your `source_path` is `app/javascript`, rename it to `app/packs`
16
- 2. If your `source_entry_path` is `packs`, rename it to `entrypoints`
17
- 3. Rename `config/webpack` to `config/webpack_old`
18
- 4. Rename `config/webpacker.yml` to `config/webpacker_old.yml`
19
- 5. Uninstall the current version of `webpack-dev-server`: `yarn remove webpack-dev-server`
20
- 6. Remove .browserslistrc from the root of your Rails app
21
- 7. Upgrade the Webpacker Ruby gem and NPM package
15
+ 1. If you are changing from the v5 default for `source_entry_path`:
16
+ ```yml
17
+ source_path: app/javascript
18
+ source_entry_path: packs
19
+ ```
20
+ to the v6 default:
21
+ ```yml
22
+ source_path: app/javascript
23
+ source_entry_path: /
24
+ ```
25
+ Then move your `app/javascript/packs/*` (including `application.js`) to `app/javascript/`.
26
+
27
+ Check if you had any entry point files in child directories of your `source_entry_path`. Files for entry points in child directories are not supported by rails/webpacker v6.
28
+
29
+ 2. Rename `config/webpack` to `config/webpack_old`
30
+
31
+ 3. Rename `config/webpacker.yml` to `config/webpacker_old.yml`
32
+
33
+ 4. Uninstall the current version of `webpack-dev-server`: `yarn remove webpack-dev-server`
34
+
35
+ 5. Upgrade the Webpacker Ruby gem and NPM package
22
36
 
23
37
  Note: [Check the releases page to verify the latest version](https://github.com/rails/webpacker/releases), and make sure to install identical version numbers of webpacker gem and `@rails/webpacker` npm package. (Gems use a period and packages use a dot between the main version number and the beta version.)
24
38
 
@@ -26,7 +40,7 @@ Example going to a specific version:
26
40
 
27
41
  ```ruby
28
42
  # Gemfile
29
- gem 'webpacker', '6.0.0.rc.2'
43
+ gem 'webpacker', '6.0.0.rc.5'
30
44
  ```
31
45
 
32
46
  ```bash
@@ -34,16 +48,18 @@ Example going to a specific version:
34
48
  ```
35
49
 
36
50
  ```bash
37
- yarn add @rails/webpacker@6.0.0-rc.2 --exact
51
+ yarn add @rails/webpacker@6.0.0-rc.5 --exact
38
52
  ```
39
53
 
40
54
  ```bash
41
55
  bundle exec rails webpacker:install
42
56
  ```
43
57
 
44
- 7. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` or `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/packs/entrypoints/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
45
- 8. If you are using any integrations like `css`, `React` or `TypeScript`. Please see https://github.com/rails/webpacker#integrations section on how they work in v6.
46
- 9. Copy over any custom webpack config from `config/webpack_old`. Common code previously called 'environment' should be changed to 'base', and import `environment` changed to `webpackConfig`.
58
+ 6. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
59
+
60
+ 7. If you are using any integrations like `css`, `React` or `TypeScript`. Please see https://github.com/rails/webpacker#integrations section on how they work in v6.
61
+
62
+ 8. Copy over any custom webpack config from `config/webpack_old`. Common code previously called 'environment' should be changed to 'base', and import `environment` changed to `webpackConfig`.
47
63
 
48
64
  ```js
49
65
  // config/webpack/base.js
@@ -53,23 +69,45 @@ Example going to a specific version:
53
69
  module.exports = merge(webpackConfig, customConfig)
54
70
  ```
55
71
 
56
- 10. Copy over custom browserlist config from `.browserslistrc` if it exists into the `"browserslist"` key in `package.json` and remove `.browserslistrc`.
57
-
58
- 11. Remove `babel.config.js` if you never changed it. Be sure to have this config in your `package.json`:
59
- ```json
60
- "babel": {
61
- "presets": [
62
- "./node_modules/@rails/webpacker/package/babel/preset.js"
63
- ]
64
- }
65
- ```
66
- 12. Remove `postcss.config.js` if you don't use `PostCSS`.
67
- 13. `extensions` was removed from the `webpacker.yml` file. Move custom extensions to your configuration by merging an object like this. For more details, see docs for [Webpack Configuration](https://github.com/rails/webpacker/blob/master/README.md#webpack-configuration)
68
-
69
- ```js
70
- {
71
- resolve: {
72
- extensions: ['.ts', '.tsx', '.vue', '.css']
72
+ 9. Copy over custom browserlist config from `.browserslistrc` if it exists into the `"browserslist"` key in `package.json` and remove `.browserslistrc`.
73
+
74
+ 10. Remove `babel.config.js` if you never changed it. Be sure to have this config in your `package.json`:
75
+
76
+ ```json
77
+ "babel": {
78
+ "presets": [
79
+ "./node_modules/@rails/webpacker/package/babel/preset.js"
80
+ ]
73
81
  }
74
- }
75
- ```
82
+ ```
83
+
84
+ 11. Remove `postcss.config.js` if you don't use `PostCSS`.
85
+
86
+ 12. `extensions` was removed from the `webpacker.yml` file. Move custom extensions to your configuration by merging an object like this. For more details, see docs for [Webpack Configuration](https://github.com/rails/webpacker/blob/master/README.md#webpack-configuration)
87
+
88
+ ```js
89
+ {
90
+ resolve: {
91
+ extensions: ['.ts', '.tsx', '.vue', '.css']
92
+ }
93
+ }
94
+ ```
95
+
96
+ 13. Some dependencies were removed in [PR 3056](https://github.com/rails/webpacker/pull/3056). If you see the error: `Error: Cannot find module 'babel-plugin-macros'`, or similar, then you need to `yarn add <dependency>` where <dependency> might include: `babel-plugin-macros`, `case-sensitive-paths-webpack-plugin`, `core-js`, `regenerator-runtime`. Or you might want to remove your dependency on those.
97
+
98
+ 14. If `bin/yarn` does not exist, create an executable [yarn](https://github.com/rails/webpacker/blob/master/lib/install/bin/yarn) file in your `/bin` directory.
99
+
100
+ 15. Remove overlapping dependencies from your `package.json` and rails/webpacker's `package.json`. For example, don't include `webpack` directly as that's a dependency of rails/webpacker.
101
+
102
+ 16. Review the new default's changes to `webpacker.yml` and `config/webpack`. Consider each suggested change carefully, especially the change to have your `source_entry_path` be at the top level of your `source_path`.
103
+
104
+ 17. Make sure that you can run `bin/webpack` without errors.
105
+
106
+ 18. Try running `RAILS_ENV=production bin/rails assets:precompile`. If all goes well, don't forget to clean the generated assets with `bin/rails assets:clobber`.
107
+
108
+ 19. Try your app!
109
+
110
+ ## Examples of v5 to v6
111
+
112
+ 1. [React on Rails Project with HMR and SSR](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/compare/webpacker-5.x...master)
113
+ 2. [Vue and Sass Example](https://github.com/guillaumebriday/upgrade-webpacker-5-to-6)
@@ -1,19 +1,15 @@
1
1
  /* eslint no-console:0 */
2
2
  // This file is automatically compiled by Webpack, along with any other files
3
3
  // present in this directory. You're encouraged to place your actual application logic in
4
- // a relevant structure within app/packs and only use these pack files to reference
4
+ // a relevant structure within app/javascript and only use these pack files to reference
5
5
  // that code so it'll be compiled.
6
6
  //
7
7
  // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8
8
  // layout file, like app/views/layouts/application.html.erb
9
9
 
10
- // Uncomment to copy all static images under ../images to the output folder and reference
10
+ // Uncomment to copy all static images under ./images to the output folder and reference
11
11
  // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
12
12
  // or the `imagePath` JavaScript helper below.
13
13
  //
14
- // const images = require.context('../images', true)
14
+ // const images = require.context('./images', true)
15
15
  // const imagePath = (name) => images(name, true)
16
-
17
- // Activate Active Storage
18
- // import * as ActiveStorage from "@rails/activestorage"
19
- // ActiveStorage.start()
@@ -1,17 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4
- ENV["NODE_ENV"] ||= "development"
5
-
6
3
  require "pathname"
7
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8
- Pathname.new(__FILE__).realpath)
9
-
10
4
  require "bundler/setup"
11
-
12
5
  require "webpacker"
13
6
  require "webpacker/webpack_runner"
14
7
 
8
+ ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
9
+ ENV["NODE_ENV"] ||= "development"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
11
+
15
12
  APP_ROOT = File.expand_path("..", __dir__)
16
13
  Dir.chdir(APP_ROOT) do
17
14
  Webpacker::WebpackRunner.run(ARGV)
@@ -1,8 +1,8 @@
1
1
  # Note: You must restart bin/webpack-dev-server for changes to take effect
2
2
 
3
3
  default: &default
4
- source_path: app/packs
5
- source_entry_path: entrypoints
4
+ source_path: app/javascript
5
+ source_entry_path: /
6
6
  public_root_path: public
7
7
  public_output_path: packs
8
8
  cache_path: tmp/webpacker
@@ -24,25 +24,28 @@ development:
24
24
  https: false
25
25
  host: localhost
26
26
  port: 3035
27
- public: localhost:3035
28
27
  # Hot Module Replacement updates modules while the application is running without a full reload
29
28
  hmr: false
30
- # Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
31
- overlay: true
29
+ # Defaults to the inverse of hmr. Uncomment to manually set this.
30
+ # live_reload: true
31
+ client:
32
+ # Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
33
+ overlay: true
34
+ # May also be a string
35
+ # webSocketURL:
36
+ # hostname: "0.0.0.0"
37
+ # pathname: "/ws"
38
+ # port: 8080
32
39
  # Should we use gzip compression?
33
40
  compress: true
34
41
  # Note that apps that do not check the host are vulnerable to DNS rebinding attacks
35
- disable_host_check: true
36
- # This option lets the browser open with your local IP
37
- use_local_ip: false
38
- # When enabled, nothing except the initial startup information will be written to the console.
39
- # This also means that errors or warnings from webpack are not visible.
40
- quiet: false
42
+ allowed_hosts: "all"
41
43
  pretty: true
42
44
  headers:
43
45
  'Access-Control-Allow-Origin': '*'
44
- watch_options:
45
- ignored: '**/node_modules/**'
46
+ static:
47
+ watch:
48
+ ignored: '**/node_modules/**'
46
49
 
47
50
  test:
48
51
  <<: *default
@@ -2,8 +2,6 @@
2
2
  "name": "app",
3
3
  "private": true,
4
4
  "dependencies": {
5
- "@rails/activestorage": "latest",
6
- "@rails/actioncable": "latest"
7
5
  },
8
6
  "version": "0.1.0",
9
7
  "babel": {
@@ -9,7 +9,8 @@ if Dir.exists?(Webpacker.config.source_path)
9
9
  say "The packs app source directory already exists"
10
10
  else
11
11
  say "Creating packs app source directory"
12
- directory "#{__dir__}/packs", Webpacker.config.source_path
12
+ empty_directory "app/javascript"
13
+ copy_file "#{__dir__}/application.js", "app/javascript/application.js"
13
14
  end
14
15
 
15
16
  apply "#{__dir__}/binstubs.rb"
@@ -53,6 +54,14 @@ Rails.application.config.assets.paths << Rails.root.join("node_modules")
53
54
  RUBY
54
55
  end
55
56
 
57
+ if (csp_config_path = Rails.root.join("config/initializers/content_security_policy.rb")).exist?
58
+ say "Make note of webpack-dev-server exemption needed to csp"
59
+ insert_into_file csp_config_path, <<-RUBY, after: %(# Rails.application.config.content_security_policy do |policy|)
60
+ # # If you are using webpack-dev-server then specify webpack-dev-server host
61
+ # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
62
+ RUBY
63
+ end
64
+
56
65
  results = []
57
66
 
58
67
  Dir.chdir(Rails.root) do
data/lib/tasks/yarn.rake CHANGED
@@ -5,28 +5,30 @@
5
5
  namespace :yarn do
6
6
  desc "Install all JavaScript dependencies as specified via Yarn"
7
7
  task :install do
8
- # Install only production deps when for not usual envs.
9
- valid_node_envs = %w[test development production]
10
- node_env = ENV.fetch("NODE_ENV") do
11
- valid_node_envs.include?(Rails.env) ? Rails.env : "production"
12
- end
13
-
14
- yarn_flags =
15
- if `#{RbConfig.ruby} "#{Rails.root}/bin/yarn" --version`.start_with?("1")
16
- "--no-progress --frozen-lockfile"
17
- else
18
- "--immutable"
8
+ begin
9
+ # Install only production deps when for not usual envs.
10
+ valid_node_envs = %w[test development production]
11
+ node_env = ENV.fetch("NODE_ENV") do
12
+ valid_node_envs.include?(Rails.env) ? Rails.env : "production"
19
13
  end
20
14
 
21
- system(
22
- { "NODE_ENV" => node_env },
23
- "#{RbConfig.ruby} \"#{Rails.root}/bin/yarn\" install #{yarn_flags}",
24
- exception: true
25
- )
26
- rescue Errno::ENOENT
27
- $stderr.puts "bin/yarn was not found."
28
- $stderr.puts "Please run `bundle exec rails app:update:bin` to create it."
29
- exit 1
15
+ yarn_flags =
16
+ if `#{RbConfig.ruby} "#{Rails.root}/bin/yarn" --version`.start_with?("1")
17
+ "--no-progress --frozen-lockfile"
18
+ else
19
+ "--immutable"
20
+ end
21
+
22
+ system(
23
+ { "NODE_ENV" => node_env },
24
+ "#{RbConfig.ruby} \"#{Rails.root}/bin/yarn\" install #{yarn_flags}",
25
+ exception: true
26
+ )
27
+ rescue Errno::ENOENT
28
+ $stderr.puts "bin/yarn was not found."
29
+ $stderr.puts "Please run `bundle exec rails app:update:bin` to create it."
30
+ exit 1
31
+ end
30
32
  end
31
33
  end
32
34
 
@@ -17,20 +17,21 @@ class Webpacker::Commands
17
17
  #
18
18
  def clean(count = 2, age = 3600)
19
19
  if config.public_output_path.exist? && config.public_manifest_path.exist?
20
- versions
21
- .sort
22
- .reverse
23
- .each_with_index
24
- .drop_while do |(mtime, _), index|
25
- max_age = [0, Time.now - Time.at(mtime)].max
26
- max_age < age || index < count
20
+ packs
21
+ .map do |paths|
22
+ paths.map { |path| [Time.now - File.mtime(path), path] }
23
+ .sort
24
+ .reject.with_index do |(file_age, _), index|
25
+ file_age < age || index < count
26
+ end
27
+ .map { |_, path| path }
27
28
  end
28
- .each do |(_, files), index|
29
- files.each do |file|
30
- if File.file?(file)
31
- File.delete(file)
32
- logger.info "Removed #{file}"
33
- end
29
+ .flatten
30
+ .compact
31
+ .each do |file|
32
+ if File.file?(file)
33
+ File.delete(file)
34
+ logger.info "Removed #{file}"
34
35
  end
35
36
  end
36
37
  end
@@ -54,12 +55,15 @@ class Webpacker::Commands
54
55
  end
55
56
 
56
57
  private
57
- def versions
58
+ def packs
58
59
  all_files = Dir.glob("#{config.public_output_path}/**/*")
59
60
  manifest_config = Dir.glob("#{config.public_manifest_path}*")
60
61
 
61
62
  packs = all_files - manifest_config - current_version
62
- packs.reject { |file| File.directory?(file) }.group_by { |file| File.mtime(file).utc.to_i }
63
+ packs.reject { |file| File.directory?(file) }.group_by do |path|
64
+ base, _, ext = File.basename(path).scan(/(.*)(-[\da-f]+)(\.\w+)/).flatten
65
+ "#{File.dirname(path)}/#{base}#{ext}"
66
+ end.values
63
67
  end
64
68
 
65
69
  def current_version
@@ -65,7 +65,7 @@ module Webpacker
65
65
  def execute_cmd
66
66
  env = Webpacker::Compiler.env
67
67
  env["WEBPACKER_CONFIG"] = @webpacker_config
68
- env["WEBPACK_DEV_SERVER"] = "true"
68
+ env["WEBPACK_SERVE"] = "true"
69
69
 
70
70
  cmd = if node_modules_bin_exist?
71
71
  ["#{@node_modules_bin_path}/webpack", "serve"]
@@ -51,4 +51,11 @@ class Webpacker::Engine < ::Rails::Engine
51
51
  app.config.javascript_path = Webpacker.config.source_path.relative_path_from(Rails.root.join("app")).to_s
52
52
  end
53
53
  end
54
+
55
+ initializer "webpacker.remove_app_packs_from_the_autoload_paths" do
56
+ Rails.application.config.before_initialize do
57
+ source_path = Webpacker.config.source_path.to_s
58
+ ActiveSupport::Dependencies.autoload_paths.delete(source_path)
59
+ end
60
+ end
54
61
  end
@@ -1,4 +1,4 @@
1
1
  module Webpacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "6.0.0.rc.2".freeze
3
+ VERSION = "6.0.0.rc.6".freeze
4
4
  end
@@ -3,6 +3,19 @@ require "webpacker/runner"
3
3
 
4
4
  module Webpacker
5
5
  class WebpackRunner < Webpacker::Runner
6
+ WEBPACK_COMMANDS = [
7
+ "help",
8
+ "h",
9
+ "--help",
10
+ "-h",
11
+ "version",
12
+ "v",
13
+ "--version",
14
+ "-v",
15
+ "info",
16
+ "i"
17
+ ].freeze
18
+
6
19
  def run
7
20
  env = Webpacker::Compiler.env
8
21
  env["WEBPACKER_CONFIG"] = @webpacker_config
@@ -13,17 +26,24 @@ module Webpacker
13
26
  ["yarn", "webpack"]
14
27
  end
15
28
 
16
- if @argv.include?("--debug-webpacker")
17
- cmd = [ "node", "--inspect-brk"] + cmd
18
- @argv.delete "--debug-webpacker"
29
+ if @argv.delete "--debug-webpacker"
30
+ cmd = ["node", "--inspect-brk"] + cmd
31
+ end
32
+
33
+ if @argv.delete "--trace-deprecation"
34
+ cmd = ["node", "--trace-deprecation"] + cmd
35
+ end
36
+
37
+ if @argv.delete "--no-deprecation"
38
+ cmd = ["node", "--no-deprecation"] + cmd
19
39
  end
20
40
 
21
- if @argv.include?("--trace-deprecation")
22
- cmd = [ "node", "--trace-deprecation"] + cmd
23
- @argv.delete "--trace-deprecation"
41
+ # Webpack commands are not compatible with --config option.
42
+ if (@argv & WEBPACK_COMMANDS).empty?
43
+ cmd += ["--config", @webpack_config]
24
44
  end
25
45
 
26
- cmd += ["--config", @webpack_config] + @argv
46
+ cmd += @argv
27
47
 
28
48
  Dir.chdir(@app_path) do
29
49
  Kernel.exec env, *cmd
@@ -11,27 +11,20 @@ describe('Development environment', () => {
11
11
  describe('webpackConfig', () => {
12
12
  beforeEach(() => jest.resetModules())
13
13
 
14
- test('should use development config and environment including devServer if WEBPACK_DEV_SERVER', () => {
14
+ test('should use development config and environment including devServer if WEBPACK_SERVE', () => {
15
15
  process.env.RAILS_ENV = 'development'
16
16
  process.env.NODE_ENV = 'development'
17
- process.env.WEBPACK_DEV_SERVER = 'true'
17
+ process.env.WEBPACK_SERVE = 'true'
18
18
  const { webpackConfig } = require('../index')
19
19
 
20
20
  expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
21
21
  expect(webpackConfig.output.publicPath).toEqual('/packs/')
22
- expect(webpackConfig).toMatchObject({
23
- devServer: {
24
- host: 'localhost',
25
- port: 3035,
26
- injectClient: false
27
- }
28
- })
29
22
  })
30
23
 
31
- test('should use development config and environment if WEBPACK_DEV_SERVER', () => {
24
+ test('should use development config and environment if WEBPACK_SERVE', () => {
32
25
  process.env.RAILS_ENV = 'development'
33
26
  process.env.NODE_ENV = 'development'
34
- process.env.WEBPACK_DEV_SERVER = undefined
27
+ process.env.WEBPACK_SERVE = undefined
35
28
  const { webpackConfig } = require('../index')
36
29
 
37
30
  expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
data/package/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const { resolve } = require('path')
2
- const { safeLoad } = require('js-yaml')
2
+ const { load } = require('js-yaml')
3
3
  const { readFileSync } = require('fs')
4
4
  const { merge } = require('webpack-merge')
5
5
  const { ensureTrailingSlash } = require('./utils/helpers')
@@ -9,12 +9,12 @@ const configPath = require('./configPath')
9
9
  const defaultConfigPath = require.resolve('../lib/install/config/webpacker.yml')
10
10
 
11
11
  const getDefaultConfig = () => {
12
- const defaultConfig = safeLoad(readFileSync(defaultConfigPath), 'utf8')
12
+ const defaultConfig = load(readFileSync(defaultConfigPath), 'utf8')
13
13
  return defaultConfig[railsEnv] || defaultConfig.production
14
14
  }
15
15
 
16
16
  const defaults = getDefaultConfig()
17
- const app = safeLoad(readFileSync(configPath), 'utf8')[railsEnv]
17
+ const app = load(readFileSync(configPath), 'utf8')[railsEnv]
18
18
 
19
19
  const config = merge(defaults, app)
20
20
  config.outputPath = resolve(config.public_root_path, config.public_output_path)
data/package/env.js CHANGED
@@ -1,4 +1,4 @@
1
- const { safeLoad } = require('js-yaml')
1
+ const { load } = require('js-yaml')
2
2
  const { readFileSync } = require('fs')
3
3
 
4
4
  const NODE_ENVIRONMENTS = ['development', 'production', 'test']
@@ -12,14 +12,11 @@ const nodeEnv
12
12
  const isProduction = nodeEnv === 'production'
13
13
  const isDevelopment = nodeEnv === 'development'
14
14
 
15
- const config = safeLoad(readFileSync(configPath), 'utf8')
15
+ const config = load(readFileSync(configPath), 'utf8')
16
16
  const availableEnvironments = Object.keys(config).join('|')
17
17
  const regex = new RegExp(`^(${availableEnvironments})$`, 'g')
18
18
 
19
- // v4 of webpack-dev-server will switch to WEBPACK_DEV_SERVE
20
- // https://github.com/rails/webpacker/issues/3057
21
- const runningWebpackDevServer = process.env.WEBPACK_DEV_SERVER === 'true' ||
22
- process.env.WEBPACK_DEV_SERVE === 'true'
19
+ const runningWebpackDevServer = process.env.WEBPACK_SERVE === 'true'
23
20
 
24
21
  module.exports = {
25
22
  railsEnv: railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT,
@@ -16,7 +16,7 @@ const getEntryObject = () => {
16
16
  const entries = {}
17
17
  const rootPath = join(config.source_path, config.source_entry_path)
18
18
 
19
- globSync(`${rootPath}/**/*.*`).forEach((path) => {
19
+ globSync(`${rootPath}/*.*`).forEach((path) => {
20
20
  const namespace = relative(join(rootPath), dirname(path))
21
21
  const name = join(namespace, basename(path, extname(path)))
22
22
  let assetPaths = resolve(path)
@@ -12,41 +12,43 @@ let devConfig = {
12
12
  }
13
13
 
14
14
  if (runningWebpackDevServer) {
15
- if (devServer.hmr) {
16
- devConfig = merge(devConfig, {
17
- output: { filename: '[name]-[hash].js' }
18
- })
15
+ const liveReload = devServer.live_reload !== undefined ? devServer.live_reload : !devServer.hmr
16
+
17
+ const devServerConfig = {
18
+ devMiddleware: {
19
+ publicPath
20
+ },
21
+ compress: devServer.compress,
22
+ allowedHosts: devServer.allowed_hosts,
23
+ host: devServer.host,
24
+ port: devServer.port,
25
+ https: devServer.https,
26
+ hot: devServer.hmr,
27
+ liveReload,
28
+ historyApiFallback: { disableDotRule: true },
29
+ headers: devServer.headers,
30
+ static: {
31
+ publicPath: contentBase
32
+ }
33
+ }
34
+
35
+ if (devServer.static) {
36
+ devServerConfig.static = { ...devServerConfig.static, ...devServer.static }
37
+ }
38
+
39
+ if (devServer.client) {
40
+ devServerConfig.client = devServer.client
19
41
  }
20
42
 
21
43
  devConfig = merge(devConfig, {
22
- devServer: {
23
- clientLogLevel: 'none',
24
- compress: devServer.compress,
25
- quiet: devServer.quiet,
26
- disableHostCheck: devServer.disable_host_check,
27
- host: devServer.host,
28
- port: devServer.port,
29
- https: devServer.https,
30
- hot: devServer.hmr,
31
- contentBase,
32
- inline: devServer.inline || devServer.hmr,
33
- injectClient: devServer.hmr,
34
- injectHot: devServer.hmr,
35
- useLocalIp: devServer.use_local_ip,
36
- public: devServer.public,
37
- publicPath,
38
- historyApiFallback: { disableDotRule: true },
39
- headers: devServer.headers,
40
- overlay: devServer.overlay,
41
- stats: {
42
- colors: true,
43
- entrypoints: false,
44
- errorDetails: true,
45
- modules: false,
46
- moduleTrace: false
47
- },
48
- watchOptions: devServer.watch_options
49
- }
44
+ stats: {
45
+ colors: true,
46
+ entrypoints: false,
47
+ errorDetails: true,
48
+ modules: false,
49
+ moduleTrace: false
50
+ },
51
+ devServer: devServerConfig
50
52
  })
51
53
  }
52
54
 
@@ -18,6 +18,6 @@ module.exports = {
18
18
  exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
19
19
  type: 'asset/resource',
20
20
  generator: {
21
- filename: 'static/[hash][ext][query]'
21
+ filename: 'static/[name]-[hash][ext][query]'
22
22
  }
23
23
  }