Skip to content

Commit d0326fc

Browse files
author
Franck Freiburger
committed
chore(core): set vueVersion from bundler
1 parent 62029c2 commit d0326fc

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

build/webpack.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ const configure = ({name, vueTarget, libraryTargetModule}) => async (env = {}, {
9292

9393
let actualTargetsBrowsers = targetsBrowsers;
9494

95+
let vueVersion; // expected vue version
96+
switch ( vueTarget ) {
97+
case '2':
98+
vueVersion = require('vue-template-compiler/package.json').version;
99+
break;
100+
case '3':
101+
vueVersion = require('@vue/compiler-sfc/package.json').version;
102+
break;
103+
default:
104+
throw new Error(`invalid vueTarget: ${ vueTarget }`)
105+
}
106+
95107
// "or" / ","" -> union
96108
// "and" -> intersection
97109
// "not" -> relative complement
@@ -199,6 +211,7 @@ const configure = ({name, vueTarget, libraryTargetModule}) => async (env = {}, {
199211
// config
200212
'process.env.GEN_SOURCEMAP': JSON.stringify(genSourcemap),
201213
'process.env.VERSION': JSON.stringify(pkg.version),
214+
'process.env.VUE_VERSION': JSON.stringify(vueVersion),
202215

203216
'process.env.LANG': 'undefined',
204217

src/createSFCModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { ModuleExport, Options, AbstractPath } from './types'
22

33
export declare function createSFCModule (source: string, filename: AbstractPath, options: Options): Promise<ModuleExport>
4-
export declare const vueVersion : string
4+

src/createVue2SFCModule.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ import {
4141
StylePreprocessor,
4242
} from '../build/vue2StyleProcessors'
4343

44-
export { version as vueVersion } from 'vue-template-compiler/package.json'
4544

4645

4746
/**
48-
* the version of the library (process.env.VERSION is set by webpack, at compile-time)
47+
* the version of the library
4948
*/
50-
const version : string = process.env.VERSION as string;
49+
import { version } from './index'
5150

5251
// @ts-ignore
5352
const targetBrowserBabelPluginsHash : string = hash(...Object.keys({ ...(typeof ___targetBrowserBabelPlugins !== 'undefined' ? ___targetBrowserBabelPlugins : {}) }));

src/createVue3SFCModule.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,16 @@ import {
3535
AbstractPath
3636
} from './types'
3737

38-
// @ts-ignore (Cannot find module '@vue/compiler-sfc/../../package.json' or its corresponding type declarations.)
39-
//export { version as vueVersion } from '@vue/compiler-sfc/../../package.json'
40-
export { version as vueVersion } from '@vue/compiler-sfc/package.json'
4138

4239
/**
4340
* @ignore
4441
*/
4542
type PreprocessLang = SFCAsyncStyleCompileOptions['preprocessLang'];
4643

4744
/**
48-
* the version of the library (process.env.VERSION is set by webpack, at compile-time)
45+
* the version of the library
4946
*/
50-
const version : string = process.env.VERSION as string;
47+
import { version } from './index'
5148

5249
// @ts-ignore
5350
const targetBrowserBabelPluginsHash : string = hash(...Object.keys({ ...(typeof ___targetBrowserBabelPlugins !== 'undefined' ? ___targetBrowserBabelPlugins : {}) }));

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const version : string = process.env.VERSION as string;
2929
/**
3030
* the version of Vue that is expected by the library
3131
*/
32-
export { vueVersion } from './createSFCModule'
32+
export const vueVersion : string = process.env.VUE_VERSION as string;
3333

3434

3535
export { createCJSModule } from './tools'

0 commit comments

Comments
 (0)