2017-07-02 05:49:06 +00:00
|
|
|
'use strict';
|
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
2017-12-30 16:22:28 +00:00
|
|
|
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
|
2018-01-15 22:51:35 +00:00
|
|
|
const SriPlugin = require('webpack-subresource-integrity');
|
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
const config = require('./config');
|
|
|
|
const _ = require('./utils');
|
2017-12-30 20:29:04 +00:00
|
|
|
|
|
|
|
const webpackConfig = {
|
2017-07-02 05:49:06 +00:00
|
|
|
entry: {
|
2017-09-25 02:06:28 +00:00
|
|
|
client: './common/index.tsx'
|
2017-07-02 05:49:06 +00:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: _.outputPath,
|
|
|
|
filename: '[name].js',
|
2018-01-15 22:51:35 +00:00
|
|
|
publicPath: config.publicPath,
|
|
|
|
crossOriginLoading: "anonymous"
|
2017-07-02 05:49:06 +00:00
|
|
|
},
|
|
|
|
resolve: {
|
2017-09-25 02:06:28 +00:00
|
|
|
extensions: ['.ts', '.tsx', '.js', '.css', '.json', '.scss', '.less'],
|
2017-07-02 05:49:06 +00:00
|
|
|
modules: [
|
|
|
|
// places where to search for required modules
|
2017-07-15 04:16:36 +00:00
|
|
|
config.srcPath,
|
2017-07-02 05:49:06 +00:00
|
|
|
_.cwd('node_modules'),
|
|
|
|
_.cwd('./')
|
|
|
|
]
|
|
|
|
},
|
|
|
|
module: {
|
2017-12-30 20:29:04 +00:00
|
|
|
rules: [
|
2017-07-02 05:49:06 +00:00
|
|
|
{
|
2017-09-25 02:06:28 +00:00
|
|
|
test: /\.(ts|tsx)$/,
|
2017-12-30 20:29:04 +00:00
|
|
|
include: path.resolve(__dirname, '../common'),
|
|
|
|
use: [{ loader: 'ts-loader', options: { happyPackMode: true, logLevel: 'info' } }],
|
|
|
|
exclude: ['assets', 'sass', 'vendor', 'translations/lang']
|
|
|
|
.map(dir => path.resolve(__dirname, `../common/${dir}`))
|
|
|
|
.concat([path.resolve(__dirname, '../node_modules')])
|
2017-07-02 05:49:06 +00:00
|
|
|
},
|
2018-01-11 06:44:13 +00:00
|
|
|
{
|
|
|
|
test: /\.worker\.js$/,
|
|
|
|
loader: 'worker-loader'
|
|
|
|
},
|
2017-07-02 05:49:06 +00:00
|
|
|
{
|
2017-12-30 20:29:04 +00:00
|
|
|
include: [
|
|
|
|
path.resolve(__dirname, '../common/assets'),
|
|
|
|
path.resolve(__dirname, '../node_modules')
|
|
|
|
],
|
|
|
|
exclude: /node_modules(?!\/font-awesome)/,
|
2017-07-14 17:04:08 +00:00
|
|
|
test: /\.(gif|png|jpe?g|svg)$/i,
|
2017-12-30 20:29:04 +00:00
|
|
|
use: [
|
2017-07-14 17:04:08 +00:00
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
2017-12-30 20:29:04 +00:00
|
|
|
options: {
|
2017-07-14 17:04:08 +00:00
|
|
|
hash: 'sha512',
|
|
|
|
digest: 'hex',
|
|
|
|
name: '[path][name].[ext]?[hash:6]'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'image-webpack-loader',
|
2017-12-30 20:29:04 +00:00
|
|
|
options: {
|
|
|
|
bypassOnDebug: true,
|
|
|
|
optipng: {
|
|
|
|
optimizationLevel: 4
|
|
|
|
},
|
|
|
|
gifsicle: {
|
|
|
|
interlaced: false
|
|
|
|
},
|
|
|
|
mozjpeg: {
|
|
|
|
quality: 80
|
|
|
|
},
|
|
|
|
svgo: {
|
|
|
|
plugins: [{ removeViewBox: true }, { removeEmptyAttrs: false }, { sortAttrs: true }]
|
|
|
|
}
|
|
|
|
}
|
2017-07-14 17:04:08 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2017-12-30 20:29:04 +00:00
|
|
|
include: [
|
|
|
|
path.resolve(__dirname, '../common/assets'),
|
|
|
|
path.resolve(__dirname, '../node_modules')
|
|
|
|
],
|
|
|
|
exclude: /node_modules(?!\/font-awesome)/,
|
2017-07-14 17:04:08 +00:00
|
|
|
test: /\.(ico|eot|otf|webp|ttf|woff|woff2)(\?.*)?$/,
|
2017-12-30 20:29:04 +00:00
|
|
|
loader: 'file-loader'
|
2017-07-02 05:49:06 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
plugins: [
|
2018-01-15 22:51:35 +00:00
|
|
|
new SriPlugin({
|
|
|
|
hashFuncNames: ['sha256', 'sha384'],
|
|
|
|
enabled: true
|
|
|
|
}),
|
2017-07-02 05:49:06 +00:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
title: config.title,
|
|
|
|
template: path.resolve(__dirname, '../common/index.html'),
|
2017-12-30 20:29:04 +00:00
|
|
|
inject: true,
|
2017-07-02 05:49:06 +00:00
|
|
|
filename: _.outputIndexPath
|
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{
|
|
|
|
from: _.cwd('./static'),
|
|
|
|
// to the root of dist path
|
|
|
|
to: './'
|
|
|
|
}
|
2017-12-30 20:29:04 +00:00
|
|
|
]),
|
|
|
|
|
|
|
|
new webpack.LoaderOptionsPlugin(_.loadersOptions())
|
2017-07-02 05:49:06 +00:00
|
|
|
],
|
|
|
|
target: _.target
|
|
|
|
};
|
2017-12-30 20:29:04 +00:00
|
|
|
module.exports = webpackConfig;
|