Added better support for external package includes

This commit is contained in:
Chris
2015-12-11 09:00:04 +01:00
parent f4fcd9111e
commit cf5093cd39
6 changed files with 75 additions and 25 deletions
+10
View File
@@ -1,5 +1,15 @@
# react-webpack-template - Changelog # react-webpack-template - Changelog
## 1.1.0:
1. Added support for easier webpack include management (can now be set via cfg/base.js, see README.md)
## 1.0.3:
1. Support for config independent settings in ```src/config/base.js``` (provided by [sthzg](https://github.com/sthzg))
2. Fixed eslint loader path (provided by [HelloYie](https://github.com/HelloYie))
3. Added support for babel-eslint (as suggested in https://github.com/newtriks/generator-react-webpack/issues/173)
## 1.0.2: ## 1.0.2:
1. Added babel-eslint (as suggested in https://github.com/newtriks/generator-react-webpack/issues/173) 1. Added babel-eslint (as suggested in https://github.com/newtriks/generator-react-webpack/issues/173)
+14
View File
@@ -25,6 +25,7 @@ Basically, it is currently only used as the base template of [generator-react-we
## Using it ## Using it
The template uses webpack as build tool to serve files and run tests. The following commands are available: The template uses webpack as build tool to serve files and run tests. The following commands are available:
```bash ```bash
# Start for development # Start for development
npm start # or npm start # or
@@ -53,6 +54,7 @@ npm run copy
``` ```
You can also use your globally installed version of webpack like this: You can also use your globally installed version of webpack like this:
```bash ```bash
# Build or run the dev version: # Build or run the dev version:
webpack webpack
@@ -65,6 +67,18 @@ webpack-dev-server --env=dev
webpack --env=dist webpack --env=dist
webpack-dev-server --env=dist webpack-dev-server --env=dist
``` ```
## Including third party modules (e.g. from npm)
The default setting for the webpack configuration is to only include the ```src``` and ```test``` directories. If you want to add any modules from npm, you have to add them in ```cfg/base.js```. One example is:
```javascript
// Somewhere on top of the file:
let npmBase = path.join(__dirname, '../node_modules');
let additionalPaths = [ path.join(npmBase, 'react-bootstrap') ];
```
All entries added to the additionalPaths array will be appended to the include path for babel.
## A note on unit testing ## A note on unit testing
When running tests, coverage information (provided via Istanbul) will also be written into the ```coverage/``` directory. If you do not need this, just comment out or remove the section in ```karma.conf``` like this: When running tests, coverage information (provided via Istanbul) will also be written into the ```coverage/``` directory. If you do not need this, just comment out or remove the section in ```karma.conf``` like this:
+13 -4
View File
@@ -1,10 +1,19 @@
var path = require('path'); 'use strict';
let path = require('path');
var port = 8000; let port = 8000;
var srcPath = path.join(__dirname, '/../src'); let srcPath = path.join(__dirname, '/../src');
var publicPath = '/assets/'; let publicPath = '/assets/';
// Additional npm or bower modules to include in builds
// Add all foreign plugins you may need into this array
// @example:
// let npmBase = path.join(__dirname, '../node_modules');
// let additionalPaths = [ path.join(npmBase, 'react-bootstrap') ];
let additionalPaths = [];
module.exports = { module.exports = {
additionalPaths: additionalPaths,
port: port, port: port,
debug: true, debug: true,
output: { output: {
+12 -7
View File
@@ -1,13 +1,15 @@
var path = require('path'); 'use strict';
var webpack = require('webpack');
var _ = require('lodash');
var baseConfig = require('./base'); let path = require('path');
let webpack = require('webpack');
let _ = require('lodash');
let baseConfig = require('./base');
// Add needed plugins here // Add needed plugins here
var BowerWebpackPlugin = require('bower-webpack-plugin'); let BowerWebpackPlugin = require('bower-webpack-plugin');
var config = _.merge({ let config = _.merge({
entry: [ entry: [
'webpack-dev-server/client?http://127.0.0.1:8000', 'webpack-dev-server/client?http://127.0.0.1:8000',
'webpack/hot/only-dev-server', 'webpack/hot/only-dev-server',
@@ -28,7 +30,10 @@ var config = _.merge({
config.module.loaders.push({ config.module.loaders.push({
test: /\.(js|jsx)$/, test: /\.(js|jsx)$/,
loader: 'react-hot!babel-loader', loader: 'react-hot!babel-loader',
include: path.join(__dirname, '/../src') include: [].concat(
config.additionalPaths,
[ path.join(__dirname, '/../src') ]
)
}); });
module.exports = config; module.exports = config;
+12 -7
View File
@@ -1,13 +1,15 @@
var path = require('path'); 'use strict';
var webpack = require('webpack');
var _ = require('lodash');
var baseConfig = require('./base'); let path = require('path');
let webpack = require('webpack');
let _ = require('lodash');
let baseConfig = require('./base');
// Add needed plugins here // Add needed plugins here
var BowerWebpackPlugin = require('bower-webpack-plugin'); let BowerWebpackPlugin = require('bower-webpack-plugin');
var config = _.merge({ let config = _.merge({
entry: path.join(__dirname, '../src/components/run'), entry: path.join(__dirname, '../src/components/run'),
cache: false, cache: false,
devtool: 'sourcemap', devtool: 'sourcemap',
@@ -29,7 +31,10 @@ var config = _.merge({
config.module.loaders.push({ config.module.loaders.push({
test: /\.(js|jsx)$/, test: /\.(js|jsx)$/,
loader: 'babel', loader: 'babel',
include: path.join(__dirname, '/../src') include: [].concat(
config.additionalPaths,
[ path.join(__dirname, '/../src') ]
)
}); });
module.exports = config; module.exports = config;
+14 -7
View File
@@ -1,8 +1,12 @@
var path = require('path'); 'use strict';
var srcPath = path.join(__dirname, '/../src/');
let path = require('path');
let srcPath = path.join(__dirname, '/../src/');
let baseConfig = require('./base');
// Add needed plugins here // Add needed plugins here
var BowerWebpackPlugin = require('bower-webpack-plugin'); let BowerWebpackPlugin = require('bower-webpack-plugin');
module.exports = { module.exports = {
devtool: 'eval', devtool: 'eval',
@@ -24,10 +28,13 @@ module.exports = {
{ {
test: /\.(js|jsx)$/, test: /\.(js|jsx)$/,
loader: 'babel-loader', loader: 'babel-loader',
include: [ include: [].concat(
path.join(__dirname, '/../src'), baseConfig.additionalPaths,
path.join(__dirname, '/../test') [
] path.join(__dirname, '/../src'),
path.join(__dirname, '/../test')
]
)
} }
] ]
}, },