Skip to content

Commit 9faeeca

Browse files
committed
Adds cdnPublicPath option to the standard Webpack cofnig for apps
1 parent 5702b72 commit 9faeeca

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Topcoder React Utils Changelog
22

3+
### v0.3.5
4+
- `cdnPublicPath` option added to the standard Webpack config for apps to support
5+
assets loading via CDN.
6+
37
### v0.3.4
48
- Small fixes in the client / server setup.
59
- `createActions(..)` alias added to `redux` utils, to use that function without

config/webpack/app-base.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const webpack = require('webpack');
2525
*
2626
* @param {String} ops.babelEnv BABEL_ENV to use for Babel during the build.
2727
*
28+
* @param {String} ops.cdnPublicPath Optional. If provided, it will be used in
29+
* the frontend bundle instead of publicPath, to direct all asset request to
30+
* CDN. The publicPath still will be used by the server as the path to serve
31+
* the assets for CDN requests.
32+
*
2833
* @param {String} ops.context Base URL for resolution of relative
2934
* config paths.
3035
*
@@ -50,9 +55,10 @@ const webpack = require('webpack');
5055
module.exports = function configFactory(ops) {
5156
const o = _.defaults(_.clone(ops), {
5257
cssLocalIdent: '[hash:base64:6]',
53-
publicPath: '',
5458
});
5559

60+
const publicPath = o.cdnPublicPath || o.publicPath || '';
61+
5662
let buildInfo;
5763
const buildInfoUrl = path.resolve(o.context, '.build-info');
5864
/* If build-info file is found, we reuse those data. */
@@ -97,7 +103,7 @@ module.exports = function configFactory(ops) {
97103
chunkFilename: '[name].js',
98104
filename: '[name].js',
99105
path: path.resolve(__dirname, o.context, 'build'),
100-
publicPath: `${o.publicPath}/`,
106+
publicPath: `${publicPath}/`,
101107
},
102108
plugins: [
103109
new ExtractCssChunks({
@@ -129,7 +135,7 @@ module.exports = function configFactory(ops) {
129135
loader: 'file-loader',
130136
options: {
131137
outputPath: '/fonts/',
132-
publicPath: `${o.publicPath}/fonts`,
138+
publicPath: `${publicPath}/fonts`,
133139
},
134140
}, {
135141
/* Loads JS and JSX moudles, and inlines SVG assets. */
@@ -147,7 +153,7 @@ module.exports = function configFactory(ops) {
147153
loader: 'file-loader',
148154
options: {
149155
outputPath: '/images/',
150-
publicPath: `${o.publicPath}/images`,
156+
publicPath: `${publicPath}/images`,
151157
},
152158
}, {
153159
/* Loads SCSS stylesheets. */

docs/webpack-config.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ mutation of the config object.
3737
- Config factory handles the following fields in the options object:
3838
- **`babelEnv`** — *String* — Babel environment to use for
3939
the Babel compilation step;
40+
- **`cdnPublicPath`** — *String* — Optional. If provided,
41+
it will be used in the frontend bundle instead of `publicPath`, to direct
42+
all asset request to CDN. The `publicPath` still will be used by the server
43+
as the path to serve the assets for CDN requests;
4044
- **`context`** — *String* — Base URL for the resolution of
4145
relative config paths;
4246
- **`cssLocalIdent`** — *String* — Optional. The template for

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@
111111
"prepublishOnly": "npm run build",
112112
"test": "npm run lint && npm run jest"
113113
},
114-
"version": "0.3.4"
114+
"version": "0.3.5"
115115
}

0 commit comments

Comments
 (0)