Skip to content

Commit

Permalink
Add cli option for webpack-config (#709)
Browse files Browse the repository at this point in the history
* Add cli option for webpack-config

* Add more doc

* Doc edits

* Update documentation based off pr feedback
  • Loading branch information
sresant authored Nov 30, 2016
1 parent 979512d commit a23199e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion docs/guides/react-server-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default (webpackConfig) => {
}
```

In the `.reactserverrc` file add an option for `webpack-config` that points to that function file and when React Server is setting up Webpack it will call your function with the result of the built in Webpack options, allowing you to make any modifications needed.
In the `.reactserverrc` file add an option for `webpackConfig` that points to that function file and when React Server is setting up Webpack it will call your function with the result of the built in Webpack options, allowing you to make any modifications needed. This may also be specified on the command line with the `--webpack-config=<FILE>` option.

This comment has been minimized.

Copy link
@drewpc

drewpc Dec 3, 2016

Collaborator

GAAHHHH!!!!! This is a breaking change! This needs to be highlighted in the CHANGELOG as a breaking change. I've been pulling my hair out for HOURS trying to figure out why my Webpack aliases no longer worked.

This comment has been minimized.

Copy link
@gigabo

gigabo Dec 5, 2016

Contributor

Oh no!

This shouldn't have been a breaking change... 🤔

Oh, wait... :squint: Did this change the .reactserverrc config key from webpack-config to webpackConfig and remove support for the old key? Oh, man... I should have caught that.

Actually, we should support both variants in .reactserverrc. It's confusing that they both work on the command-line, but only one works in config. I've created #783 to track this.

Sorry this caused you so much frustration @drewpc!


### Use Custom Express Middleware
Currently the default Express Middlewares used are compression, body-parser, cookie-parser. If you need to setup custom express middleware you can do it with a setup function.
Expand Down Expand Up @@ -283,6 +283,11 @@ Path to the custom middleware function file. If it is not defined the default se

Defaults to **undefined**.

#### --webpack-config
Path to your webpack options callback function file.

Defaults to **undefined**.

#### --long-term-caching
Adds hashes to all JavaScript and CSS file names output by the build, allowing
for the static files to be served with far-future expires headers. This option
Expand Down
5 changes: 3 additions & 2 deletions packages/react-server-cli/src/compileClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import callerDependency from "./callerDependency"
export default (opts = {}) => {
const {
routes,
webpackConfig,
workingDir = "./__clientTemp",
routesDir = ".",
outputDir = workingDir + "/build",
Expand All @@ -39,8 +40,8 @@ export default (opts = {}) => {
}

var webpackConfigFunc = (data) => { return data }
if (opts['webpack-config']) {
const webpackDirAbsolute = path.resolve(process.cwd(), opts['webpack-config']);
if (webpackConfig) {
const webpackDirAbsolute = path.resolve(process.cwd(), webpackConfig);
const userWebpackConfigFunc = require(webpackDirAbsolute)
webpackConfigFunc = userWebpackConfigFunc.default
}
Expand Down
5 changes: 5 additions & 0 deletions packages/react-server-cli/src/parseCliArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export default (args = process.argv) => {
default: undefined,
type: "string",
})
.option("webpack-config", {
describe: "Path to Webpack options callback function file.",
default: undefined,
type: "string",
})
.option("long-term-caching", {
describe: "Use long-term cache headers for the static JS & CSS files. Default is true in production mode, false otherwise.",
default: undefined,
Expand Down

0 comments on commit a23199e

Please sign in to comment.