Skip to content

Commit 2805d9d

Browse files
committed
Add Webpacker 3 test app
1 parent 253ccde commit 2805d9d

File tree

21 files changed

+1071
-2070
lines changed

21 files changed

+1071
-2070
lines changed

test/dummy_webpacker3/.babelrc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"presets": [
3-
[
4-
"env",
5-
{
6-
"modules": false,
7-
"targets": {
8-
"browsers": "> 1%",
9-
"uglify": true
10-
},
11-
"useBuiltIns": true
12-
}
13-
],
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": "> 1%",
7+
"uglify": true
8+
},
9+
"useBuiltIns": true
10+
}],
1411
"react"
12+
],
13+
14+
"plugins": [
15+
"syntax-dynamic-import",
16+
["transform-class-properties", { "spec": true }]
1517
]
1618
}

test/dummy_webpacker3/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/public/packs
2+
/node_modules

test/dummy_webpacker3/app/javascript/packs/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var ctx = require.context("components", true)
2-
var ReactRailsUJS = require("../../../../../react_ujs/index")
2+
var ReactRailsUJS = require("react_ujs")
33
ReactRailsUJS.useContext(ctx)
44
var React = require("react")
55

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// By default, this pack is loaded for server-side rendering.
22
// It must expose react_ujs as `ReactRailsUJS` and prepare a require context.
33
var componentRequireContext = require.context("components", true)
4-
var ReactRailsUJS = require("../../../../../react_ujs/index")
4+
var ReactRailsUJS = require("react_ujs")
55
ReactRailsUJS.useContext(componentRequireContext)

test/dummy_webpacker3/bin/webpack

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,17 @@ RAILS_ENV = ENV["RAILS_ENV"]
1010
ENV["NODE_ENV"] ||= RAILS_ENV
1111
NODE_ENV = ENV["NODE_ENV"]
1212

13-
APP_PATH = File.expand_path("../", __dir__)
13+
APP_PATH = File.expand_path("../", __dir__)
14+
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
15+
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js")
1416

15-
def load_yaml_config(config_file)
16-
YAML.load_file(File.join(APP_PATH, config_file))[NODE_ENV]
17-
rescue Errno::ENOENT, NoMethodError
18-
puts "Configuration not found in #{config_file}."
17+
unless File.exist?(WEBPACK_CONFIG)
18+
puts "Webpack configuration not found."
1919
puts "Please run bundle exec rails webpacker:install to install webpacker"
2020
exit!
2121
end
2222

23-
paths = load_yaml_config("config/webpack/paths.yml")
24-
NODE_MODULES_PATH = File.join(APP_PATH, paths["node_modules"])
25-
WEBPACK_CONFIG = File.join(APP_PATH, paths["config"], "#{NODE_ENV}.js")
26-
27-
newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
23+
newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
2824
cmdline = ["yarn", "run", "webpack", "--", "--config", WEBPACK_CONFIG] + ARGV
2925

3026
Dir.chdir(APP_PATH) do

test/dummy_webpacker3/bin/webpack-dev-server

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,32 @@ RAILS_ENV = ENV["RAILS_ENV"]
1010
ENV["NODE_ENV"] ||= RAILS_ENV
1111
NODE_ENV = ENV["NODE_ENV"]
1212

13-
APP_PATH = File.expand_path("../", __dir__)
13+
APP_PATH = File.expand_path("../", __dir__)
14+
CONFIG_FILE = File.join(APP_PATH, "config/webpacker.yml")
15+
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
16+
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/development.js")
17+
18+
def args(key)
19+
index = ARGV.index(key)
20+
index ? ARGV[index + 1] : nil
21+
end
22+
23+
begin
24+
dev_server = YAML.load_file(CONFIG_FILE)["development"]["dev_server"]
25+
26+
DEV_SERVER_HOST = "http#{"s" if args('--https') || dev_server["https"]}://#{args('--host') || dev_server["host"]}:#{args('--port') || dev_server["port"]}"
1427

