京都のkintone用javascript
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

109 lines
2.9KB

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