From d997b819062b033eeaf592a4b682865096028c76 Mon Sep 17 00:00:00 2001 From: Paul Gascou-Vaillancourt Date: Sat, 11 Aug 2018 19:25:41 -0400 Subject: [PATCH] feat: Add option to automatically add vue-i18n-loader to Webpack config vue-i18n-loader: https://github.com/kazupon/vue-i18n-loader Closes #58 --- package.json | 1 + src/helpers/constants.js | 1 + src/module.js | 8 ++++++++ yarn.lock | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/package.json b/package.json index cc7e5f2c0..c55c6ace8 100755 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ ] }, "dependencies": { + "@kazupon/vue-i18n-loader": "^0.3.0", "acorn": "^5.6.2", "cookie": "^0.3.1", "esm": "3.0.28", diff --git a/src/helpers/constants.js b/src/helpers/constants.js index 7c5870621..b07e801b6 100644 --- a/src/helpers/constants.js +++ b/src/helpers/constants.js @@ -20,6 +20,7 @@ export const STRATEGIES = { export const COMPONENT_OPTIONS_KEY = 'nuxtI18n' export const DEFAULT_OPTIONS = { vueI18n: {}, + vueI18nLoader: false, locales: [], defaultLocale: null, routesNameSeparator: '___', diff --git a/src/module.js b/src/module.js index 7ef82bd33..72f9d93ac 100644 --- a/src/module.js +++ b/src/module.js @@ -98,6 +98,14 @@ export default function (userOptions) { this.options.build.vendor.push('vue-i18n') } + // Add vue-i18n-loader if applicable + if (options.vueI18nLoader) { + this.extendBuild(config => { + config.module.rules.find(el => el.loader === 'vue-loader') + .options.loaders.i18n = '@kazupon/vue-i18n-loader' + }) + } + this.options.router.middleware.push('i18n') this.options.render.bundleRenderer.directives = this.options.render.bundleRenderer.directives || {} this.options.render.bundleRenderer.directives.t = i18nExtensions.directive diff --git a/yarn.lock b/yarn.lock index b487396ca..bd64bc938 100644 --- a/yarn.lock +++ b/yarn.lock @@ -660,6 +660,10 @@ version "1.4.0" resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7" +"@kazupon/vue-i18n-loader@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@kazupon/vue-i18n-loader/-/vue-i18n-loader-0.3.0.tgz#e068de2d75d891275814ae28ad1fcaf1b537694f" + "@mrmlnc/readdir-enhanced@^2.2.1": version "2.2.1" resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"