Last active
October 22, 2016 20:02
-
-
Save image72/a87b43bf55c1db07eee729e4c3cbae77 to your computer and use it in GitHub Desktop.
webpack config for product. with dist min.files alias, relative context resolve.
This file contains hidden or 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
| // require('babel-runtime/core-js/promise').default = require('bluebird'); | |
| // global.Promise = require('bluebird'); // extra override | |
| var path = require('path'); | |
| var webpack = require('webpack'); | |
| var ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
| var HtmlWebpackPlugin = require('html-webpack-plugin'); | |
| var modulesPath = path.join(__dirname, 'node_modules'); | |
| var reactPath = path.join(modulesPath, 'react', 'react.js') | |
| , reactDOMPath = path.join(modulesPath, 'react', 'lib', 'ReactDOM.js') | |
| , reactPureRenderPath = path.join(modulesPath, 'react','lib','ReactComponentWithPureRenderMixin.js') | |
| , reactCSSTransitionGroupPath = path.join(modulesPath, 'react', 'lib', 'ReactCSSTransitionGroup.js'); | |
| var axiosPath = path.join(modulesPath, 'axios','dist', 'axios.min.js'); | |
| module.exports = { | |
| devtool: 'hidden-source-map', | |
| entry: { | |
| app: [ | |
| 'babel-polyfill', | |
| './src/index.js' | |
| ], | |
| vendor: [ | |
| 'history', | |
| 'axios', | |
| 'react', | |
| 'react-dom', | |
| 'react-redux', | |
| 'react-router', | |
| 'redux', | |
| 'redux-thunk' | |
| ] | |
| }, | |
| output: { | |
| path: __dirname + '/dist/', | |
| // filename: '[name].[chunkhash].js', | |
| filename: 'bundle.[chunkhash:7].js', | |
| publicPath: 'http://a.ymatou.cn/main/dist/', | |
| }, | |
| resolve: { | |
| alias: { | |
| 'react': reactPath, | |
| 'react-dom': reactDOMPath, | |
| 'react-addons-pure-render-mixin': reactPureRenderPath, | |
| 'axios': axiosPath, | |
| 'redux': 'redux/dist/redux.min.js', | |
| 'react-redux': 'react-redux/dist/react-redux.min.js', | |
| 'react-router': 'react-router/umd/ReactRouter.min.js', | |
| 'react-router-redux': 'react-router-redux/dist/ReactRouterRedux.min.js' | |
| }, | |
| extensions: ['', '.js', '.jsx'], | |
| modules: [ | |
| 'src', | |
| 'node_modules', | |
| ], | |
| root: [ path.join(__dirname, 'src')], | |
| modulesDirectories: ['node_modules'] | |
| }, | |
| module: { | |
| loaders: [ | |
| { | |
| test: /\.less$/, | |
| // loader: ExtractTextPlugin.extract('style-loader', 'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]_[hash:base64:5]!postcss-loader!less-loader'), | |
| loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader") | |
| }, { | |
| test: /\.css$/, | |
| include: /node_modules/, | |
| loader: ExtractTextPlugin.extract('style-loader', 'css-loader') | |
| }, { | |
| test: /\.jsx*$/, | |
| exclude: /node_modules/, | |
| loader: 'babel', | |
| }, { | |
| test: /\.(jpe?g|gif|png|svg)$/i, | |
| loader: 'url-loader?limit=10000', | |
| }, { | |
| test: /\.json$/, | |
| loader: 'json-loader', | |
| }, | |
| ], | |
| }, | |
| plugins: [ | |
| new webpack.DefinePlugin({ | |
| 'process.env': { | |
| 'NODE_ENV': JSON.stringify('production'), | |
| } | |
| }), | |
| new webpack.optimize.CommonsChunkPlugin({ | |
| name: 'vendor', | |
| minChunks: Infinity, | |
| filename: '[name].[chunkhash:7].js', | |
| }), | |
| new ExtractTextPlugin('app.[chunkhash:7].css', { allChunks: true }), | |
| new webpack.optimize.UglifyJsPlugin({ | |
| mangle: false, | |
| compressor: { | |
| warnings: false, | |
| } | |
| }), | |
| new HtmlWebpackPlugin({ | |
| templateContent: '<html> <head> <title>system</title> <meta charset="utf-8"> <base href="/main"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <div id="root"> </div></body></html>', | |
| hash: false, | |
| filename: 'index.html', | |
| inject: 'body' | |
| }), | |
| ] | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment