Chatter Desktop という Electron アプリ を作っていて真っ先にハマったところのメモ。
Lightning Design System という CSS フレームワークを入れようとしたところ、以下のエラーとなった。
$ git clone --depth=1 https://github.com/chentsulin/electron-react-boilerplate.git your-project-name $ cd your-project-name $ yarn $ yarn add @salesforce-ux/design-system ... ERROR in dll renderer Module not found: Error: Can't resolve '@salesforce-ux/design-system' in '/Users/yamazaki/workspace/electron/electron-react-boilerplate' @ dll renderer ERROR in ./node_modules/bootstrap/dist/js/bootstrap.js Module not found: Error: Can't resolve 'jquery' in '/Users/yamazaki/workspace/electron/electron-react-boilerplate/node_modules/bootstrap/dist/js' @ ./node_modules/bootstrap/dist/js/bootstrap.js 7:81-98 @ dll renderer ERROR in ./node_modules/bootstrap/dist/js/bootstrap.js Module not found: Error: Can't resolve 'popper.js' in '/Users/yamazaki/workspace/electron/electron-react-boilerplate/node_modules/bootstrap/dist/js' @ ./node_modules/bootstrap/dist/js/bootstrap.js 7:100-120 @ dll renderer npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! electron-react-boilerplate@0.13.2 build-dll: `cross-env NODE_ENV=development node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.dev.dll.js --colors` npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the electron-react-boilerplate@0.13.2 build-dll script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /Users/yamazaki/.npm/_logs/2018-03-04T21_19_46_858Z-debug.log error Command failed with exit code 2. info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
https://github.com/chentsulin/electron-react-boilerplate/blob/master/package.json#L23
どうやら postinstall スクリプトが走っており、この中で build-dll
という DLL ファイルの生成処理をやろうとして失敗しているよう。
また build-dll
は webpack.config.renderer.dev.dll.js
を見て webpack によるビルドを行っているので、設定ファイルの中身を見る。そうすると
entry: { renderer: ( Object .keys(dependencies || {}) .filter(dependency => dependency !== 'font-awesome') ) },
ここで、元から入っていた font-awesome
については明示的にビルド対象から外しているようだ。
なので手動で
entry: { renderer: ( Object .keys(dependencies || {}) .filter(dependency => { // also ignore installed CSS library return dependency !== 'font-awesome' && dependency !== '@salesforce-ux/design-system'; }) ) },
というふうにインストールする CSS フレームワークをビルド対象から除外してやると、ビルドに成功するようになった。
が、正しい手順なのかがよくわからず、Issue で質問してみることにした。
おまけ: webpack.config.renderer.dev.dll.js
がやっていること
開発時のビルドパフォーマンス向上のために webpack.DLLPlugin というのを使っている。
DLLPlugin についてはきちんと理解したわけではないが、外部ライブラリなど毎回毎回ビルドする必要がないモジュールを DLL バンドルという形で別ファイルに切り出し、require() 時に読み込むらしい。
こちらの記事が非常に参考になった。