Skip to content

Commit bdeac75

Browse files
committed
Refactor: Don't include package.json into dist files
Instead of including package.json file into the build files. Use webpacks DefinePlugin to define a global lib version.
1 parent ebcab9f commit bdeac75

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ module.exports = {
1515
'arrow-parens': 0,
1616
// allow debugger during development
1717
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
18+
},
19+
"globals": {
20+
"LIB_VERSION": true
1821
}
1922
}

build/webpack.base.conf.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict'
2+
const webpack = require('webpack')
23
const path = require('path')
34
const utils = require('./utils')
45
const config = require('../config')
56
const vueLoaderConfig = require('./vue-loader.conf')
7+
const npmCfg = require('../package.json')
68

79
function resolve (dir) {
810
return path.join(__dirname, '..', dir)
@@ -72,5 +74,10 @@ module.exports = {
7274
}
7375
}
7476
]
75-
}
77+
},
78+
plugins: [
79+
new webpack.DefinePlugin({
80+
LIB_VERSION: JSON.stringify(npmCfg.version)
81+
})
82+
]
7683
}

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mixins from './mixins/index.js'
2-
import npmCfg from '../package.json'
2+
33
import {
44
Bar,
55
HorizontalBar,
@@ -13,7 +13,7 @@ import {
1313
} from './BaseCharts'
1414

1515
const VueCharts = {
16-
version: npmCfg.version,
16+
version: LIB_VERSION,
1717
Bar,
1818
HorizontalBar,
1919
Doughnut,

0 commit comments

Comments
 (0)