es-preset-ccb
Advanced tools
Comparing version 0.13.0 to 0.14.0
58
index.js
@@ -5,2 +5,3 @@ import uglify from 'uglify-js'; | ||
import { build } from 'esbuild'; | ||
import inlineImportPlugin from 'esbuild-plugin-inline-import'; | ||
@@ -105,2 +106,3 @@ function getNamespaceRegex (namespace) { | ||
resolveImports = false, | ||
resolveInlineImports = false, | ||
minify, | ||
@@ -119,4 +121,22 @@ handleGlobals, | ||
const useUglify = minify || globalDefinitions; | ||
const uglifyConfig = { | ||
compress: { | ||
drop_console: true, | ||
global_defs: globalDefinitions, | ||
}, | ||
mangle: { | ||
toplevel: false, | ||
}, | ||
toplevel: false, | ||
warnings: 'verbose', | ||
}; | ||
if (!minify) { | ||
disableCompressOptions(uglifyConfig); | ||
} | ||
if (resolveImports) { | ||
const esbuildResult = await build({ | ||
const esbuildOptions = { | ||
bundle: true, | ||
@@ -126,3 +146,19 @@ entryPoints: [file], | ||
write: false, | ||
}); | ||
}; | ||
if (resolveInlineImports) { | ||
const inlineImportOptions = {}; | ||
if (useUglify) { | ||
inlineImportOptions.transform = function transform (contents, args) { | ||
const path = args.path; | ||
const isJsFile = path && path.endsWith('.js'); | ||
if (!isJsFile) return contents; | ||
return uglify.minify(outputText, uglifyConfig).code; | ||
}; | ||
} | ||
esbuildOptions.plugins = [ | ||
inlineImportPlugin(inlineImportOptions), | ||
]; | ||
} | ||
const esbuildResult = await build(esbuildOptions); | ||
outputText = esbuildResult.outputFiles[0].text; | ||
@@ -155,21 +191,5 @@ } | ||
if (!minify && !globalDefinitions) return outputText; | ||
if (!useUglify) return outputText; | ||
const uglifyConfig = { | ||
compress: { | ||
drop_console: true, | ||
global_defs: globalDefinitions, | ||
}, | ||
mangle: { | ||
toplevel: false, | ||
}, | ||
toplevel: false, | ||
warnings: 'verbose', | ||
}; | ||
if (!minify) { | ||
disableCompressOptions(uglifyConfig); | ||
} | ||
return uglify.minify(outputText, uglifyConfig).code; | ||
} |
{ | ||
"name": "es-preset-ccb", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "Processes JS code", | ||
@@ -23,19 +23,13 @@ "homepage": "https://github.com/carlosjeurissen/es-preset-ccb#readme", | ||
"dependencies": { | ||
"@babel/core": "^7.24.0", | ||
"@babel/preset-env": "^7.24.0", | ||
"@babel/core": "^7.24.4", | ||
"@babel/preset-env": "^7.24.4", | ||
"esbuild": "^0.20.2", | ||
"esbuild-plugin-inline-import": "^1.0.4", | ||
"uglify-js": "^3.17.4" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.57.0", | ||
"eslint-config-ccb": "^0.18.0", | ||
"vitest": "^1.3.1" | ||
"eslint": "^9.1.1", | ||
"eslint-config-ccb": "^0.25.1", | ||
"vitest": "^1.5.1" | ||
}, | ||
"eslintConfig": { | ||
"extends": "ccb", | ||
"env": { | ||
"es2022": true, | ||
"node": true | ||
} | ||
}, | ||
"engines": { | ||
@@ -42,0 +36,0 @@ "node": ">=14.0.0" |
Sorry, the diff of this file is not supported yet
189140
7
330
5
+ Addedesbuild-plugin-inline-import@1.0.4(transitive)
Updated@babel/core@^7.24.4
Updated@babel/preset-env@^7.24.4