ruby-on-rails 代码拆分时esbuild超时

mrphzbgm  于 2022-11-19  发布在  Ruby
关注(0)|答案(1)|浏览(110)

在Rails 7应用程序中使用esbuild,我已经成功地将代码拆分为2个包:一个带有StimulusJS控制器,另一个带有ReactJS应用程序。配置在开发中工作正常。
当推送到CI(GitHub操作)或直接推送到Heroku时,它会超时。

包. json
"scripts": {
    "build": "node app/assets/config/esbuild.js",
    "build:css": "sass ./app/assets/stylesheets/application.sass.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
  }

配置文件

const path = require('path');

require("esbuild").build({
  entryPoints: ["stimulus.js","article.js"],
  bundle: true,
  minify: true,
  outdir: path.join(process.cwd(), "app/assets/builds"),
  absWorkingDir: path.join(process.cwd(), "app/javascript"),
  watch: true,
  loader: { '.js': 'jsx' },
  publicPath: 'assets',
  target: 'es6',
  // custom plugins will be inserted is this array
  plugins: [],
}).catch(() => process.exit(1));
GitHub操作
yarn install v1.22.19
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.13s.
yarn run v1.22.19
$ node app/assets/config/esbuild.js
Error: The operation was canceled.

希鲁
挂在此台阶上

remote:        $ node app/assets/config/esbuild.js
ds97pgxw

ds97pgxw1#

解决方案是删除watch: true

const path = require('path');

require("esbuild").build({
  entryPoints: ["stimulus.js","article.js"],
  bundle: true,
  minify: true,
  outdir: path.join(process.cwd(), "app/assets/builds"),
  absWorkingDir: path.join(process.cwd(), "app/javascript"),
  watch: false,  // set to true in dev
  loader: { '.js': 'jsx' },
  publicPath: 'assets',
  target: 'es6',
  // custom plugins will be inserted is this array
  plugins: [],
}).catch(() => process.exit(1));

更新

对于其他正在与此斗争的人,请参见project上更新的解决方案和讨论。

const path = require('path');

console.log("NODE_ENV: " + process.env.NODE_ENV);
console.log("CI: " + process.env.CI);
console.log(!(process.env.NODE_ENV === 'production' || process.env.CI));

require("esbuild").build({
  entryPoints: ["stimulus.js","article.js"],
  bundle: true,
  minify: true,
  outdir: path.join(process.cwd(), "app/assets/builds"),
  absWorkingDir: path.join(process.cwd(), "app/javascript"),
  watch: !(process.env.NODE_ENV === 'production' || process.env.CI),
  loader: { '.js': 'jsx' },
  publicPath: 'assets',
  target: 'es6',
  // custom plugins will be inserted is this array
  plugins: [],
}).catch(() => process.exit(1));

相关问题