Upgrade to v5.x using `vue upgrade --next`. Update `vue.config.js` to import and use `defineConfig`, because it provides type safety and created by Vue CLI 5 as default. Vue CLI 5.x upgrades from webpack 4 to 5. It causes some issues that this commit attemps to fix: 1. Fail due to webpack resolving of Ace. Third-party dependency (code editor) Ace uses legacy `file-loader` for webpack resolving. It's not supported in webpack 5. So change it with manual imports. Refs: ajaxorg/ace-builds#211, ajaxorg/ace-builds#221. 2. Wehpack drops polyfilling node core modules (`path`, `fs`, etc.). Webpack does not polyfill those modules by default anymore. This is good because they did not need browser polyfilling as they are used in desktop version only and resolved already by Electron. To resolve errors (using webpack recommendations): - Add typeof check around `process` variable. - Tell webpack explicitly to ignore used node modules. 3. Fail due to legacy dependency of vue-cli-plugin-electron-builder. This plugin is used for electron builds and development. It still uses webpack 4 that leads to failed builds. Downgrading `ts-loader` to latest version which has support for `loader-utils` solves the problem (typestrong/ts-loader#1288). Related issue: nklayman/vue-cli-plugin-electron-builder#1625 4. Compilation fails due to webpack loading of `fsevents` on macOS. This happens only when running `vue-cli-service test:unit` command (used in integration tests and unit tests). Other builds work fine. Refs: yan-foto/electron-reload#71, nklayman/vue-cli-plugin-electron-builder#712, nklayman/vue-cli-plugin-electron-builder#1333
67 lines
2.8 KiB
JavaScript
67 lines
2.8 KiB
JavaScript
const { defineConfig } = require('@vue/cli-service');
|
|
|
|
loadVueAppRuntimeVariables();
|
|
|
|
module.exports = defineConfig({
|
|
chainWebpack: (config) => {
|
|
changeAppEntryPoint('./src/presentation/main.ts', config);
|
|
},
|
|
configureWebpack:{
|
|
resolve: {
|
|
alias: { // also requires path alias in tsconfig.json
|
|
"@tests": require('path').resolve(__dirname, 'tests/'),
|
|
},
|
|
fallback: {
|
|
/* Tell webpack to ignore polyfilling them because Node core modules are never used
|
|
for browser code but only for desktop where Electron supports them. */
|
|
...ignorePolyfills('os', 'child_process', 'fs', 'path'),
|
|
}
|
|
},
|
|
// Fix compilation failing on macOS when running unit/integration tests
|
|
externals: ['fsevents'],
|
|
},
|
|
pluginOptions: {
|
|
// https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html#native-modules
|
|
electronBuilder: {
|
|
mainProcessFile: './src/presentation/electron/main.ts', // https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/configuration.html#webpack-configuration
|
|
nodeIntegration: true, // required to reach Node.js APIs for environment specific logic
|
|
// https://www.electron.build/configuration/configuration
|
|
builderOptions: {
|
|
publish: [{
|
|
// https://www.electron.build/configuration/publish#githuboptions
|
|
// https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/recipes.html#enable-publishing-to-github
|
|
provider: 'github',
|
|
vPrefixedTagName: false, // default: true
|
|
releaseType: 'release' // or "draft" (default), "prerelease"
|
|
}],
|
|
mac: { // https://www.electron.build/configuration/mac
|
|
target: 'dmg',
|
|
},
|
|
win: { // https://www.electron.build/configuration/win
|
|
target: 'nsis',
|
|
},
|
|
linux: { // https://www.electron.build/configuration/linux
|
|
target: 'AppImage',
|
|
}
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
function changeAppEntryPoint(entryPath, config) {
|
|
config.entry('app').clear().add(entryPath).end();
|
|
}
|
|
|
|
function loadVueAppRuntimeVariables() {
|
|
const packageJson = require('./package.json');
|
|
process.env.VUE_APP_VERSION = packageJson.version;
|
|
process.env.VUE_APP_NAME = packageJson.name;
|
|
process.env.VUE_APP_REPOSITORY_URL = packageJson.repository.url;
|
|
process.env.VUE_APP_HOMEPAGE_URL = packageJson.homepage;
|
|
};
|
|
|
|
function ignorePolyfills(...moduleNames) {
|
|
return moduleNames
|
|
.reduce((obj, module) => { obj[module] = false; return obj; }, {});
|
|
}
|