-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix asset host support & improve output path #397
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
70eace2
Allow output path to be customized and distinct from entry path
javan 28fc868
Use computed asset host
javan 4ae0faf
Appease the linters
javan 2a94cdf
Construct dev server asset host in bin/webpack-dev-server
javan 1a778af
Bring consistent style to bin/weback
javan c07dc9b
Remove unintended config change
javan b3732f3
gitignore test app logs
javan cc0dfb5
Add changelog entry
javan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/.bundle | ||
/pkg | ||
/test/test_app/log | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
// Note: You must restart bin/webpack-dev-server for changes to take effect | ||
|
||
const { resolve } = require('path') | ||
const merge = require('webpack-merge') | ||
const devConfig = require('./development.js') | ||
const { devServer, publicPath, paths } = require('./configuration.js') | ||
const { devServer, output } = require('./configuration.js') | ||
|
||
module.exports = merge(devConfig, { | ||
devServer: { | ||
host: devServer.host, | ||
port: devServer.port, | ||
contentBase: output.path, | ||
publicPath: output.publicPath, | ||
compress: true, | ||
headers: { 'Access-Control-Allow-Origin': '*' }, | ||
historyApiFallback: true, | ||
contentBase: resolve(paths.output, paths.entry), | ||
publicPath | ||
historyApiFallback: true | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# Note: You must restart bin/webpack-dev-server for changes to take effect | ||
|
||
default: &default | ||
config: config/webpack | ||
entry: packs | ||
output: public | ||
manifest: manifest.json | ||
node_modules: node_modules | ||
source: app/javascript | ||
default: &default # ~ = Rails.root | ||
source: app/javascript # ~/:source | ||
entry: packs # ~/:source/:entry | ||
output: packs # ~/public/:output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome 👍 been thinking to do this |
||
manifest: manifest.json # ~/public/:output/:manifest | ||
config: config/webpack # ~/:config | ||
node_modules: node_modules # ~/:node_modules | ||
extensions: | ||
- .coffee | ||
- .js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,42 +4,54 @@ | |
|
||
class Webpacker::Configuration < Webpacker::FileLoader | ||
class << self | ||
def config_path | ||
Rails.root.join(paths.fetch(:config, "config/webpack")) | ||
end | ||
|
||
def entry_path | ||
Rails.root.join(source_path, paths.fetch(:entry, "packs")) | ||
source_path.join(fetch(:entry)) | ||
end | ||
|
||
def file_path | ||
Rails.root.join("config", "webpack", "paths.yml") | ||
def output_path | ||
public_path.join(fetch(:output)) | ||
end | ||
|
||
def manifest_path | ||
Rails.root.join(packs_path, paths.fetch(:manifest, "manifest.json")) | ||
output_path.join(fetch(:manifest)) | ||
end | ||
|
||
def packs_path | ||
Rails.root.join(output_path, paths.fetch(:entry, "packs")) | ||
def source_path | ||
Rails.root.join(source) | ||
end | ||
|
||
def paths | ||
load if Webpacker.env.development? | ||
raise Webpacker::FileLoader::FileLoaderError.new("Webpacker::Configuration.load must be called first") unless instance | ||
instance.data | ||
def public_path | ||
Rails.root.join("public") | ||
end | ||
|
||
def output_path | ||
Rails.root.join(paths.fetch(:output, "public")) | ||
def config_path | ||
Rails.root.join(fetch(:config)) | ||
end | ||
|
||
def file_path(root: Rails.root) | ||
root.join("config/webpack/paths.yml") | ||
end | ||
|
||
def default_file_path | ||
file_path(root: Pathname.new(__dir__).join("../install")) | ||
end | ||
|
||
def source | ||
paths.fetch(:source, "app/javascript") | ||
fetch(:source) | ||
end | ||
|
||
def source_path | ||
Rails.root.join(source) | ||
def fetch(key) | ||
paths.fetch(key, default_paths[key]) | ||
end | ||
|
||
def paths | ||
load if Webpacker.env.development? | ||
raise Webpacker::FileLoader::FileLoaderError.new("Webpacker::Configuration.load must be called first") unless instance | ||
instance.data | ||
end | ||
|
||
def default_paths | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🍰 🎉 |
||
@default_paths ||= HashWithIndifferentAccess.new(YAML.load(default_file_path.read)["default"]) | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we set
ASSET_HOST
to dev server host in development when it's enabled? That way we don't need to replace manifest plugin.OR
We would be able to do this in development config without
if
, but guess we can't since we have much shared logic here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I described the reason for not doing it this way in the PR:
That said, I cleaned things up in 2a94cdf by constructing and setting
ASSET_HOST
inbin/webpack-dev-server
.