123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- const nodeResolvePlugin = require('@rollup/plugin-node-resolve').default;
- const nodePath = require('path');
- const ecDir = nodePath.resolve(__dirname, '..');
- const {terser} = require('rollup-plugin-terser');
- const replace = require('@rollup/plugin-replace');
- const MagicString = require('magic-string');
- const preamble = require('./preamble');
- function createAddLicensePlugin(sourcemap) {
- return {
- renderChunk(code, chunk) {
- const s = new MagicString(code);
- s.prepend(preamble.js);
- return {
- code: s.toString(),
- map: sourcemap ? s.generateMap({ hires: true }).toString() : null
- };
- }
- }
- }
- function createOutputs(basename, { min }, commonOutputOpts) {
- commonOutputOpts = {
- format: 'umd',
- ...commonOutputOpts
- }
- function createReplacePlugin(replacement) {
- const plugin = replace({
- 'process.env.NODE_ENV': JSON.stringify(replacement)
- });
-
- delete plugin.transform;
- return plugin;
- }
- const output = [{
- ...commonOutputOpts,
-
- sourcemap: true,
- plugins: [
- createReplacePlugin('development'),
- createAddLicensePlugin(true)
- ],
- file: basename + '.js'
- }];
- if (min) {
- output.push({
- ...commonOutputOpts,
-
- sourcemap: false,
-
- plugins: [
- createReplacePlugin('production'),
- terser(),
- createAddLicensePlugin(false)
- ],
- file: basename + '.min.js'
- })
- }
- return output;
- }
- exports.createECharts = function (opt = {}) {
- const srcType = opt.type !== 'all' ? '.' + opt.type : '';
- const postfixType = srcType;
- const format = opt.format || 'umd';
- const postfixFormat = (format !== 'umd') ? '.' + format.toLowerCase() : '';
- const input = nodePath.resolve(ecDir, `index${srcType}.js`);
- return {
- plugins: [nodeResolvePlugin()],
- treeshake: {
- moduleSideEffects: false
- },
- input: input,
- output: createOutputs(
- nodePath.resolve(ecDir, `dist/echarts${postfixFormat}${postfixType}`),
- opt,
- {
- name: 'echarts',
-
-
- exports: 'named',
- format: format
- }
- )
- };
- };
- exports.createBMap = function (opt) {
- const input = nodePath.resolve(ecDir, `extension/bmap/bmap.js`);
- return {
- plugins: [nodeResolvePlugin()],
- input: input,
- external: ['echarts'],
- output: createOutputs(
- nodePath.resolve(ecDir, `dist/extension/bmap`),
- opt,
- {
- name: 'bmap',
- globals: {
-
- echarts: 'echarts'
- }
- }
- )
- };
- };
- exports.createDataTool = function (opt) {
- let input = nodePath.resolve(ecDir, `extension/dataTool/index.js`);
- return {
- plugins: [nodeResolvePlugin()],
- input: input,
- external: ['echarts'],
- output: createOutputs(
- nodePath.resolve(ecDir, `dist/extension/dataTool`),
- opt,
- {
- name: 'dataTool',
- globals: {
-
- echarts: 'echarts'
- }
- }
- )
- };
- };
- exports.createMyTransform = function (opt) {
- let input = nodePath.resolve(ecDir, `test/lib/myTransform/src/index.ts`);
- return {
- plugins: [nodeResolvePlugin()],
- input: input,
- output: createOutputs(
- nodePath.resolve(ecDir, `test/lib/myTransform/dist/myTransform`),
- opt,
- {
- name: 'myTransform'
- }
- )
- };
- };
|