我正在尝试将 knex 用于电子应用程序中的 sqlite 本地存储,并且由于 knex 使用了一些在 webpack v5 上存在的 polyfll 组件,因此收到了“重大更改”消息。听说可以使用 node-polyfill-webpack-plugin 把 polyfill 放回去。对于这个项目,我在根目录下创建了一个“webpack.config.js”,并在里面放了以下内容:
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
module.exports = {
// Other rules...
plugins: [
new NodePolyfillPlugin()
]
}
这是我的 package.json:
{
"name": "react_test",
"homepage": "./",
"version": "0.1.0",
"private": true,
"main": "public/electron.js",
"dependencies": {
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"assert": "^2.0.0",
"axios": "^0.21.1",
"babel-loader": "^8.2.2",
"buffer": "^6.0.3",
"constants-browserify": "^1.0.0",
"copy-webpack-plugin": "^7.0.0",
"crypto-browserify": "^3.12.0",
"css-loader": "^5.0.1",
"concurrently": "^6.0.0",
"cross-env": "^7.0.3",
"file-loader": "^6.2.0",
"html-loader": "^1.3.2",
"html-webpack-plugin": "^5.0.0",
"https-browserify": "^1.0.0",
"electron": "^12.0.0",
"electron-is-dev": "^2.0.0",
"knex": "^1.0.1",
"node-polyfill-webpack-plugin": "^1.1.4",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"prettier": "^2.2.1",
"process": "^0.11.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router": "^5.2.1",
"react-router-dom": "^5.2.1",
"react-scripts": "5.0.0",
"regenerator-runtime": "^0.13.7",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"style-loader": "^2.0.0",
"svg-url-loader": "^7.1.1",
"webpack": "^5.21.1",
"webpack-cli": "^3.3.12",
"wait-on": "^5.2.1",
"web-vitals": "^2.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"electron": "wait-on tcp:3000 && electron .",
"electron:build": "npm build && electron-builder -c.extraMetadata.main=build/main.js",
"package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds",
"package-win": "electron-packager . electron-tutorial-app --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"Electron Tutorial App\"",
"package-all": "electron-packager . electron-app --all --asar",
"package-linux": "electron-packager . electron-tutorial-app --overwrite --asar=true --platform=linux --arch=x64 --icon=assets/icons/png/1024x1024.png --prune=true --out=release-builds"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
但是,当我运行“npm start”时,我仍然会收到所有 webpack 重大更改消息。
任何帮助将非常感激。直到我尝试使用任何类型的本地存储(例如 sqlite 或 NEDB)并在 Stack Overflow 上进行了广泛的搜索并尝试了其中一些建议的方法(实际上是 node-polyfill-webpack-插件来自阅读这个网站)但我仍然无法让它工作。