-
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
Include RAILS_RELATIVE_URL_ROOT
environment variable in publicPath
.
#1428
Conversation
package/config.js
Outdated
|
||
// Add prefix to publicPath. | ||
if (process.env.RAILS_RELATIVE_URL_ROOT) { | ||
config.publicPath = `/${process.env.RAILS_RELATIVE_URL_ROOT}${config.publicPath}` |
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.
Could you add some test for this, please? using different paths
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 thought about that, but wasn't sure which test file to put them in? I was thinking of using the config test file, but wasn't sure because I didn't see anything in there for publicPath
.
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.
Ahh yes, but could you please add one :)
/* global test expect, describe */
const { chdirTestApp, chdirCwd } = require('../utils/helpers')
chdirTestApp()
describe('Config', () => {
beforeEach(() => jest.resetModules())
afterAll(chdirCwd)
test('public path', () => {
delete process.env.RAILS_RELATIVE_URL_ROOT
const config = require('../config')
expect(config.publicPath).toEqual('/packs/')
})
test('public path with relative root', () => {
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', () => {
const config = require('../config')
expect(config.extensions).toEqual([
'.js',
'.sass',
'.scss',
'.css',
'.module.sass',
'.module.scss',
'.module.css',
'.png',
'.svg',
'.gif',
'.jpeg',
'.jpg'
])
})
})
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.
Will do. Thanks for the boilerplate.
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.
Great thanks 👍
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 guess we need to set RAILS_ENV in the test for consistent results:
test('public path', () => {
process.env.RAILS_ENV = 'development'
delete process.env.RAILS_RELATIVE_URL_ROOT
const config = require('../config')
expect(config.publicPath).toEqual('/packs/')
})
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/')
})
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 assume you meant NODE_ENV
in your examples.
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.
Nope, you meant RAILS_ENV
.
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.
oh yes! I guess you figured it out 😉
package/config.js
Outdated
} | ||
|
||
// Remove extra slashes. | ||
config.publicPath = config.publicPath.replace(/(^\/|[^:]\/)\/+/g, '$1') |
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.
The [^:]\/
part doesn't seem correct because if public_output_path
contains a protocol, then publicPath
would have a leading slash; e.g., (ignoring relative root) public_output_path='https://cdn.com'
and publicPath='/https://cdn.com/'
. The protocol would be preserved with the current RegExp, but that doesn't appear to be correct. Maybe I'm missing something.
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.
Yeah, but at the moment Rails handles the CDN side of things so it's fine but you are right this needs more check if we expect the public_output_path
to have a protocol as well (which we don't at the moment).
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.
Sounds good.
Fix #1357.