@@ -24,15 +24,21 @@ if (env['process.env.NODE_ENV'] !== '"production"') {
24
24
throw new Error ( 'Production builds must have NODE_ENV=production.' ) ;
25
25
}
26
26
27
- // We use "homepage" field to infer "public path" at which the app is served.
28
- // Webpack needs to know it to put the right <script> hrefs into HTML even in
29
- // single-page apps that may serve index.html for nested URLs like /todos/42.
30
- // We can't use a relative path in HTML because we don't want to load something
31
- // like /todos/42/static/js/bundle.7289d.js. We have to know the root.
32
- var homepagePath = require ( paths . appPackageJson ) . homepage ;
33
- var publicPath = homepagePath ? url . parse ( homepagePath ) . pathname : '/' ;
27
+ // We use $CDN_URL environment variable to set the "public path" at which the
28
+ // app is served, if no $CDN_URL is set we then look at the "homepage" field
29
+ // in package.json. Webpack needs to know it to put the right <script> hrefs
30
+ // into HTML even in single-page apps that may serve index.html for nested URLs
31
+ // like /todos/42. We can't use a relative path in HTML because we don't want to
32
+ // load something like /todos/42/static/js/bundle.7289d.js. We have to know the root.
33
+
34
+ var publicPath ;
35
+ if ( process . env . CDN_URL ) {
36
+ publicPath = process . env . CDN_URL ;
37
+ } else {
38
+ var homepagePath = require ( paths . appPackageJson ) . homepage ;
39
+ publicPath = homepagePath ? url . parse ( homepagePath ) . pathname : '' ;
40
+ }
34
41
if ( ! publicPath . endsWith ( '/' ) ) {
35
- // If we don't do this, file assets will get incorrect paths.
36
42
publicPath += '/' ;
37
43
}
38
44
@@ -58,7 +64,7 @@ module.exports = {
58
64
// We don't currently advertise code splitting but Webpack supports it.
59
65
filename : 'static/js/[name].[chunkhash:8].js' ,
60
66
chunkFilename : 'static/js/[name].[chunkhash:8].chunk.js' ,
61
- // We inferred the "public path" (such as / or /my-project) from homepage.
67
+ // We use $CDN_URL or infer the "public path" (such as / or /my-project) from homepage.
62
68
publicPath : publicPath
63
69
} ,
64
70
resolve : {
0 commit comments