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:
parent
b2f3a855b0
commit
b453b01b81
|
@ -60,8 +60,6 @@ class ProcessLocalesPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
|
|
||||||
this.locales = null
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
startRenderer(startMain)
|
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)
|
||||||
|
} else {
|
||||||
|
startWeb(({ port }) => {
|
||||||
|
open(`http://localhost:${port}`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -24,7 +24,9 @@ const config = {
|
||||||
filename: '[name].js',
|
filename: '[name].js',
|
||||||
},
|
},
|
||||||
externals: {
|
externals: {
|
||||||
electron: '{}'
|
electron: '{}',
|
||||||
|
ytpl: '{}',
|
||||||
|
ytsr: '{}'
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
|
@ -168,14 +170,15 @@ 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'),
|
||||||
outputDir: 'static/locales',
|
outputDir: 'static/locales',
|
||||||
})
|
})
|
||||||
|
|
||||||
config.plugins.push(
|
config.plugins.push(
|
||||||
processLocalesPlugin,
|
processLocalesPlugin,
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env.LOCALE_NAMES': JSON.stringify(processLocalesPlugin.localeNames)
|
'process.env.LOCALE_NAMES': JSON.stringify(processLocalesPlugin.localeNames)
|
||||||
|
@ -202,7 +205,7 @@ if (isDevMode) {
|
||||||
resourceRegExp: /^js-yaml$/,
|
resourceRegExp: /^js-yaml$/,
|
||||||
contextRegExp: /i18n$/
|
contextRegExp: /i18n$/
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = config
|
module.exports = config
|
||||||
|
|
|
@ -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 ./",
|
||||||
|
|
|
@ -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') {
|
||||||
|
|
|
@ -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
|
||||||
|
@ -70,7 +71,6 @@ class CustomVueI18n extends VueI18n {
|
||||||
this.setLocaleMessage(locale, data)
|
this.setLocaleMessage(locale, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue