我使用的是Electron样板,从这里开始:https://github.com/szwacz/electron-boilerplate/
它使用gulp汇总来捆绑资产,并且开发服务器可以使用npm start
运行。
以下是我从app.js
:导入的声明
import os from 'os';
import { remote } from 'electron';
import jetpack from 'fs-jetpack';
import env from './env';
import jquery from 'jquery';
import parsley from 'parsleyjs';
import select2 from 'select2/dist/js/select2.js';
import { setupForm } from './form/form';
在npm start
的初始加载中,一切都很好,但当我编辑文件并保存时,触发watch
重新加载构建,我就会得到一个错误:
Error: Could not load select2/dist/js/select2.js (imported by /##/repo-name-example/src/app.js): ENOENT: no such file or directory, open 'select2/dist/js/select2.js'
at /##/repo-name-example/node_modules/rollup/dist/rollup.js:9428:10
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
如果我取消这个过程,再次使用npm start
,一切都会好起来。
为什么它会忘记select2
在哪里?
由于您使用文件路径手动导入,而不是像jquery行那样的命名导入,因此需要使用
import select2 from './select2/dist/js/select2.js';
注意开头的./
。否则,它会有效地查找名为select2/dist/js/select2.js
的模块,而不是使用路径。
您可能还需要将其更改为
import select2 from './node_modules/select2/dist/js/select2.js';
(假设文件夹在那里)