refs #901 Use window object in index.ejs

This commit is contained in:
AkiraFukushima 2019-11-26 22:27:48 +09:00
parent 1627472682
commit a635cce89d
6 changed files with 22 additions and 9 deletions

View File

@ -6,7 +6,7 @@
<% if (htmlWebpackPlugin.options.nodeModules) { %>
<!-- Add `node_modules/` to global paths so `require` works properly in development -->
<script>
require('module').globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
window.mod.globalPaths.push('<%= htmlWebpackPlugin.options.nodeModules.replace(/\\/g, '\\\\') %>')
</script>
<% } %>
</head>
@ -14,7 +14,7 @@
<div id="app"></div>
<!-- Set `__static` path to static files in production -->
<script>
if (process.env.NODE_ENV !== 'development') window.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
if (window.node_env !== 'development') window.__static = window.static_path
</script>
<!-- webpack builds are automatically injected -->

View File

@ -1,5 +1,11 @@
const electron = require('electron')
const path = require('path')
const mod = require('module')
global.ipcRenderer = electron.ipcRenderer
global.shell = electron.shell
global.clipboard = electron.clipboard
global.process = process
global.node_env = process.env.NODE_ENV
global.platform = process.platform
global.path = path
global.mod = mod
global.static_path = path.join(__dirname, '/static').replace(/\\/g, '\\\\')

View File

@ -9,6 +9,7 @@ import PreferencesAppearance from '@/components/Preferences/Appearance.vue'
import PreferencesNotification from '@/components/Preferences/Notification.vue'
import PreferencesAccount from '@/components/Preferences/Account.vue'
import PreferencesLanguage from '@/components/Preferences/Language.vue'
import PreferencesNetwork from '@/components/Preferences/Network.vue'
import GlobalHeader from '@/components/GlobalHeader.vue'
import Settings from '@/components/Settings.vue'
import SettingsGeneral from '@/components/Settings/General.vue'
@ -28,6 +29,7 @@ import TimelineSpaceContentsDirectMessages from '@/components/TimelineSpace/Cont
import TimelineSpaceContentsListsIndex from '@/components/TimelineSpace/Contents/Lists/Index.vue'
import TimelineSpaceContentsListsEdit from '@/components/TimelineSpace/Contents/Lists/Edit.vue'
import TimelineSpaceContentsListsShow from '@/components/TimelineSpace/Contents/Lists/Show.vue'
import TimelineSpaceContentsFollowRequests from '@/components/TimelineSpace/Contents/FollowRequests.vue'
Vue.use(Router)
@ -72,7 +74,7 @@ const router = new Router({
{
path: 'network',
name: 'network',
component: require('@/components/Preferences/Network').default
component: PreferencesNetwork
},
{
path: 'language',
@ -123,7 +125,7 @@ const router = new Router({
{
path: 'follow-requests',
name: 'follow-requests',
component: require('@/components/TimelineSpace/Contents/FollowRequests').default
component: TimelineSpaceContentsFollowRequests
},
{
path: 'favourites',

View File

@ -4,6 +4,9 @@ import { RootState } from '@/store'
import { Sound } from '~/src/types/sound'
import { Timeline } from '~/src/types/timeline'
import { BaseConfig, General, Other } from '~/src/types/preference'
import { MyWindow } from '~/src/types/global'
const win = window as MyWindow
export type GeneralState = {
general: General
@ -141,7 +144,7 @@ const actions: ActionTree<GeneralState, RootState> = {
const getters: GetterTree<GeneralState, RootState> = {
notDarwin: () => {
return process.platform !== 'darwin'
return win.platform !== 'darwin'
}
}

View File

@ -30,8 +30,8 @@ export interface RootState {
}
export default new Vuex.Store({
strict: win.process.env.NODE_ENV !== 'production',
plugins: win.process.env.NODE_ENV !== 'production' ? [createLogger({})] : [],
strict: win.node_env !== 'production',
plugins: win.node_env !== 'production' ? [createLogger({})] : [],
modules: {
App,
GlobalHeader,

View File

@ -4,5 +4,7 @@ export interface MyWindow extends Window {
shell: Shell
ipcRenderer: IpcRenderer
clipboard: Clipboard
process: NodeJS.Process
node_env: string
platform: string
static_path: string
}