This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.js
97 lines (88 loc) · 2.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const webpack = require('webpack')
const path = require('path')
const debug = require('debug')('vue-cli-plugin-i18n:service')
module.exports = (api, options) => {
const {
enableInSFC,
localeDir,
runtimeOnly,
enableLegacy,
compositionOnly,
fullInstall
} = options.pluginOptions.i18n
debug('options', options)
const { semver, loadModule } = require(require.resolve(
'@vue/cli-shared-utils'
))
const vue = loadModule('vue', api.service.context)
debug('vue version', vue.version)
const isVue3 = vue && semver.major(vue.version) === 3
if (isVue3) {
api.chainWebpack(webpackConfig => {
debug('chainWebpack called')
// prettier-ignore
webpackConfig.module
.rule('i18n-resource')
.test(/\.(json5?|ya?ml)$/)
.include.add(path.resolve(__dirname, '../../', `./src/${localeDir}`))
.end()
.type('javascript/auto')
.use('i18n-resource')
.loader('@intlify/vue-i18n-loader')
// prettier-ignore
webpackConfig.module
.rule('i18n')
.resourceQuery(/blockType=i18n/)
.type('javascript/auto')
.use('i18n')
.loader('@intlify/vue-i18n-loader')
if (runtimeOnly) {
webpackConfig.resolve.alias.set(
'vue-i18n',
'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
)
debug('set vue-i18n runtime only')
}
// prettier-ignore
const legacyApiFlag = enableLegacy
? 'true'
: compositionOnly
? 'false' : 'true'
const installFlag = fullInstall ? 'true' : 'false'
webpackConfig.plugin('vue-i18n-feature-flags').use(webpack.DefinePlugin, [
{
__VUE_I18N_LEGACY_API__: legacyApiFlag,
__VUE_I18N_FULL_INSTALL__: installFlag,
__VUE_I18N_PROD_DEVTOOLS__: 'false'
}
])
debug(
'set __VUE_I18N_LEGACY_API__ and __VUE_I18N_FULL_INSTALL',
legacyApiFlag,
installFlag
)
})
} else {
api.chainWebpack(webpackConfig => {
debug('chainWebpack called')
if (enableInSFC) {
// prettier-ignore
webpackConfig.module
.rule('i18n')
.resourceQuery(/blockType=i18n/)
.type('javascript/auto')
.use('i18n')
.loader('@intlify/vue-i18n-loader')
.end()
.end()
}
})
}
const report = require('./report')
api.registerCommand('i18n:report', report.options, args =>
report.service(args, api)
)
}
module.exports.defaultModes = {
build: 'production'
}