Skip to content

Commit

Permalink
Remove RAILS_RELATIVE_URL_ROOT from publicPath (#2151)
Browse files Browse the repository at this point in the history
  • Loading branch information
sspread authored and gauravtiwari committed Jul 31, 2019
1 parent 704e15f commit d410d01
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
23 changes: 0 additions & 23 deletions package/__tests__/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@ describe('Config', () => {
expect(config.publicPath).toEqual('/packs/')
})

// also tests removal of extra slashes
test('public path with relative root', () => {
process.env.RAILS_ENV = 'development'
process.env.RAILS_RELATIVE_URL_ROOT = '/foo'
const config = require('../config')
expect(config.publicPath).toEqual('/foo/packs/')
})

test('public path with relative root without slash', () => {
process.env.RAILS_ENV = 'development'
process.env.RAILS_RELATIVE_URL_ROOT = 'foo'
const config = require('../config')
expect(config.publicPath).toEqual('/foo/packs/')
})

test('public path with asset host and relative root', () => {
process.env.RAILS_ENV = 'development'
process.env.RAILS_RELATIVE_URL_ROOT = '/foo/'
process.env.WEBPACKER_ASSET_HOST = 'http://foo.com/'
const config = require('../config')
expect(config.publicPath).toEqual('http://foo.com/foo/packs/')
})

test('public path with asset host', () => {
process.env.RAILS_ENV = 'development'
process.env.WEBPACKER_ASSET_HOST = 'http://foo.com/'
Expand Down
12 changes: 2 additions & 10 deletions package/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,8 @@ 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.
const getPublicPath = () => {
const rootUrl = process.env.WEBPACKER_ASSET_HOST || '/'
let packPath = `${config.public_output_path}/`
// Add relative root prefix to pack path.
if (process.env.RAILS_RELATIVE_URL_ROOT) {
let relativeRoot = process.env.RAILS_RELATIVE_URL_ROOT
relativeRoot = relativeRoot.startsWith('/') ? relativeRoot.substr(1) : relativeRoot
packPath = `${ensureTrailingSlash(relativeRoot)}${packPath}`
}

return ensureTrailingSlash(rootUrl) + packPath
const rootUrl = ensureTrailingSlash(process.env.WEBPACKER_ASSET_HOST || '/')
return `${rootUrl}${config.public_output_path}/`
}

config.publicPath = getPublicPath()
Expand Down

0 comments on commit d410d01

Please sign in to comment.