Skip to content

Commit

Permalink
Make public root path configurable (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan authored and gauravtiwari committed Dec 21, 2018
1 parent 39e6a35 commit 0d2db5f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/install/config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
Expand Down
2 changes: 1 addition & 1 deletion lib/webpacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def source_entry_path
end

def public_path
root_path.join("public")
root_path.join(fetch(:public_root_path))
end

def public_output_path
Expand Down
2 changes: 1 addition & 1 deletion package/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const app = safeLoad(readFileSync(configPath), 'utf8')[railsEnv]
if (isArray(app.extensions) && app.extensions.length) delete defaults.extensions

const config = deepMerge(defaults, app)
config.outputPath = resolve('public', config.public_output_path)
config.outputPath = resolve(config.public_root_path, config.public_output_path)

// Ensure that the publicPath includes our asset host so dynamic imports
// (code-splitting chunks and static assets) load from the CDN instead of a relative path.
Expand Down
9 changes: 9 additions & 0 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def test_source_entry_path
def test_public_output_path
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
assert_equal @config.public_output_path.to_s, public_output_path

@config = Webpacker::Configuration.new(
root_path: @config.root_path,
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_public_root.yml", __dir__)),
env: "production"
)

public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
assert_equal @config.public_output_path.to_s, public_output_path
end

def test_public_manifest_path
Expand Down
1 change: 1 addition & 0 deletions test/test_app/config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
webpack_compile_output: false
Expand Down
19 changes: 19 additions & 0 deletions test/test_app/config/webpacker_public_root.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Note: You must restart bin/webpack-dev-server for changes to take effect

default: &default
public_root_path: ../public

development:
<<: *default
compile: true

test:
<<: *default
compile: true
public_output_path: packs-test

production:
<<: *default
compile: false
extract_css: true
cache_manifest: true

0 comments on commit 0d2db5f

Please sign in to comment.