京都のkintone用javascript
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

112 行
3.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 Dotenv = require('dotenv-webpack');
  9. const dotenv = require('dotenv');
  10. const { format } = require('date-fns');
  11. const basePath = path.resolve('src', 'apps');
  12. const env = dotenv.config().parsed
  13. // basePath配下の各ディレクトリを複数のentryとする
  14. const entries = glob.sync('**/index.+(js|ts|tsx)', { cwd: basePath }).reduce(
  15. (prev, file) => ({
  16. ...prev,
  17. [path.dirname(file)]: path.resolve(basePath, file),
  18. }),
  19. {}
  20. );
  21. module.exports = {
  22. entry: entries,
  23. cache: false,
  24. resolve: {
  25. // 拡張子を配列で指定
  26. extensions: [
  27. '.ts', '.js',
  28. ],
  29. plugins: [
  30. new TsconfigPathsPlugin({
  31. configFile: './tsconfig.json',
  32. }),
  33. ]
  34. },
  35. module: {
  36. rules: [
  37. {
  38. test: /\.m?js$/,
  39. exclude: /node_modules/,
  40. use: {
  41. loader: 'babel-loader',
  42. options: {
  43. presets: [
  44. [
  45. '@babel/preset-env',
  46. {
  47. useBuiltIns: 'usage',
  48. corejs: 3,
  49. },
  50. ],
  51. ],
  52. },
  53. },
  54. },
  55. {
  56. test: /\.tsx?$/,
  57. use: 'ts-loader',
  58. }
  59. ],
  60. },
  61. output: {
  62. path: path.resolve(__dirname, 'dist'),
  63. filename: '[name].js',
  64. },
  65. plugins: [
  66. // new Dotenv({ systemvars: true }),
  67. new ForkTsCheckerWebpackPlugin(),
  68. // new BundleAnalyzerPlugin(),
  69. {
  70. // watchモードのとき再ビルドされたものをアップロードする
  71. apply: (compiler) => {
  72. compiler.hooks.afterEmit.tapPromise(
  73. 'upload javascript files',
  74. (compilation) => {
  75. if (!compiler.options.watch) return Promise.resolve();
  76. const emittedFiles = Object.keys(compilation.assets)
  77. .filter((file) => {
  78. const source = compilation.assets[file];
  79. return source.emitted && source.existsAt;
  80. })
  81. .map((file) => file.replace('.js', ''));
  82. const processes = glob
  83. .sync(`@(${emittedFiles.join('|')})/customize-manifest.json`, {
  84. cwd: basePath,
  85. })
  86. .map((file) => {
  87. console.log('\nuploading... ', file);
  88. return exec(
  89. `yarn upload ${path.resolve(basePath, file)}`,
  90. (err, stdout, stderr) => {
  91. if (stdout) process.stdout.write(stdout);
  92. if (stderr) process.stderr.write(stderr);
  93. }
  94. );
  95. });
  96. return Promise.all(processes);
  97. }
  98. );
  99. },
  100. },
  101. new webpack.DefinePlugin({
  102. 'process.env.BUILD_TIME': JSON.stringify(format(new Date(), 'yyyy-MM-dd HH:mm:ss')),
  103. }),
  104. ],
  105. };