Skip to content

Commit 09cb632

Browse files
authored
fix: export default warning (#168)
1 parent 676caa3 commit 09cb632

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/pluginWebpack4.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import webpack from 'webpack'
55
import { ReplaceSource } from 'webpack-sources'
66
import { isFunction, isObject, isRegExp, isString } from '@intlify/shared'
77
const Dependency = require('webpack/lib/Dependency') // eslint-disable-line @typescript-eslint/no-var-requires
8+
const NullFactory = require('webpack/lib/NullFactory') // eslint-disable-line @typescript-eslint/no-var-requires
89

910
const PLUGIN_ID = 'IntlifyVuePlugin'
1011

@@ -44,6 +45,17 @@ class VueComponentDependency extends Dependency {
4445
this.statement = statement
4546
}
4647

48+
get type() {
49+
return 'harmony export expression'
50+
}
51+
52+
getExports() {
53+
return {
54+
exports: ['default'],
55+
dependencies: undefined
56+
}
57+
}
58+
4759
updateHash(hash: any) {
4860
super.updateHash(hash)
4961
const scriptModule = this.script
@@ -52,7 +64,7 @@ class VueComponentDependency extends Dependency {
5264
(!scriptModule.buildMeta || scriptModule.buildMeta.exportsType)) + ''
5365
)
5466
hash.update((scriptModule && scriptModule.id) + '')
55-
const templateModule = this.templa
67+
const templateModule = this.template
5668
hash.update(
5769
(templateModule &&
5870
(!templateModule.buildMeta || templateModule.buildMeta.exportsType)) +
@@ -164,6 +176,7 @@ function toVueComponentDependency(parser: any, values: InjectionValues) {
164176
values,
165177
statement
166178
)
179+
// dep.loc = statement.loc
167180
parser.state.current.addDependency(dep)
168181
return true
169182
}
@@ -182,11 +195,11 @@ export default class IntlifyVuePlugin implements webpack.Plugin {
182195
compiler.hooks.compilation.tap(
183196
PLUGIN_ID,
184197
(compilation, { normalModuleFactory }) => {
185-
// compilation.dependencyFactories.set(
186-
// // @ts-ignore
187-
// VueComponentDependency,
188-
// new NullFactory()
189-
// )
198+
compilation.dependencyFactories.set(
199+
// @ts-ignore
200+
VueComponentDependency,
201+
new NullFactory()
202+
)
190203
compilation.dependencyTemplates.set(
191204
// @ts-ignore
192205
VueComponentDependency,
@@ -200,7 +213,10 @@ export default class IntlifyVuePlugin implements webpack.Plugin {
200213
parser.hooks.exportExpression.tap(
201214
PLUGIN_ID,
202215
(statement, declaration) => {
203-
if (declaration.name === 'script') {
216+
if (
217+
(parser as any).state.module.resource.endsWith('.vue') &&
218+
declaration.name === 'script'
219+
) {
204220
// console.log('exportExpression', statement, declaration)
205221
return toVueComponentDependency(parser, injections)(statement)
206222
}

0 commit comments

Comments
 (0)