@@ -5,6 +5,7 @@ import webpack from 'webpack'
5
5
import { ReplaceSource } from 'webpack-sources'
6
6
import { isFunction , isObject , isRegExp , isString } from '@intlify/shared'
7
7
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
8
9
9
10
const PLUGIN_ID = 'IntlifyVuePlugin'
10
11
@@ -44,6 +45,17 @@ class VueComponentDependency extends Dependency {
44
45
this . statement = statement
45
46
}
46
47
48
+ get type ( ) {
49
+ return 'harmony export expression'
50
+ }
51
+
52
+ getExports ( ) {
53
+ return {
54
+ exports : [ 'default' ] ,
55
+ dependencies : undefined
56
+ }
57
+ }
58
+
47
59
updateHash ( hash : any ) {
48
60
super . updateHash ( hash )
49
61
const scriptModule = this . script
@@ -52,7 +64,7 @@ class VueComponentDependency extends Dependency {
52
64
( ! scriptModule . buildMeta || scriptModule . buildMeta . exportsType ) ) + ''
53
65
)
54
66
hash . update ( ( scriptModule && scriptModule . id ) + '' )
55
- const templateModule = this . templa
67
+ const templateModule = this . template
56
68
hash . update (
57
69
( templateModule &&
58
70
( ! templateModule . buildMeta || templateModule . buildMeta . exportsType ) ) +
@@ -164,6 +176,7 @@ function toVueComponentDependency(parser: any, values: InjectionValues) {
164
176
values ,
165
177
statement
166
178
)
179
+ // dep.loc = statement.loc
167
180
parser . state . current . addDependency ( dep )
168
181
return true
169
182
}
@@ -182,11 +195,11 @@ export default class IntlifyVuePlugin implements webpack.Plugin {
182
195
compiler . hooks . compilation . tap (
183
196
PLUGIN_ID ,
184
197
( 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
+ )
190
203
compilation . dependencyTemplates . set (
191
204
// @ts -ignore
192
205
VueComponentDependency ,
@@ -200,7 +213,10 @@ export default class IntlifyVuePlugin implements webpack.Plugin {
200
213
parser . hooks . exportExpression . tap (
201
214
PLUGIN_ID ,
202
215
( statement , declaration ) => {
203
- if ( declaration . name === 'script' ) {
216
+ if (
217
+ ( parser as any ) . state . module . resource . endsWith ( '.vue' ) &&
218
+ declaration . name === 'script'
219
+ ) {
204
220
// console.log('exportExpression', statement, declaration)
205
221
return toVueComponentDependency ( parser , injections ) ( statement )
206
222
}
0 commit comments