2019-01-03 17:14:25 +03:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
|
2019-01-10 21:51:14 +03:00
|
|
|
module.exports = (env = {}) => ({
|
2020-08-09 08:06:18 +03:00
|
|
|
mode: env.development ? 'development' : 'production',
|
2019-01-10 21:51:14 +03:00
|
|
|
entry: {
|
2020-08-08 23:26:39 +03:00
|
|
|
app: './index.js',
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, 'build/' + env.platform),
|
|
|
|
publicPath: '',
|
|
|
|
filename: 'js/[name].js',
|
2020-08-08 23:26:39 +03:00
|
|
|
sourceMapFilename: 'js/[name].map',
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'babel-loader',
|
2020-08-08 23:26:39 +03:00
|
|
|
exclude: /node_modules/,
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.html$/,
|
2020-08-08 23:26:39 +03:00
|
|
|
loader: 'html-loader',
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
2020-08-08 23:26:39 +03:00
|
|
|
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|gif|jpg)$/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: '25000',
|
|
|
|
outputPath: 'images/',
|
2020-08-08 23:26:39 +03:00
|
|
|
publicPath: 'images/',
|
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(ttf|eot|svg|woff|woff2)$/,
|
|
|
|
loader: 'file-loader',
|
2020-08-08 23:26:39 +03:00
|
|
|
options: { outputPath: 'fonts/', publicPath: 'fonts/' },
|
|
|
|
},
|
|
|
|
],
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: JSON.stringify(
|
|
|
|
env.development ? 'development' : 'production'
|
|
|
|
),
|
2020-08-08 23:26:39 +03:00
|
|
|
PLATFORM: JSON.stringify(env.platform),
|
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
2020-08-08 23:26:39 +03:00
|
|
|
template: 'assets/index.html',
|
|
|
|
}),
|
2019-01-10 21:51:14 +03:00
|
|
|
],
|
|
|
|
optimization: {
|
|
|
|
minimize: false,
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
vendor: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: 'common',
|
2020-08-08 23:26:39 +03:00
|
|
|
chunks: 'all',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
performance: {
|
2020-08-08 23:26:39 +03:00
|
|
|
hints: false,
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
devServer: {
|
2020-08-08 23:26:39 +03:00
|
|
|
port: 3000,
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
2020-08-08 23:26:39 +03:00
|
|
|
devtool: env.development ? 'eval-source-map' : 'source-map',
|
2019-01-10 21:51:14 +03:00
|
|
|
});
|