♻️ Migrate Vue from bundled mode to ESM mode

This commit is contained in:
KaKi87 2022-03-16 20:08:17 +01:00
parent d93ec4b046
commit 109d86f4a0
12 changed files with 49 additions and 67 deletions

2
.gitignore vendored
View File

@ -1,6 +1,4 @@
.idea
node_modules
config.js
.parcel-cache
dist
build

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "src-vue"]
path = src-vue
url = https://git.kaki87.net/KaKi87/template-vue3-parcel2-src.git

View File

@ -1,21 +1,10 @@
import fs from 'fs';
import { Parcel } from '@parcel/core';
import electronBuilder from 'electron-builder';
process.env['PARCEL_WORKER_BACKEND'] = 'process';
(async () => {
fs.rmdirSync('./dist', { recursive: true });
fs.rmdirSync('./build', { recursive: true });
const packageFileLines = fs.readFileSync('./package.json', 'utf8').split('\n');
fs.writeFileSync('./package.json', [...packageFileLines.slice(0, 2), ...packageFileLines.slice(4)].join('\n'));
await new Parcel({
entries: 'src-vue/index.html',
defaultConfig: '@parcel/config-default',
env: { NODE_ENV: 'production' },
defaultTargetOptions: { publicUrl: '.' }
}).run();
fs.writeFileSync('./package.json', packageFileLines.join('\n'));
await electronBuilder.build({
targets: {
'linux': electronBuilder.Platform.LINUX.createTarget(),
@ -35,7 +24,7 @@ process.env['PARCEL_WORKER_BACKEND'] = 'process';
...fs
.readFileSync('./.gitignore', 'utf8')
.split('\n')
.filter(item => !['dist', 'node_modules', 'config.js'].includes(item))
.filter(item => !['node_modules', 'config.js'].includes(item))
].includes(item.name))
.map(item => `${item.name}${item.isDirectory() ? '/**' : ''}`),
directories: {

View File

@ -6,7 +6,5 @@ module.exports = {
/** @type {boolean} */
isMenuBarEnabled: false,
/** @type {boolean} */
isCorsEnabled: false,
/** @type {number} */
devServerPort: 1234
isCorsEnabled: false
};

10
main.js
View File

@ -13,8 +13,7 @@ const
isSpellcheckEnabled,
isTitleBarEnabled,
isMenuBarEnabled,
isCorsEnabled,
devServerPort
isCorsEnabled
} = require('./config.js');
(async () => {
@ -53,11 +52,8 @@ const
mode: 'detach',
activate: !app.isPackaged
});
if(app.isPackaged){
if(app.isPackaged)
mainWindow.webContents.closeDevTools();
await mainWindow.loadFile('./dist/index.html');
}
else
await mainWindow.loadURL(`http://localhost:${devServerPort}/`);
await mainWindow.loadFile('./src-vue/index.html');
mainWindow.show();
})();

View File

@ -6,9 +6,6 @@
"author": "KaKi87 <KaKi87@pm.me>",
"license": "MIT",
"devDependencies": {
"@parcel/config-default": "^2.2.1",
"@parcel/core": "^2.2.1",
"@parcel/transformer-vue": "^2.2.1",
"electron": "^17.0.0",
"electron-builder": "^22.14.13",
"electron-devtools-installer": "^3.2.0",

@ -1 +0,0 @@
Subproject commit 3e0a19bee7cb276c1e9a16ae111226f7aab39f67

View File

@ -0,0 +1,6 @@
export default createApp => createApp({
template: `
<AppMain>
</AppMain>
`
});

View File

@ -0,0 +1,13 @@
export default app => app.component(
'AppMain',
{
'data': () => ({
message: 'Hello, World !'
}),
template: `
<main class="App__Main">
{{ message }}
</main>
`
}
);

21
src-vue/index.html Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<!--suppress JSUnresolvedFunction -->
<html lang="en">
<head>
<title>template-vue3-cdn</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="module">
import { createApp } from '../node_modules/vue/dist/vue.esm-browser.js';
import App from './components/App.js';
import AppMain from './components/AppMain.js';
const app = App(createApp);
AppMain(app);
document.addEventListener('DOMContentLoaded', () => app.mount('.app'));
</script>
</head>
<body class="app"></body>
</html>

View File

@ -1,15 +1,4 @@
import { spawn } from 'child_process';
import { Parcel } from '@parcel/core';
import electron from 'electron';
import config from './config.js';
(async () => {
await new Parcel({
entries: 'src-vue/index.html',
defaultConfig: '@parcel/config-default',
env: { NODE_ENV: 'development' },
serveOptions: { port: config.devServerPort },
hmrOptions: { port: config.devServerPort }
}).watch();
const child = spawn(electron, ['main.js'], { stdio: 'inherit' });
child.on('close', () => process.exit());
})();
const child = spawn(electron, ['main.js'], { stdio: 'inherit' });
child.on('close', () => process.exit());

View File

@ -917,20 +917,6 @@
posthtml-render "^3.0.0"
semver "^5.7.1"
"@parcel/transformer-vue@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@parcel/transformer-vue/-/transformer-vue-2.2.1.tgz#09f3aeb8d116ab37614015c0aebf6b401d3c1823"
integrity sha512-WbyXukOuPihO5wP3WwamZ/34r1Pcs9fFruz3+zE+jRKn7GNKLJcW91d09CppuZyWxm6ZhVrOU2gdmP5rayfAxA==
dependencies:
"@parcel/diagnostic" "^2.2.1"
"@parcel/plugin" "^2.2.1"
"@parcel/source-map" "^2.0.0"
"@parcel/utils" "^2.2.1"
"@vue/compiler-sfc" "^3.2.27"
consolidate "^0.16.0"
nullthrows "^1.1.1"
semver "^5.7.1"
"@parcel/types@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@parcel/types/-/types-2.2.1.tgz#c27d57dbc5be5bdee18ab22222f731b3de494d4c"
@ -1115,7 +1101,7 @@
"@vue/compiler-core" "3.2.30"
"@vue/shared" "3.2.30"
"@vue/compiler-sfc@3.2.30", "@vue/compiler-sfc@^3.2.27":
"@vue/compiler-sfc@3.2.30":
version "3.2.30"
resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.2.30.tgz#9d2e56adb859059551fc1204bc37503f168c4d0c"
integrity sha512-P/5YpILtcQY92z72gxhkyOUPHVskEzhSrvYi91Xcr+csOxaDaYU5OqOxCzZKcf3Og70Tat404vO1OHrwprN90A==
@ -1398,7 +1384,7 @@ bluebird-lst@^1.0.9:
dependencies:
bluebird "^3.5.5"
bluebird@^3.5.0, bluebird@^3.5.5, bluebird@^3.7.2:
bluebird@^3.5.0, bluebird@^3.5.5:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
@ -1881,13 +1867,6 @@ console-browserify@^1.2.0:
resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.2.0.tgz#67063cef57ceb6cf4993a2ab3a55840ae8c49336"
integrity sha512-ZMkYO/LkF17QvCPqM0gxw8yUzigAOZOSWSHg91FH6orS7vcEj5dVZTidN2fQ14yBSdg97RqhSNwLUXInd52OTA==
consolidate@^0.16.0:
version "0.16.0"
resolved "https://registry.yarnpkg.com/consolidate/-/consolidate-0.16.0.tgz#a11864768930f2f19431660a65906668f5fbdc16"
integrity sha512-Nhl1wzCslqXYTJVDyJCu3ODohy9OfBMB5uD2BiBTzd7w+QY0lBzafkR8y8755yMYHAaMD4NuzbAw03/xzfw+eQ==
dependencies:
bluebird "^3.7.2"
constants-browserify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/constants-browserify/-/constants-browserify-1.0.0.tgz#c20b96d8c617748aaf1c16021760cd27fcb8cb75"