Skip to content

Commit

Permalink
fix: avoid using commonjs for runtime (vite support) (#1080)
Browse files Browse the repository at this point in the history
Co-authored-by: Rafał Chłodnicki <[email protected]>
  • Loading branch information
rchl authored Mar 1, 2021
2 parents 03585e4 + 31532e7 commit a9003b4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/templates/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function stringifyValue(value) {

for (const [key, value] of Object.entries(options)) {
if (key === 'vueI18n' && typeof value === 'string') {
%>export const <%= key %> = require('<%= value %>').default
%>export const <%= key %> = (context) => import('<%= value %>').then(m => m.default(context))
<%
} else {
%>export const <%= key %> = <%= stringifyValue(value) %>
Expand Down
4 changes: 2 additions & 2 deletions src/templates/plugin.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
setLocaleCookie,
syncVuex
} from './utils-common'
import { loadLanguageAsync } from './utils'
import { klona } from '~i18n-klona'

Vue.use(VueI18n)
Expand Down Expand Up @@ -90,7 +91,6 @@ export default async (context) => {

// Lazy-loading enabled
if (lazy) {
const { loadLanguageAsync } = require('./utils')
const i18nFallbackLocale = app.i18n.fallbackLocale

// Load fallback locale(s).
Expand Down Expand Up @@ -294,7 +294,7 @@ export default async (context) => {
}

// Set instance options
const vueI18nOptions = typeof vueI18n === 'function' ? vueI18n(context) : klona(vueI18n)
const vueI18nOptions = typeof vueI18n === 'function' ? await vueI18n(context) : klona(vueI18n)
vueI18nOptions.componentInstanceCreatedListener = extendVueI18nInstance
app.i18n = new VueI18n(vueI18nOptions)
// Initialize locale and fallbackLocale as vue-i18n defaults those to 'en-US' if falsey
Expand Down
2 changes: 1 addition & 1 deletion src/templates/utils-common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Cookie from 'cookie'
import JsCookie from 'js-cookie'
import isHTTPS from 'is-https'

/**
* Parses locales provided from browser through `accept-language` header.
Expand Down Expand Up @@ -104,7 +105,6 @@ export const getDomainFromLocale = (localeCode, req, { locales, localeDomainKey,
if (lang && lang[localeDomainKey]) {
let protocol
if (process.server) {
const isHTTPS = require('is-https')
protocol = (req && isHTTPS(req)) ? 'https' : 'http'
} else {
protocol = window.location.protocol.split(':')[0]
Expand Down

0 comments on commit a9003b4

Please sign in to comment.