|
- const webpack = require('webpack');
- const path = require('path');
- const glob = require('glob');
- const { exec } = require('child_process');
- const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
- const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
- const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
- const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
- const TerserPlugin = require('terser-webpack-plugin');
- const Dotenv = require('dotenv-webpack');
- const dotenv = require('dotenv');
- const { format } = require('date-fns');
-
- const basePath = path.resolve('src', 'apps');
-
- const env = dotenv.config().parsed
-
- // basePath配下の各ディレクトリを複数のentryとする
- const entries = glob.sync('*/index.+(js|ts|tsx)', { cwd: basePath }).reduce(
- (prev, file) => ({
- ...prev,
- [path.dirname(file)]: path.resolve(basePath, file),
- }),
- {}
- );
-
- module.exports = {
- optimization: {
- minimize: true,
- minimizer: [new TerserPlugin()],
- },
- entry: entries,
- cache: false,
- resolve: {
- // 拡張子を配列で指定
- extensions: [
- '.ts', '.js',
- ],
- plugins: [
- new TsconfigPathsPlugin({
- configFile: './tsconfig.json',
- }),
- ]
- },
- module: {
- rules: [
- {
- test: /\.m?js$/,
- exclude: /node_modules/,
- use: {
- loader: 'babel-loader',
- options: {
- presets: [
- [
- '@babel/preset-env',
- {
- useBuiltIns: 'usage',
- corejs: 3,
- },
- ],
- ],
- },
- },
- },
- {
- test: /\.tsx?$/,
- use: 'ts-loader',
- }
- ],
- },
- output: {
- path: path.resolve(__dirname, 'dist'),
- filename: '[name].js',
- },
- plugins: [
- // new Dotenv({ systemvars: true }),
- new ForkTsCheckerWebpackPlugin(),
- // new BundleAnalyzerPlugin(),
- new LodashModuleReplacementPlugin(),
- new webpack.DefinePlugin({
- 'process.env.BUILD_TIME': JSON.stringify(format(new Date(), 'yyyy-MM-dd HH:mm:ss')),
- }),
- ],
- };
|