Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make public root path configurable #1848

Merged
merged 2 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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