@@ -24,15 +24,21 @@ if (env['process.env.NODE_ENV'] !== '"production"') {
2424 throw new Error ( 'Production builds must have NODE_ENV=production.' ) ;
2525}
2626
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+ }
3441if ( ! publicPath . endsWith ( '/' ) ) {
35- // If we don't do this, file assets will get incorrect paths.
3642 publicPath += '/' ;
3743}
3844
@@ -58,7 +64,7 @@ module.exports = {
5864 // We don't currently advertise code splitting but Webpack supports it.
5965 filename : 'static/js/[name].[chunkhash:8].js' ,
6066 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.
6268 publicPath : publicPath
6369 } ,
6470 resolve : {
0 commit comments