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

Include RAILS_RELATIVE_URL_ROOT environment variable in publicPath. #1428

Merged
merged 7 commits into from
Apr 17, 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
18 changes: 17 additions & 1 deletion package/__tests__/config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
/* global test expect, describe */

const { chdirTestApp, chdirCwd } = require('../utils/helpers')
const { chdirCwd, chdirTestApp } = require('../utils/helpers')

chdirTestApp()

const config = require('../config')

describe('Config', () => {
beforeEach(() => jest.resetModules())
afterAll(chdirCwd)

test('public path', () => {
process.env.RAILS_ENV = 'development'
delete process.env.RAILS_RELATIVE_URL_ROOT
const config = require('../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('should return extensions as listed in app config', () => {
expect(config.extensions).toEqual([
'.js',
Expand Down
10 changes: 9 additions & 1 deletion package/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ if (isArray(app.extensions) && app.extensions.length) delete defaults.extensions

const config = deepMerge(defaults, app)
config.outputPath = resolve('public', config.public_output_path)
config.publicPath = `/${config.public_output_path}/`.replace(/([^:]\/)\/+/g, '$1')

let publicPath = `/${config.public_output_path}/`
// Add prefix to publicPath.
if (process.env.RAILS_RELATIVE_URL_ROOT) {
publicPath = `/${process.env.RAILS_RELATIVE_URL_ROOT}${publicPath}`
}

// Remove extra slashes.
config.publicPath = publicPath.replace(/(^\/|[^:]\/)\/+/g, '$1')

module.exports = config