Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the npm package size #6105

Merged
merged 4 commits into from Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 0 additions & 13 deletions .npmignore

This file was deleted.

4 changes: 2 additions & 2 deletions karma.conf.js
Expand Up @@ -49,12 +49,12 @@ module.exports = function(karma) {
{pattern: 'test/fixtures/**/*.png', included: false},
'node_modules/moment/min/moment.min.js',
'test/index.js',
'src/chart.js'
'src/index.js'
].concat(args.inputs),

preprocessors: {
'test/index.js': ['rollup'],
'src/chart.js': ['sources']
'src/index.js': ['sources']
},

rollupPreprocessor: {
Expand Down
7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -22,6 +22,13 @@
"bugs": {
"url": "https://github.com/chartjs/Chart.js/issues"
},
"files": [
"bower.json",
"composer.json",
"dist/*.css",
"dist/*.js",
"src/chart.js"
],
"devDependencies": {
"clean-css": "^4.2.1",
"coveralls": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Expand Up @@ -7,7 +7,7 @@ const optional = require('./rollup.plugins').optional;
const stylesheet = require('./rollup.plugins').stylesheet;
const pkg = require('./package.json');

const input = 'src/chart.js';
const input = 'src/index.js';
const banner = `/*!
* Chart.js v${pkg.version}
* ${pkg.homepage}
Expand Down
143 changes: 4 additions & 139 deletions src/chart.js
@@ -1,141 +1,6 @@
/**
* @namespace Chart
* DEPRECATED since version 2.8, this file is provided for
* backward compatibility and will be removed at version 3.
* https://github.com/chartjs/Chart.js/pull/6105
*/
var Chart = require('./core/core.controller');

Chart.helpers = require('./helpers/index');

// @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
require('./core/core.helpers')(Chart);

Chart._adapters = require('./core/core.adapters');
Chart.Animation = require('./core/core.animation');
Chart.animationService = require('./core/core.animations');
Chart.controllers = require('./controllers/index');
Chart.DatasetController = require('./core/core.datasetController');
Chart.defaults = require('./core/core.defaults');
Chart.Element = require('./core/core.element');
Chart.elements = require('./elements/index');
Chart.Interaction = require('./core/core.interaction');
Chart.layouts = require('./core/core.layouts');
Chart.platform = require('./platforms/platform');
Chart.plugins = require('./core/core.plugins');
Chart.Scale = require('./core/core.scale');
Chart.scaleService = require('./core/core.scaleService');
Chart.Ticks = require('./core/core.ticks');
Chart.Tooltip = require('./core/core.tooltip');

// Register built-in scales
var scales = require('./scales');
Chart.helpers.each(scales, function(scale, type) {
Chart.scaleService.registerScaleType(type, scale, scale._defaults);
});

// Load to register built-in adapters (as side effects)
require('./adapters');

// Loading built-in plugins
var plugins = require('./plugins');
for (var k in plugins) {
if (plugins.hasOwnProperty(k)) {
Chart.plugins.register(plugins[k]);
}
}

Chart.platform.initialize();

module.exports = Chart;
if (typeof window !== 'undefined') {
window.Chart = Chart;
}

// DEPRECATIONS

/**
* Provided for backward compatibility, not available anymore
* @namespace Chart.Legend
* @deprecated since version 2.1.5
* @todo remove at version 3
* @private
*/
Chart.Legend = plugins.legend._element;

/**
* Provided for backward compatibility, not available anymore
* @namespace Chart.Title
* @deprecated since version 2.1.5
* @todo remove at version 3
* @private
*/
Chart.Title = plugins.title._element;

/**
* Provided for backward compatibility, use Chart.plugins instead
* @namespace Chart.pluginService
* @deprecated since version 2.1.5
* @todo remove at version 3
* @private
*/
Chart.pluginService = Chart.plugins;

/**
* Provided for backward compatibility, inheriting from Chart.PlugingBase has no
* effect, instead simply create/register plugins via plain JavaScript objects.
* @interface Chart.PluginBase
* @deprecated since version 2.5.0
* @todo remove at version 3
* @private
*/
Chart.PluginBase = Chart.Element.extend({});

/**
* Provided for backward compatibility, use Chart.helpers.canvas instead.
* @namespace Chart.canvasHelpers
* @deprecated since version 2.6.0
* @todo remove at version 3
* @private
*/
Chart.canvasHelpers = Chart.helpers.canvas;

/**
* Provided for backward compatibility, use Chart.layouts instead.
* @namespace Chart.layoutService
* @deprecated since version 2.7.3
* @todo remove at version 3
* @private
*/
Chart.layoutService = Chart.layouts;

/**
* Provided for backward compatibility, not available anymore.
* @namespace Chart.LinearScaleBase
* @deprecated since version 2.8
* @todo remove at version 3
* @private
*/
Chart.LinearScaleBase = require('./scales/scale.linearbase');

/**
* Provided for backward compatibility, instead we should create a new Chart
* by setting the type in the config (`new Chart(id, {type: '{chart-type}'}`).
* @deprecated since version 2.8.0
* @todo remove at version 3
*/
Chart.helpers.each(
[
'Bar',
'Bubble',
'Doughnut',
'Line',
'PolarArea',
'Radar',
'Scatter'
],
function(klass) {
Chart[klass] = function(ctx, cfg) {
return new Chart(ctx, Chart.helpers.merge(cfg || {}, {
type: klass.charAt(0).toLowerCase() + klass.slice(1)
}));
};
}
);
module.exports = require('../dist/Chart');
141 changes: 141 additions & 0 deletions src/index.js
@@ -0,0 +1,141 @@
/**
* @namespace Chart
*/
var Chart = require('./core/core.controller');

Chart.helpers = require('./helpers/index');

// @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
require('./core/core.helpers')(Chart);

Chart._adapters = require('./core/core.adapters');
Chart.Animation = require('./core/core.animation');
Chart.animationService = require('./core/core.animations');
Chart.controllers = require('./controllers/index');
Chart.DatasetController = require('./core/core.datasetController');
Chart.defaults = require('./core/core.defaults');
Chart.Element = require('./core/core.element');
Chart.elements = require('./elements/index');
Chart.Interaction = require('./core/core.interaction');
Chart.layouts = require('./core/core.layouts');
Chart.platform = require('./platforms/platform');
Chart.plugins = require('./core/core.plugins');
Chart.Scale = require('./core/core.scale');
Chart.scaleService = require('./core/core.scaleService');
Chart.Ticks = require('./core/core.ticks');
Chart.Tooltip = require('./core/core.tooltip');

// Register built-in scales
var scales = require('./scales');
Chart.helpers.each(scales, function(scale, type) {
Chart.scaleService.registerScaleType(type, scale, scale._defaults);
});

// Load to register built-in adapters (as side effects)
require('./adapters');

// Loading built-in plugins
var plugins = require('./plugins');
for (var k in plugins) {
if (plugins.hasOwnProperty(k)) {
Chart.plugins.register(plugins[k]);
}
}

Chart.platform.initialize();

module.exports = Chart;
if (typeof window !== 'undefined') {
window.Chart = Chart;
}

// DEPRECATIONS

/**
* Provided for backward compatibility, not available anymore
* @namespace Chart.Legend
* @deprecated since version 2.1.5
* @todo remove at version 3
* @private
*/
Chart.Legend = plugins.legend._element;

/**
* Provided for backward compatibility, not available anymore
* @namespace Chart.Title
* @deprecated since version 2.1.5
* @todo remove at version 3
* @private
*/
Chart.Title = plugins.title._element;

/**
* Provided for backward compatibility, use Chart.plugins instead
* @namespace Chart.pluginService
* @deprecated since version 2.1.5
* @todo remove at version 3
* @private
*/
Chart.pluginService = Chart.plugins;

/**
* Provided for backward compatibility, inheriting from Chart.PlugingBase has no
* effect, instead simply create/register plugins via plain JavaScript objects.
* @interface Chart.PluginBase
* @deprecated since version 2.5.0
* @todo remove at version 3
* @private
*/
Chart.PluginBase = Chart.Element.extend({});

/**
* Provided for backward compatibility, use Chart.helpers.canvas instead.
* @namespace Chart.canvasHelpers
* @deprecated since version 2.6.0
* @todo remove at version 3
* @private
*/
Chart.canvasHelpers = Chart.helpers.canvas;

/**
* Provided for backward compatibility, use Chart.layouts instead.
* @namespace Chart.layoutService
* @deprecated since version 2.7.3
* @todo remove at version 3
* @private
*/
Chart.layoutService = Chart.layouts;

/**
* Provided for backward compatibility, not available anymore.
* @namespace Chart.LinearScaleBase
* @deprecated since version 2.8
* @todo remove at version 3
* @private
*/
Chart.LinearScaleBase = require('./scales/scale.linearbase');

/**
* Provided for backward compatibility, instead we should create a new Chart
* by setting the type in the config (`new Chart(id, {type: '{chart-type}'}`).
* @deprecated since version 2.8.0
* @todo remove at version 3
*/
Chart.helpers.each(
[
'Bar',
'Bubble',
'Doughnut',
'Line',
'PolarArea',
'Radar',
'Scatter'
],
function(klass) {
Chart[klass] = function(ctx, cfg) {
return new Chart(ctx, Chart.helpers.merge(cfg || {}, {
type: klass.charAt(0).toLowerCase() + klass.slice(1)
}));
};
}
);
2 changes: 1 addition & 1 deletion src/scales/scale.category.js
Expand Up @@ -130,5 +130,5 @@ module.exports = Scale.extend({
}
});

// INTERNAL: static default options, registered in src/chart.js
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;
2 changes: 1 addition & 1 deletion src/scales/scale.linear.js
Expand Up @@ -186,5 +186,5 @@ module.exports = LinearScaleBase.extend({
}
});

// INTERNAL: static default options, registered in src/chart.js
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;
2 changes: 1 addition & 1 deletion src/scales/scale.logarithmic.js
Expand Up @@ -345,5 +345,5 @@ module.exports = Scale.extend({
}
});

// INTERNAL: static default options, registered in src/chart.js
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;
2 changes: 1 addition & 1 deletion src/scales/scale.radialLinear.js
Expand Up @@ -530,5 +530,5 @@ module.exports = LinearScaleBase.extend({
}
});

// INTERNAL: static default options, registered in src/chart.js
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;
2 changes: 1 addition & 1 deletion src/scales/scale.time.js
Expand Up @@ -764,5 +764,5 @@ module.exports = Scale.extend({
}
});

// INTERNAL: static default options, registered in src/chart.js
// INTERNAL: static default options, registered in src/index.js
module.exports._defaults = defaultConfig;