From bdeac754224d0c77eb75d4e2794a10e11dd3edb2 Mon Sep 17 00:00:00 2001 From: Nick Nissen Date: Mon, 5 Feb 2018 13:40:04 +0100 Subject: [PATCH] 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. --- .eslintrc.js | 3 +++ build/webpack.base.conf.js | 9 ++++++++- src/index.js | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index af096009..dcb2c453 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,5 +15,8 @@ module.exports = { 'arrow-parens': 0, // allow debugger during development 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 + }, + "globals": { + "LIB_VERSION": true } } diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js index 15f60334..1b383605 100644 --- a/build/webpack.base.conf.js +++ b/build/webpack.base.conf.js @@ -1,8 +1,10 @@ 'use strict' +const webpack = require('webpack') const path = require('path') const utils = require('./utils') const config = require('../config') const vueLoaderConfig = require('./vue-loader.conf') +const npmCfg = require('../package.json') function resolve (dir) { return path.join(__dirname, '..', dir) @@ -72,5 +74,10 @@ module.exports = { } } ] - } + }, + plugins: [ + new webpack.DefinePlugin({ + LIB_VERSION: JSON.stringify(npmCfg.version) + }) + ] } diff --git a/src/index.js b/src/index.js index 65376ca1..f03fa1e0 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ import mixins from './mixins/index.js' -import npmCfg from '../package.json' + import { Bar, HorizontalBar, @@ -13,7 +13,7 @@ import { } from './BaseCharts' const VueCharts = { - version: npmCfg.version, + version: LIB_VERSION, Bar, HorizontalBar, Doughnut,