Skip to content

Commit 9390b09

Browse files
committed
Webpack 3 settings
1 parent 2805d9d commit 9390b09

25 files changed

+668
-483
lines changed

lib/react/server_rendering/webpacker_manifest_container.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def file_path path
6464
end
6565
elsif MAJOR == 3
6666
def file_path path
67-
File.join(Webpacker.config.public_output_path, path)
67+
::Rails.root.join('public', manifest.lookup(path)[1..-1])
6868
end
6969
else # 1.0 and 1.1 support
7070
def file_path path

test/dummy_webpacker3/.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
"plugins": [
1515
"syntax-dynamic-import",
16+
"transform-object-rest-spread",
1617
["transform-class-properties", { "spec": true }]
1718
]
1819
}

test/dummy_webpacker3/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
/public/packs
22
/node_modules
3+
/public/packs
4+
/public/packs-test
5+
/node_modules
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
plugins:
22
postcss-smart-import: {}
3-
precss: {}
4-
autoprefixer: {}
3+
postcss-cssnext: {}

test/dummy_webpacker3/bin/webpack

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
$stdout.sync = true
33

44
require "shellwords"
5-
require "yaml"
65

76
ENV["RAILS_ENV"] ||= "development"
87
RAILS_ENV = ENV["RAILS_ENV"]
@@ -20,9 +19,9 @@ unless File.exist?(WEBPACK_CONFIG)
2019
exit!
2120
end
2221

23-
newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
24-
cmdline = ["yarn", "run", "webpack", "--", "--config", WEBPACK_CONFIG] + ARGV
22+
env = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
23+
cmd = [ "#{NODE_MODULES_PATH}/.bin/webpack", "--config", WEBPACK_CONFIG ] + ARGV
2524

2625
Dir.chdir(APP_PATH) do
27-
exec newenv, *cmdline
26+
exec env, *cmd
2827
end

test/dummy_webpacker3/bin/webpack-dev-server

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ $stdout.sync = true
33

44
require "shellwords"
55
require "yaml"
6+
require "socket"
67

78
ENV["RAILS_ENV"] ||= "development"
89
RAILS_ENV = ENV["RAILS_ENV"]
@@ -13,31 +14,55 @@ NODE_ENV = ENV["NODE_ENV"]
1314
APP_PATH = File.expand_path("../", __dir__)
1415
CONFIG_FILE = File.join(APP_PATH, "config/webpacker.yml")
1516
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
16-
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/development.js")
17+
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js")
18+
19+
DEFAULT_LISTEN_HOST_ADDR = NODE_ENV == 'development' ? 'localhost' : '0.0.0.0'
1720

1821
def args(key)
1922
index = ARGV.index(key)
2023
index ? ARGV[index + 1] : nil
2124
end
2225

2326
begin
24-
dev_server = YAML.load_file(CONFIG_FILE)["development"]["dev_server"]
27+
dev_server = YAML.load_file(CONFIG_FILE)[RAILS_ENV]["dev_server"]
2528

26-
DEV_SERVER_HOST = "http#{"s" if args('--https') || dev_server["https"]}://#{args('--host') || dev_server["host"]}:#{args('--port') || dev_server["port"]}"
29+
HOSTNAME = args('--host') || dev_server["host"]
30+
PORT = args('--port') || dev_server["port"]
31+
HTTPS = ARGV.include?('--https') || dev_server["https"]
32+
DEV_SERVER_ADDR = "http#{"s" if HTTPS}://#{HOSTNAME}:#{PORT}"
33+
LISTEN_HOST_ADDR = args('--listen-host') || DEFAULT_LISTEN_HOST_ADDR
2734

2835
rescue Errno::ENOENT, NoMethodError
29-
puts "Webpack dev_server configuration not found in #{CONFIG_FILE}."
30-
puts "Please run bundle exec rails webpacker:install to install webpacker"
36+
$stdout.puts "Webpack dev_server configuration not found in #{CONFIG_FILE}."
37+
$stdout.puts "Please run bundle exec rails webpacker:install to install webpacker"
38+
exit!
39+
end
40+
41+
begin
42+
server = TCPServer.new(LISTEN_HOST_ADDR, PORT)
43+
server.close
44+
45+
rescue Errno::EADDRINUSE
46+
$stdout.puts "Another program is running on port #{PORT}. Set a new port in #{CONFIG_FILE} for dev_server"
3147
exit!
3248
end
3349

34-
newenv = {
35-
"NODE_PATH" => NODE_MODULES_PATH.shellescape,
36-
"ASSET_HOST" => DEV_SERVER_HOST.shellescape
37-
}.freeze
50+
# Delete supplied host, port and listen-host CLI arguments
51+
["--host", "--port", "--listen-host"].each do |arg|
52+
ARGV.delete(args(arg))
53+
ARGV.delete(arg)
54+
end
55+
56+
env = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
3857

39-
cmdline = ["yarn", "run", "webpack-dev-server", "--", "--progress", "--color", "--config", WEBPACK_CONFIG] + ARGV
58+
cmd = [
59+
"#{NODE_MODULES_PATH}/.bin/webpack-dev-server", "--progress", "--color",
60+
"--config", WEBPACK_CONFIG,
61+
"--host", LISTEN_HOST_ADDR,
62+
"--public", "#{HOSTNAME}:#{PORT}",
63+
"--port", PORT.to_s
64+
] + ARGV
4065

4166
Dir.chdir(APP_PATH) do
42-
exec newenv, *cmdline
67+
exec env, *cmd
4368
end

test/dummy_webpacker3/bin/webpack-watcher

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/dummy_webpacker3/config/webpack/configuration.js

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
// Note: You must restart bin/webpack-dev-server for changes to take effect
1+
const environment = require('./environment')
22

3-
const merge = require('webpack-merge')
4-
const sharedConfig = require('./shared.js')
5-
const { settings, output } = require('./configuration.js')
6-
7-
module.exports = merge(sharedConfig, {
8-
devtool: 'cheap-eval-source-map',
9-
10-
stats: {
11-
errorDetails: true
12-
},
13-
14-
output: {
15-
pathinfo: true
16-
},
17-
18-
devServer: {
19-
clientLogLevel: 'none',
20-
https: settings.dev_server.https,
21-
host: settings.dev_server.host,
22-
port: settings.dev_server.port,
23-
contentBase: output.path,
24-
publicPath: output.publicPath,
25-
compress: true,
26-
headers: { 'Access-Control-Allow-Origin': '*' },
27-
historyApiFallback: true,
28-
watchOptions: {
29-
ignored: /node_modules/
30-
}
31-
}
32-
})
3+
module.exports = environment.toWebpackConfig()

test/dummy_webpacker3/config/webpack/development.server.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)