2020-10-26 02:32:04 +03:00
|
|
|
import * as path from 'path';
|
|
|
|
import * as webpack from 'webpack';
|
|
|
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
|
|
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
2019-01-03 17:14:25 +03:00
|
|
|
|
2021-12-05 06:28:45 +03:00
|
|
|
export default (
|
2023-07-12 21:03:20 +03:00
|
|
|
env: { development?: boolean; platform?: string } = {},
|
2021-12-05 06:28:45 +03:00
|
|
|
): webpack.Configuration => ({
|
2020-08-09 08:06:18 +03:00
|
|
|
mode: env.development ? 'development' : 'production',
|
2019-01-10 21:51:14 +03:00
|
|
|
entry: {
|
2020-12-22 20:02:14 +03:00
|
|
|
app: './demo/index',
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
|
|
|
output: {
|
2020-10-26 02:32:04 +03:00
|
|
|
path: path.resolve(__dirname, `build/${env.platform as string}`),
|
2019-01-10 21:51:14 +03:00
|
|
|
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: [
|
|
|
|
{
|
2020-10-26 02:32:04 +03:00
|
|
|
test: /\.(js|ts)x?$/,
|
2019-01-10 21:51:14 +03:00
|
|
|
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
|
|
|
},
|
|
|
|
{
|
2022-01-16 17:37:49 +03:00
|
|
|
test: /\.woff2$/,
|
|
|
|
type: 'asset/resource',
|
2020-08-08 23:26:39 +03:00
|
|
|
},
|
|
|
|
],
|
2019-01-10 21:51:14 +03:00
|
|
|
},
|
2020-10-26 02:32:04 +03:00
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
|
|
},
|
2019-01-10 21:51:14 +03:00
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': {
|
|
|
|
NODE_ENV: JSON.stringify(
|
2023-07-12 21:03:20 +03:00
|
|
|
env.development ? 'development' : 'production',
|
2019-01-10 21:51:14 +03:00
|
|
|
),
|
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',
|
|
|
|
}),
|
2020-10-26 02:32:04 +03:00
|
|
|
new ForkTsCheckerWebpackPlugin({
|
|
|
|
typescript: {
|
2021-08-30 07:54:35 +03:00
|
|
|
configFile: 'tsconfig.demo.json',
|
2020-10-26 02:32:04 +03:00
|
|
|
},
|
|
|
|
}),
|
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
|
|
|
});
|