hedera-web/webpack.config.js

81 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-09-27 19:31:46 +00:00
var path = require ('path');
2017-03-02 10:01:29 +00:00
var webpack = require ('webpack');
var AssetsWebpackPlugin = require ('assets-webpack-plugin');
var WebpackChunkHash = require ('webpack-chunk-hash');
var merge = require ('webpack-merge');
var wpConfig = require ('./webpack.config.json');
2016-09-27 19:31:46 +00:00
2016-10-14 10:58:35 +00:00
var devMode = process.env.NODE_ENV !== 'production';
2017-03-02 10:01:29 +00:00
var outputPath = path.join (__dirname, wpConfig.buildDir);
var publicPath = wpConfig.buildDir +'/';
2016-09-24 14:32:31 +00:00
2017-03-02 10:01:29 +00:00
var baseConfig = {
entry: wpConfig.entry,
2016-10-04 15:27:49 +00:00
output: {
2017-03-02 10:01:29 +00:00
path: outputPath,
publicPath: publicPath,
filename: '[name].js',
chunkFilename: 'chunk.[id].js'
2016-10-04 15:27:49 +00:00
},
module: {
2017-03-02 10:01:29 +00:00
rules: [
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{ test: /\.xml$/, loader: 'raw-loader' },
{ test: /\.ttf$/, loader: 'file-loader' }
2016-09-26 09:28:47 +00:00
]
2016-10-04 15:27:49 +00:00
},
resolve: {
2017-03-02 10:01:29 +00:00
modules: [
__dirname +'/js',
__dirname,
'node_modules',
'/usr/lib/node_modules'
]
2016-10-04 15:27:49 +00:00
},
2017-03-02 10:01:29 +00:00
plugins: [
new webpack.DefinePlugin ({
_DEV_MODE: devMode,
_DEV_SERVER_PORT: wpConfig.devServerPort,
_PUBLIC_PATH: JSON.stringify (publicPath)
}),
new webpack.optimize.CommonsChunkPlugin ({
names: ['vendor', 'manifest']
})
]
};
var prodConfig = {
output: {
filename: '[name].[chunkhash].js',
chunkFilename: 'chunk.[id].[chunkhash].js'
2016-10-04 15:27:49 +00:00
},
2016-09-26 09:28:47 +00:00
plugins: [
2017-03-02 10:01:29 +00:00
new webpack.optimize.UglifyJsPlugin ({
minimize: true,
compress: { warnings: false }
}),
new AssetsWebpackPlugin ({
path: outputPath
}),
new webpack.HashedModuleIdsPlugin (),
new WebpackChunkHash ()
],
devtool: 'source-map'
};
var devConfig = {
plugins: [
new webpack.NamedModulesPlugin ()
2016-10-11 14:45:10 +00:00
],
2016-10-30 22:48:18 +00:00
devServer: {
host: '0.0.0.0',
2017-03-02 10:01:29 +00:00
port: wpConfig.devServerPort,
headers: { "Access-Control-Allow-Origin": "*" },
stats: { chunks: false }
},
devtool: 'eval-source-map'
2016-09-24 14:32:31 +00:00
};
2016-09-27 19:31:46 +00:00
2017-03-02 10:01:29 +00:00
var mrgConfig = devMode ? devConfig : prodConfig;
module.exports = merge (baseConfig, mrgConfig);