File tree 2 files changed +26
-2
lines changed
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 1
1
/* global test expect, describe */
2
2
3
- const { chdirTestApp , chdirCwd } = require ( '../utils/helpers' )
3
+ const { chdirCwd , chdirTestApp } = require ( '../utils/helpers' )
4
4
5
5
chdirTestApp ( )
6
6
7
7
const config = require ( '../config' )
8
8
9
9
describe ( 'Config' , ( ) => {
10
+ beforeEach ( ( ) => jest . resetModules ( ) )
10
11
afterAll ( chdirCwd )
11
12
13
+ test ( 'public path' , ( ) => {
14
+ process . env . RAILS_ENV = 'development'
15
+ delete process . env . RAILS_RELATIVE_URL_ROOT
16
+ const config = require ( '../config' )
17
+ expect ( config . publicPath ) . toEqual ( '/packs/' )
18
+ } )
19
+
20
+ // also tests removal of extra slashes
21
+ test ( 'public path with relative root' , ( ) => {
22
+ process . env . RAILS_ENV = 'development'
23
+ process . env . RAILS_RELATIVE_URL_ROOT = '/foo'
24
+ const config = require ( '../config' )
25
+ expect ( config . publicPath ) . toEqual ( '/foo/packs/' )
26
+ } )
27
+
12
28
test ( 'should return extensions as listed in app config' , ( ) => {
13
29
expect ( config . extensions ) . toEqual ( [
14
30
'.js' ,
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ if (isArray(app.extensions) && app.extensions.length) delete defaults.extensions
20
20
21
21
const config = deepMerge ( defaults , app )
22
22
config . outputPath = resolve ( 'public' , config . public_output_path )
23
- config . publicPath = `/${ config . public_output_path } /` . replace ( / ( [ ^ : ] \/ ) \/ + / g, '$1' )
23
+
24
+ let publicPath = `/${ config . public_output_path } /`
25
+ // Add prefix to publicPath.
26
+ if ( process . env . RAILS_RELATIVE_URL_ROOT ) {
27
+ publicPath = `/${ process . env . RAILS_RELATIVE_URL_ROOT } ${ publicPath } `
28
+ }
29
+
30
+ // Remove extra slashes.
31
+ config . publicPath = publicPath . replace ( / ( ^ \/ | [ ^ : ] \/ ) \/ + / g, '$1' )
24
32
25
33
module . exports = config
You can’t perform that action at this time.
0 commit comments