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
|
|
|
|
2019-05-10 04:23:28 +05:30
|
|
|
const { ContextReplacementPlugin } = require('webpack');
|
2016-08-30 12:32:00 +05:30
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2019-05-13 04:57:07 +05:30
|
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
2016-08-28 18:55:56 +05:30
|
|
|
|
2019-05-10 04:23:28 +05:30
|
|
|
const SUPPORTED_LANGUAGES = Object.keys(require('./src/i18n/index.json'));
|
|
|
|
|
2019-03-17 04:07:00 +05:30
|
|
|
module.exports = (env, { mode = 'development' }) => {
|
|
|
|
const isProduction = mode === 'production';
|
2016-08-28 18:55:56 +05:30
|
|
|
|
2019-03-17 04:07:00 +05:30
|
|
|
return {
|
|
|
|
devtool: isProduction ? false : 'source-map',
|
2016-08-28 18:55:56 +05:30
|
|
|
|
2019-03-17 04:07:00 +05:30
|
|
|
entry: {
|
|
|
|
app: path.join(__dirname, 'src'),
|
|
|
|
},
|
2016-08-28 18:55:56 +05:30
|
|
|
|
2019-03-17 04:07:00 +05:30
|
|
|
output: {
|
|
|
|
path: path.join(__dirname, 'dist'),
|
|
|
|
publicPath: '/',
|
|
|
|
filename: isProduction ? '[name].js' : '[name].js?[hash]',
|
|
|
|
libraryTarget: isProduction ? 'commonjs2' : undefined,
|
|
|
|
},
|
2016-08-30 12:32:00 +05:30
|
|
|
|
2019-03-17 04:07:00 +05:30
|
|
|
resolve: {
|
|
|
|
modules: [
|
|
|
|
path.join(__dirname, 'src'),
|
|
|
|
path.join(__dirname, 'node_modules'),
|
|
|
|
],
|
2019-05-13 04:57:07 +05:30
|
|
|
extensions: ['.tsx', '.ts', '.js'],
|
2019-03-17 04:07:00 +05:30
|
|
|
},
|
2016-08-28 18:55:56 +05:30
|
|
|
|
2019-03-17 04:07:00 +05:30
|
|
|
resolveLoader: {
|
|
|
|
alias: {
|
2019-05-10 04:23:28 +05:30
|
|
|
'image-size-loader': path.join(__dirname, 'node_modules/@lesechos/image-size-loader/index.js'),
|
2016-08-28 18:55:56 +05:30
|
|
|
},
|
2019-03-17 04:07:00 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
devServer: {
|
|
|
|
host: 'localhost',
|
|
|
|
port: 8080,
|
|
|
|
hot: true,
|
|
|
|
inline: true,
|
|
|
|
historyApiFallback: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
2019-05-13 04:57:07 +05:30
|
|
|
new ContextReplacementPlugin(/i18n/, new RegExp(`/(${SUPPORTED_LANGUAGES.join('|')})\\.json`)),
|
|
|
|
new ContextReplacementPlugin(/locale-data/, new RegExp(`/(${SUPPORTED_LANGUAGES.join('|')})\\.js`)),
|
2019-03-17 04:07:00 +05:30
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'src/index.ejs',
|
|
|
|
favicon: 'src/favicon.ico',
|
|
|
|
filename: 'index.html',
|
|
|
|
inject: false,
|
|
|
|
}),
|
2019-05-13 04:57:07 +05:30
|
|
|
new BundleAnalyzerPlugin({
|
|
|
|
openAnalyzer: false,
|
|
|
|
generateStatsFile: true,
|
2019-05-19 23:16:49 +05:30
|
|
|
analyzerMode: isProduction ? 'static' : 'server',
|
2019-05-13 04:57:07 +05:30
|
|
|
}),
|
2019-03-17 04:07:00 +05:30
|
|
|
],
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2019-05-13 04:57:07 +05:30
|
|
|
test: /\.[jt]sx?$/,
|
2019-03-17 04:07:00 +05:30
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: [
|
2019-05-13 04:57:07 +05:30
|
|
|
['@babel/preset-env', {
|
|
|
|
targets: isProduction ? {
|
|
|
|
node: '8',
|
|
|
|
} : {
|
|
|
|
browsers: [
|
|
|
|
'last 1 chrome version',
|
|
|
|
'last 1 firefox version',
|
|
|
|
],
|
2019-03-17 04:07:00 +05:30
|
|
|
},
|
2019-05-13 04:57:07 +05:30
|
|
|
}],
|
|
|
|
['@babel/preset-react', {
|
|
|
|
development: !isProduction,
|
|
|
|
}],
|
|
|
|
['@babel/preset-typescript', {
|
|
|
|
jsx: true,
|
|
|
|
}],
|
2019-03-17 04:07:00 +05:30
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
'@babel/plugin-proposal-export-default-from',
|
2019-05-19 23:16:49 +05:30
|
|
|
'@babel/plugin-syntax-dynamic-import',
|
2019-03-17 04:07:00 +05:30
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2019-05-19 23:16:49 +05:30
|
|
|
{
|
|
|
|
loader: 'ifdef-loader',
|
|
|
|
options: {
|
|
|
|
PRODUCTION: isProduction,
|
|
|
|
},
|
|
|
|
},
|
2019-03-17 04:07:00 +05:30
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|gif|jpg|svg)$/,
|
|
|
|
loader: 'file-loader',
|
|
|
|
query: {
|
|
|
|
name: 'assets/[name]-[folder].[ext]?[hash]',
|
|
|
|
},
|
|
|
|
},
|
2019-05-10 04:23:28 +05:30
|
|
|
// The explicit declaration of the json loader allows us to disable the built-in
|
|
|
|
// webpack 4 loader for json, which interferes with the work of text2png-loader
|
|
|
|
{
|
|
|
|
test: /\.json$/,
|
|
|
|
exclude: /\.intl\.json$/,
|
|
|
|
loader: 'json-loader',
|
|
|
|
type: 'javascript/auto',
|
|
|
|
},
|
2019-03-17 04:07:00 +05:30
|
|
|
{
|
|
|
|
test: /\.intl\.json$/,
|
|
|
|
loader: 'intl-json-loader',
|
|
|
|
type: 'javascript/auto',
|
|
|
|
},
|
2019-05-10 04:23:28 +05:30
|
|
|
],
|
2019-03-17 04:07:00 +05:30
|
|
|
},
|
|
|
|
};
|
2016-08-28 18:55:56 +05:30
|
|
|
};
|