2016-08-28 18:55:56 +05:30
|
|
|
/* eslint-env node */
|
|
|
|
|
2016-08-30 12:32:00 +05:30
|
|
|
const path = require('path');
|
2016-08-28 18:55:56 +05:30
|
|
|
|
2016-08-30 12:32:00 +05:30
|
|
|
const webpack = require('webpack');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2016-08-28 18:55:56 +05:30
|
|
|
|
|
|
|
const rootPath = path.resolve('./src');
|
|
|
|
|
2016-08-30 12:32:00 +05:30
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
2016-08-28 18:55:56 +05:30
|
|
|
|
|
|
|
process.env.NODE_ENV = isProduction ? 'production' : 'development';
|
|
|
|
|
2016-09-04 21:54:50 +05:30
|
|
|
const webpackConfig = {
|
2016-08-28 18:55:56 +05:30
|
|
|
entry: {
|
2016-08-30 12:32:00 +05:30
|
|
|
app: path.join(__dirname, 'src')
|
2016-08-28 18:55:56 +05:30
|
|
|
},
|
|
|
|
|
2016-08-30 12:32:00 +05:30
|
|
|
target: isProduction ? 'node' : 'web',
|
|
|
|
|
2016-08-28 18:55:56 +05:30
|
|
|
output: {
|
|
|
|
path: path.join(__dirname, 'dist'),
|
|
|
|
publicPath: '/',
|
2016-08-30 12:32:00 +05:30
|
|
|
filename: isProduction ? '[name].js' : '[name].js?[hash]',
|
|
|
|
libraryTarget: isProduction ? 'commonjs' : undefined
|
2016-08-28 18:55:56 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
root: rootPath,
|
|
|
|
extensions: ['', '.js', '.jsx']
|
|
|
|
},
|
|
|
|
|
|
|
|
devServer: {
|
|
|
|
host: 'localhost',
|
|
|
|
port: 8080,
|
|
|
|
hot: true,
|
|
|
|
inline: true,
|
|
|
|
historyApiFallback: true
|
|
|
|
},
|
|
|
|
|
2016-09-15 02:32:30 +05:30
|
|
|
devtool: isProduction ? false : 'eval',
|
2016-08-28 18:55:56 +05:30
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
|
|
|
},
|
|
|
|
__DEV__: !isProduction,
|
|
|
|
__PROD__: isProduction
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'src/index.ejs',
|
|
|
|
favicon: 'src/favicon.ico',
|
|
|
|
filename: 'index.html',
|
2016-08-30 12:32:00 +05:30
|
|
|
inject: false
|
2016-08-28 18:55:56 +05:30
|
|
|
}),
|
|
|
|
new webpack.ProvidePlugin({
|
2016-08-30 12:32:00 +05:30
|
|
|
React: 'react'
|
|
|
|
})
|
|
|
|
],
|
2016-08-28 18:55:56 +05:30
|
|
|
|
|
|
|
module: {
|
|
|
|
loaders: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: 'babel'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|gif|jpg|svg)$/,
|
2016-09-27 10:32:19 +05:30
|
|
|
loader: 'file',
|
2016-08-28 18:55:56 +05:30
|
|
|
query: {
|
2016-09-27 10:32:19 +05:30
|
|
|
name: 'assets/[name]-[folder].[ext]?[hash]'
|
2016-08-28 18:55:56 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.json$/,
|
|
|
|
exclude: /(intl|font)\.json/,
|
|
|
|
loader: 'json'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.intl\.json$/,
|
|
|
|
loader: 'babel!intl!json'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
resolveLoader: {
|
|
|
|
alias: {
|
|
|
|
intl: path.resolve('webpack-utils/intl-loader')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!isProduction) {
|
|
|
|
webpackConfig.plugins.push(
|
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
|
|
|
new webpack.NoErrorsPlugin()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = webpackConfig;
|