Last active
February 12, 2017 08:08
-
-
Save blessdyb/446a4236962bb25ee09473b8a28cacb7 to your computer and use it in GitHub Desktop.
Webpack2 React Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require('webpack'); | |
var path = require('path'); | |
var HtmlWebpackPlugin = require('html-webpack-plugin'); | |
module.exports = { | |
entry: { | |
bundle: './src/index.js', | |
vendor: [ | |
'faker', 'lodash', 'redux', | |
'react-redux', 'react-dom', 'react-input-range', | |
'redux-form', 'redux-thunk' | |
] | |
}, | |
output: { | |
path: path.join(__dirname, 'dist'), | |
filename: '[name].[chunkhash].js', | |
publicPath: '/' | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
use: ['babel-loader'], | |
exclude: /node_modules/ | |
}, | |
{ | |
test: /\.css$/, | |
use: ['style-loader', 'css-loader'] | |
} | |
] | |
}, | |
plugins: [ | |
new webpack.optimize.CommonsChunkPlugin({ | |
names: ['vendor', 'manifest'] | |
}), | |
new HtmlWebpackPlugin({ | |
template: 'src/index.html' | |
}), | |
new webpack.DefinePlugin({ | |
'process.env': JSON.stringify(process.env.NODE_ENV) | |
}), | |
new webpack.optimize.UglifyJsPlugin() | |
] | |
}; |
Author
blessdyb
commented
Feb 5, 2017
Code Split
const componentRoutes = {
component: Home,
path: '/',
indexRoute: {
component: ArtistMain
},
childRoutes: [
{
path: 'artists/new',
getComponent(location, cb) {
System.import('./components/artists/ArtistCreate')
.then(module => cb(null, module.default));
}
},
{
path: 'artists/:id',
getComponent(location, cb) {
System.import('./components/artists/ArtistDetail')
.then(module => cb(null, module.default));
}
},
{
path: 'artists/:id/edit',
getComponent(location, cb) {
System.import('./components/artists/ArtistEdit')
.then(module => cb(null, module.default));
}
}
]
};
const Routes = () => {
return (
<Router history={hashHistory} routes={componentRoutes}/>
);
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment