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

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