15-
def load_yaml_config(config_file)
16-
YAML.load_file(File.join(APP_PATH, config_file))[NODE_ENV]
1728
rescue Errno::ENOENT, NoMethodError
18-
puts "Configuration not found in #{config_file}."
29+
puts "Webpack dev_server configuration not found in #{CONFIG_FILE}."
1930
puts "Please run bundle exec rails webpacker:install to install webpacker"
2031
exit!
2132
end
2233

23-
paths = load_yaml_config("config/webpack/paths.yml")
24-
NODE_MODULES_PATH = File.join(APP_PATH, paths["node_modules"])
25-
WEBPACK_CONFIG = File.join(APP_PATH, paths["config"], "development.server.js")
26-
27-
dev_server = load_yaml_config("config/webpack/development.server.yml")
28-
DEV_SERVER_HOST = "http#{"s" if dev_server["https"]}://#{dev_server["host"]}:#{dev_server["port"]}"
34+
newenv = {
35+
"NODE_PATH" => NODE_MODULES_PATH.shellescape,
36+
"ASSET_HOST" => DEV_SERVER_HOST.shellescape
37+
}.freeze
2938

30-
newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape, "ASSET_HOST" => DEV_SERVER_HOST.shellescape }
3139
cmdline = ["yarn", "run", "webpack-dev-server", "--", "--progress", "--color", "--config", WEBPACK_CONFIG] + ARGV
3240

3341
Dir.chdir(APP_PATH) do

test/dummy_webpacker3/config/application.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
require "action_controller/railtie"
66
require "action_mailer/railtie"
77

8-
# Test no-sprockets environment by testing the gemfile name
9-
if SprocketsHelpers.available?
10-
require "sprockets/railtie"
11-
end
12-
138
require "rails/test_unit/railtie"
149

1510
# Make sure gems in development group are required, for example, react-rails and turbolinks.
@@ -35,9 +30,5 @@ class Application < Rails::Application
3530
config.react.server_renderer_options = {
3631
replay_console: true,
3732
}
38-
39-
if SprocketsHelpers.available?
40-
config.assets.enabled = true
41-
end
4233
end
4334
end

test/dummy_webpacker3/config/environments/development.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,4 @@
1818

1919
# Print deprecation notices to the Rails logger.
2020
config.active_support.deprecation = :log
21-
22-
# Debug mode disables concatenation and preprocessing of assets.
23-
# This option may cause significant delays in view rendering with a large
24-
# number of complex assets.
25-
config.assets.debug = true
2621
end

test/dummy_webpacker3/config/environments/test.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
# we need this to reload the jsx transformer when different version is dropped in
1010
config.cache_classes = false
1111
config.reload_plugins = true
12-
if SprocketsHelpers.available?
13-
config.assets.cache_store = :null_store
14-
end
1512

1613
# Do not eager load code on boot. This avoids loading your whole application
1714
# just for the purpose of running a single test. If you are using a tool that
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
// Common configuration for webpacker loaded from config/webpack/paths.yml
1+
// Common configuration for webpacker loaded from config/webpacker.yml
22

33
const { join, resolve } = require('path')
44
const { env } = require('process')
55
const { safeLoad } = require('js-yaml')
66
const { readFileSync } = require('fs')
77

8-
const configPath = resolve('config', 'webpack')
8+
const configPath = resolve('config', 'webpacker.yml')
99
const loadersDir = join(__dirname, 'loaders')
10-
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV]
11-
const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))[env.NODE_ENV]
10+
const settings = safeLoad(readFileSync(configPath), 'utf8')[env.NODE_ENV]
1211

1312
function removeOuterSlashes(string) {
1413
return string.replace(/^\/*/, '').replace(/\/*$/, '')
@@ -24,14 +23,13 @@ function formatPublicPath(host = '', path = '') {
2423
}
2524

2625
const output = {
27-
path: resolve('public', paths.output),
28-
publicPath: formatPublicPath(env.ASSET_HOST, paths.output)
26+
path: resolve('public', settings.public_output_path),
27+
publicPath: formatPublicPath(env.ASSET_HOST, settings.public_output_path)
2928
}
3029

3130
module.exports = {
32-
devServer,
31+
settings,
3332
env,
34-
paths,
3533
loadersDir,
3634
output
3735
}

0 commit comments

Comments
 (0)