Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3137b886
Commit
3137b886
authored
Jun 28, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
configure webpack publicPath dynamically to account for CDN or relative path settings
parent
5b43aa95
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
15 deletions
+23
-15
app/assets/javascripts/webpack.js
app/assets/javascripts/webpack.js
+4
-8
app/helpers/webpack_helper.rb
app/helpers/webpack_helper.rb
+16
-7
lib/gitlab/gon_helper.rb
lib/gitlab/gon_helper.rb
+3
-0
No files found.
app/assets/javascripts/webpack.js
View file @
3137b886
/**
* This is the first script loaded by webpack's runtime. It is used to manually configure
* config.output.publicPath to account for relative_url_root
settings which cannot be baked-in
* to our webpack bundles.
* config.output.publicPath to account for relative_url_root
or CDN settings which cannot be
*
baked-in
to our webpack bundles.
*/
if
(
gon
&&
gon
.
relative_url_root
)
{
// this assumes config.output.publicPath is an absolute path
const
basePath
=
gon
.
relative_url_root
.
replace
(
/
\/
$/
,
''
);
// eslint-disable-next-line camelcase, no-undef
__webpack_public_path__
=
basePath
+
__webpack_public_path__
;
if
(
gon
&&
gon
.
webpack_public_path
)
{
__webpack_public_path__
=
gon
.
webpack_public_path
;
// eslint-disable-line
}
app/helpers/webpack_helper.rb
View file @
3137b886
...
...
@@ -11,20 +11,29 @@ module WebpackHelper
paths
=
Webpack
::
Rails
::
Manifest
.
asset_paths
(
source
)
if
extension
paths
=
paths
.
select
{
|
p
|
p
.
ends_with?
".
#{
extension
}
"
}
paths
.
select!
{
|
p
|
p
.
ends_with?
".
#{
extension
}
"
}
end
# include full webpack-dev-server url for rspec tests running locally
force_host
=
webpack_public_host
if
force_host
paths
.
map!
{
|
p
|
"
#{
force_host
}#{
p
}
"
}
end
paths
end
def
webpack_public_host
if
Rails
.
env
.
test?
&&
Rails
.
configuration
.
webpack
.
dev_server
.
enabled
host
=
Rails
.
configuration
.
webpack
.
dev_server
.
host
port
=
Rails
.
configuration
.
webpack
.
dev_server
.
port
protocol
=
Rails
.
configuration
.
webpack
.
dev_server
.
https
?
'https'
:
'http'
paths
.
map!
do
|
p
|
"
#{
protocol
}
://
#{
host
}
:
#{
port
}#{
p
}
"
"
#{
protocol
}
://
#{
host
}
:
#{
port
}
"
else
ActionController
::
Base
.
asset_host
.
try
(
:chomp
,
'/'
)
end
end
paths
def
webpack_public_path
"
#{
webpack_public_host
}
/
#{
Rails
.
application
.
config
.
webpack
.
public_path
}
/"
end
end
lib/gitlab/gon_helper.rb
View file @
3137b886
...
...
@@ -2,11 +2,14 @@
module
Gitlab
module
GonHelper
include
WebpackHelper
def
add_gon_variables
gon
.
api_version
=
'v4'
gon
.
default_avatar_url
=
URI
.
join
(
Gitlab
.
config
.
gitlab
.
url
,
ActionController
::
Base
.
helpers
.
image_path
(
'no_avatar.png'
)).
to_s
gon
.
max_file_size
=
current_application_settings
.
max_attachment_size
gon
.
asset_host
=
ActionController
::
Base
.
asset_host
gon
.
webpack_public_path
=
webpack_public_path
gon
.
relative_url_root
=
Gitlab
.
config
.
gitlab
.
relative_url_root
gon
.
shortcuts_path
=
help_page_path
(
'shortcuts'
)
gon
.
user_color_scheme
=
Gitlab
::
ColorSchemes
.
for_user
(
current_user
).
css_class
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment