Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
Merge webpack.config.js if exists, close #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Ola Holmström committed Jun 20, 2016
1 parent 8848892 commit ca1c7b7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2016-06-20 (0.7.0)

* Load `webpack.config.js` if one is found and merge with reactpack config.

# 2016-06-20 (0.6.0)

* Load .babelrc if one is found and merge with reactpack babel settings.
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ One command to build your React frontend.

- Unified package, only one `npm i` needed.
- Linting with your `.eslintrc` or with `standard`.
- Smartly merges existing `.babelrc` and `webpack.config.js` into configuration.
- ES6 with Babel presets `react`, `es2015` and `stage-0`.
- PostCSS with `precss` and `autoprefixer`.
- Style extraction into dedicated css bundle.
Expand All @@ -28,6 +29,7 @@ One command to build your React frontend.
* [FAQ](#faq)
* [How do I use another linter than `standard`?](#how-do-i-use-another-linter-than-standard)
* [How do I customize index.html?](#how-do-i-customize-indexhtml)
* [How do I add other loaders?](#how-do-i-add-other-loaders)
* [CLI](#cli)
* [Tested on](#tested-on)
* [Contributors](#contributors)
Expand Down Expand Up @@ -111,6 +113,24 @@ for generating html. The default `index.ejs` looks like:
</html>
```

##### How do I add other loaders?

Reactpack merge existing `webpack.config.js` it into its config so for example if
you want to add `less-loader` just have a `webpack.config.js` with:

```js
module.exports = {
module: {
loaders: [
{
test: /\.less$/,
loader: 'style!css!less'
}
]
}
}
```

## CLI

```
Expand Down
16 changes: 15 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin')
var eslintrcUp = require('eslintrc-up')
var findUp = require('find-up')
var merge = require('lodash.merge')
var webpackMerge = require('webpack-merge')

module.exports = function (options) {
options = options || {}
Expand All @@ -24,6 +25,7 @@ module.exports = function (options) {

var eslintConf = eslintrcUp.sync({cwd: process.cwd()})
var babelRc = findUp.sync('.babelrc', {cwd: process.cwd()})
var webpackConfig = findUp.sync('webpack.config.js', {cwd: process.cwd()})

var config = {
entry: entry,
Expand Down Expand Up @@ -96,7 +98,7 @@ module.exports = function (options) {
'Using babel config (%s)',
path.relative(process.cwd(), babelRc)
))
babelLoaderQuery = merge(babelLoaderQuery, babelRcQuery)
babelLoaderQuery = webpackMerge(babelLoaderQuery, babelRcQuery)
} catch (e) {
config._msgs.push(util.format(
'Error loading babel config (%s): %s',
Expand Down Expand Up @@ -215,5 +217,17 @@ module.exports = function (options) {
}))
}

if (webpackConfig) {
try {
var webpackConfigData = require(webpackConfig)
config = webpackMerge.smart(config, webpackConfigData)
config._msgs.push(util.format(
'Merging found webpack config %s with reactpack config.',
path.relative(process.cwd(), webpackConfig)
))
} catch (e) {
}
}

return config
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactpack",
"version": "0.6.0",
"version": "0.7.0",
"description": "One command to build your React frontend.",
"bin": "cli.js",
"main": "index.js",
Expand Down

0 comments on commit ca1c7b7

Please sign in to comment.