京都のkintone用javascript
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.1KB

  1. const webpack = require('webpack');
  2. const path = require('path');
  3. const glob = require('glob');
  4. const { exec } = require('child_process');
  5. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
  6. const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
  7. const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
  8. const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
  9. const TerserPlugin = require('terser-webpack-plugin');
  10. const Dotenv = require('dotenv-webpack');
  11. const dotenv = require('dotenv');
  12. const { format } = require('date-fns');
  13. const basePath = path.resolve('src', 'apps');
  14. const env = dotenv.config().parsed
  15. // basePath配下の各ディレクトリを複数のentryとする
  16. const entries = glob.sync('*/index.+(js|ts|tsx)', { cwd: basePath }).reduce(
  17. (prev, file) => ({
  18. ...prev,
  19. [path.dirname(file)]: path.resolve(basePath, file),
  20. }),
  21. {}
  22. );
  23. module.exports = {
  24. optimization: {
  25. minimize: true,
  26. minimizer: [new TerserPlugin()],
  27. },
  28. entry: entries,
  29. cache: false,
  30. resolve: {
  31. // 拡張子を配列で指定
  32. extensions: [
  33. '.ts', '.js',
  34. ],
  35. plugins: [
  36. new TsconfigPathsPlugin({
  37. configFile: './tsconfig.json',
  38. }),
  39. ]
  40. },
  41. module: {
  42. rules: [
  43. {
  44. test: /\.m?js$/,
  45. exclude: /node_modules/,
  46. use: {
  47. loader: 'babel-loader',
  48. options: {
  49. presets: [
  50. [
  51. '@babel/preset-env',
  52. {
  53. useBuiltIns: 'usage',
  54. corejs: 3,
  55. },
  56. ],
  57. ],
  58. },
  59. },
  60. },
  61. {
  62. test: /\.tsx?$/,
  63. use: 'ts-loader',
  64. }
  65. ],
  66. },
  67. output: {
  68. path: path.resolve(__dirname, 'dist'),
  69. filename: '[name].js',
  70. },
  71. plugins: [
  72. // new Dotenv({ systemvars: true }),
  73. new ForkTsCheckerWebpackPlugin(),
  74. // new BundleAnalyzerPlugin(),
  75. new LodashModuleReplacementPlugin(),
  76. new webpack.DefinePlugin({
  77. 'process.env.BUILD_TIME': JSON.stringify(format(new Date(), 'yyyy-MM-dd HH:mm:ss')),
  78. }),
  79. ],
  80. };