add cjs build versions

This commit is contained in:
Mark Silverwood 2023-01-27 13:55:01 +00:00
parent 1d2f35775c
commit e7b4390af6
4 changed files with 31 additions and 21 deletions

View File

@ -1,9 +1,14 @@
// eslint-env node
module.exports = [
{
name: 'CJS',
path: 'dist/lightweight-charts.production.cjs',
limit: '44.1 KB',
},
{
name: 'ESM',
path: 'dist/lightweight-charts.esm.production.js',
path: 'dist/lightweight-charts.production.mjs',
limit: '44.0 KB',
},
{

View File

@ -1,7 +1,7 @@
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/lightweight-charts.esm.production.js');
module.exports = require('./dist/lightweight-charts.production.cjs');
} else {
module.exports = require('./dist/lightweight-charts.esm.development.js');
module.exports = require('./dist/lightweight-charts.development.cjs');
}

View File

@ -12,7 +12,7 @@
"type": "git",
"url": "https://github.com/tradingview/lightweight-charts.git"
},
"module": "dist/lightweight-charts.esm.production.js",
"module": "dist/lightweight-charts.production.mjs",
"main": "index.cjs",
"typings": "dist/typings.d.ts",
"exports": {
@ -20,17 +20,17 @@
".": {
"development": {
"types": "./dist/typings.d.ts",
"import": "./dist/lightweight-charts.esm.development.js",
"require": "./dist/lightweight-charts.esm.development.js"
"import": "./dist/lightweight-charts.development.mjs",
"require": "./dist/lightweight-charts.development.cjs"
},
"production": {
"types": "./dist/typings.d.ts",
"import": "./dist/lightweight-charts.esm.production.js",
"require": "./dist/lightweight-charts.esm.production.js"
"import": "./dist/lightweight-charts.production.mjs",
"require": "./dist/lightweight-charts.production.cjs"
},
"default": {
"types": "./dist/typings.d.ts",
"import": "./dist/lightweight-charts.esm.production.js",
"import": "./dist/lightweight-charts.production.mjs",
"require": "./index.cjs"
}
}

View File

@ -15,16 +15,19 @@ function getCurrentVersion() {
const currentVersion = getCurrentVersion();
function getConfig(inputFile, type, isProd) {
const isModular = type === 'module';
const suffix = isModular ? 'esm' : 'standalone';
function getConfig(inputFile, format, isProd) {
const isStandalone = format === 'iife';
const mode = isProd ? 'production' : 'development';
const extension = {
cjs: 'cjs',
esm: 'mjs',
iife: 'js',
}[format];
const config = {
input: inputFile,
output: {
format: isModular ? 'esm' : 'iife',
file: `./dist/lightweight-charts.${suffix}.${mode}.js`,
format,
file: `./dist/lightweight-charts${isStandalone ? '.standalone' : ''}.${mode}.${extension}`,
banner: `
/*!
* @license
@ -50,28 +53,30 @@ function getConfig(inputFile, type, isProd) {
inline_script: true,
},
mangle: {
module: (type === 'module'),
module: (format === 'esm' || format === 'cjs'),
properties: {
regex: /^_(private|internal)_/,
},
},
}),
],
external: id => isModular && /^fancy-canvas(\/.+)?$/.test(id),
external: id => !isStandalone && /^fancy-canvas(\/.+)?$/.test(id),
};
return config;
}
const configs = [
getConfig('./lib/prod/src/index.js', 'module', false),
getConfig('./lib/prod/src/standalone.js', 'standalone', false),
getConfig('./lib/prod/src/index.js', 'esm', false),
getConfig('./lib/prod/src/index.js', 'cjs', false),
getConfig('./lib/prod/src/standalone.js', 'iife', false),
];
if (process.env.NODE_ENV === 'production') {
configs.push(
getConfig('./lib/prod/src/index.js', 'module', true),
getConfig('./lib/prod/src/standalone.js', 'standalone', true)
getConfig('./lib/prod/src/index.js', 'esm', true),
getConfig('./lib/prod/src/index.js', 'cjs', true),
getConfig('./lib/prod/src/standalone.js', 'iife', true)
);
}