Adding web support to dev-runner (#2729)

* Adding ytpl and ytsr as externals in web.config

This should get rid of those two warnings that were
showing up on web builds

* Reducing discrepancies between dev and prod in web builds

* Removing  a line which would prevent hot reloading

`this.locales` is retained between hot reloads, so it shouldn't
be set to `null`.

* Adding a new flag to the dev runner

Adding a new command: `run dev:web`

* Running `loadLocale` in development web builds

* Adding a line back which was removed

* Removing a line which was added
This commit is contained in:
Emma 2022-10-18 08:50:32 -04:00 committed by GitHub
parent b2f3a855b0
commit b453b01b81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 121 additions and 84 deletions

View File

@ -60,8 +60,6 @@ class ProcessLocalesPlugin {
} }
await Promise.all(promises) await Promise.all(promises)
this.locales = null
}) })
}) })
} }

View File

@ -1,5 +1,6 @@
process.env.NODE_ENV = 'development' process.env.NODE_ENV = 'development'
const open = require('open')
const electron = require('electron') const electron = require('electron')
const webpack = require('webpack') const webpack = require('webpack')
const WebpackDevServer = require('webpack-dev-server') const WebpackDevServer = require('webpack-dev-server')
@ -10,13 +11,14 @@ const { spawn } = require('child_process')
const mainConfig = require('./webpack.main.config') const mainConfig = require('./webpack.main.config')
const rendererConfig = require('./webpack.renderer.config') const rendererConfig = require('./webpack.renderer.config')
const webConfig = require('./webpack.web.config')
const workersConfig = require('./webpack.workers.config') const workersConfig = require('./webpack.workers.config')
let electronProcess = null let electronProcess = null
let manualRestart = null let manualRestart = null
const remoteDebugging = !!(
process.argv[2] && process.argv[2] === '--remote-debug' const remoteDebugging = process.argv.indexOf('--remote-debug') !== -1
) const web = process.argv.indexOf('--web') !== -1
if (remoteDebugging) { if (remoteDebugging) {
// disable dvtools open in electron // disable dvtools open in electron
@ -87,7 +89,6 @@ function startMain() {
manualRestart = true manualRestart = true
await restartElectron() await restartElectron()
setTimeout(() => { setTimeout(() => {
manualRestart = false manualRestart = false
}, 2500) }, 2500)
@ -135,4 +136,38 @@ function startRenderer(callback) {
}) })
} }
function startWeb (callback) {
const compiler = webpack(webConfig)
const { name } = compiler
compiler.hooks.afterEmit.tap('afterEmit', () => {
console.log(`\nCompiled ${name} script!`)
console.log(`\nWatching file changes for ${name} script...`)
})
const server = new WebpackDevServer({
static: {
directory: path.join(process.cwd(), 'dist/web/static'),
watch: {
ignored: [
/(dashFiles|storyboards)\/*/,
'/**/.DS_Store',
]
}
},
port
}, compiler)
server.startCallback(err => {
if (err) console.error(err)
callback({ port: server.options.port })
})
}
if (!web) {
startRenderer(startMain) startRenderer(startMain)
} else {
startWeb(({ port }) => {
open(`http://localhost:${port}`)
})
}

View File

@ -24,7 +24,9 @@ const config = {
filename: '[name].js', filename: '[name].js',
}, },
externals: { externals: {
electron: '{}' electron: '{}',
ytpl: '{}',
ytsr: '{}'
}, },
module: { module: {
rules: [ rules: [
@ -168,7 +170,8 @@ if (isDevMode) {
__static: `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`, __static: `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`,
}) })
) )
} else { }
const processLocalesPlugin = new ProcessLocalesPlugin({ const processLocalesPlugin = new ProcessLocalesPlugin({
compress: false, compress: false,
inputDir: path.join(__dirname, '../static/locales'), inputDir: path.join(__dirname, '../static/locales'),
@ -203,6 +206,6 @@ if (isDevMode) {
contextRegExp: /i18n$/ contextRegExp: /i18n$/
}) })
) )
}
module.exports = config module.exports = config

View File

@ -29,6 +29,7 @@
"debug": "run-s rebuild:electron debug-runner", "debug": "run-s rebuild:electron debug-runner",
"debug-runner": "node _scripts/dev-runner.js --remote-debug", "debug-runner": "node _scripts/dev-runner.js --remote-debug",
"dev": "run-s rebuild:electron dev-runner", "dev": "run-s rebuild:electron dev-runner",
"dev:web": "node _scripts/dev-runner.js --web",
"dev-runner": "node _scripts/dev-runner.js", "dev-runner": "node _scripts/dev-runner.js",
"lint-fix": "eslint --fix --ext .js,.vue ./", "lint-fix": "eslint --fix --ext .js,.vue ./",
"lint": "eslint --ext .js,.vue ./", "lint": "eslint --ext .js,.vue ./",

View File

@ -117,7 +117,7 @@ export default Vue.extend({
this.$t('Settings.General Settings.System Default') this.$t('Settings.General Settings.System Default')
] ]
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development' && process.env.IS_ELECTRON) {
Object.entries(this.$i18n.messages).forEach(([locale, localeData]) => { Object.entries(this.$i18n.messages).forEach(([locale, localeData]) => {
const localeName = localeData['Locale Name'] const localeName = localeData['Locale Name']
if (typeof localeName !== 'undefined') { if (typeof localeName !== 'undefined') {

View File

@ -9,8 +9,9 @@ const isDev = process.env.NODE_ENV === 'development'
const messages = {} const messages = {}
if (isDev) { if (isDev && process.env.IS_ELECTRON) {
const { load } = require('js-yaml') const { load } = require('js-yaml')
// Take active locales and load respective YAML file // Take active locales and load respective YAML file
activeLocales.forEach((locale) => { activeLocales.forEach((locale) => {
try { try {
@ -30,8 +31,8 @@ class CustomVueI18n extends VueI18n {
} }
async loadLocale(locale) { async loadLocale(locale) {
// we only lazy load locales for producation builds // we don't lazy load locales in development in electron
if (!isDev) { if (isDev && process.env.IS_ELECTRON) { return }
// don't need to load it if it's already loaded // don't need to load it if it's already loaded
if (this.availableLocales.includes(locale)) { if (this.availableLocales.includes(locale)) {
return return
@ -71,7 +72,6 @@ class CustomVueI18n extends VueI18n {
} }
} }
} }
}
Vue.use(CustomVueI18n) Vue.use(CustomVueI18n)
@ -81,7 +81,7 @@ const i18n = new CustomVueI18n({
messages messages
}) })
if (!isDev) { if (!isDev || !process.env.IS_ELECTRON) {
i18n.loadLocale('en-US') i18n.loadLocale('en-US')
} }

View File

@ -318,7 +318,7 @@ const stateWithSideEffects = {
} }
} }
if (process.env.NODE_ENV !== 'development') { if (process.env.NODE_ENV !== 'development' || !process.env.IS_ELECTRON) {
await i18n.loadLocale(targetLocale) await i18n.loadLocale(targetLocale)
} }