Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ditojs/build

Package Overview
Dependencies
Maintainers
4
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ditojs/build - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

5

package.json
{
"name": "@ditojs/build",
"version": "1.4.1",
"version": "1.5.0",
"type": "module",

@@ -27,2 +27,3 @@ "repository": "https://github.com/ditojs/dito/tree/master/packages/build",

"autoprefixer": "^10.4.4",
"find-up": "^6.3.0",
"mime": "^3.0.0",

@@ -34,3 +35,3 @@ "mini-svg-data-uri": "^1.4.4",

},
"gitHead": "0e8a22ea0cb68eec3df1b6236cf77a85f5a2c836"
"gitHead": "36a57512228cc233211bf6e4038123a9e775f5c5"
}

48

src/rollup.js

@@ -0,2 +1,7 @@

import fs from 'fs'
import path from 'path'
import { builtinModules, createRequire } from 'module'
import { findUpSync } from 'find-up'
import { asArray, escapeRegexp } from '@ditojs/utils'
const require = createRequire(import.meta.url)

@@ -8,3 +13,3 @@

exclude = []
}) {
} = {}) {
const externals = Object.fromEntries(

@@ -39,1 +44,42 @@ [...builtinModules, ...include].map(name => [name, name])

}
export function createRollupImportsResolver({ cwd = process.cwd() } = {}) {
// Read `package.json` from the closest package.json, so we can emulate
// ESM-style imports mappings in rollup / vite.
const pkg = findUpSync('package.json', { cwd })
const { imports = {} } = JSON.parse(fs.readFileSync(pkg, 'utf8'))
return {
// Use a custom rollup resolver to emulate ESM-style imports
// mappings in vite, as read from `package.json` above:
find: /^#/,
replacement: '#',
customResolver(id) {
for (const [find, replacement] of Object.entries(imports)) {
const { match, capture } = matchModuleIdentifier(id, find)
if (match) {
const replacementPath = path.resolve(replacement)
id = capture
? replacementPath.replace('*', capture)
: replacementPath
}
}
return id
}
}
}
export function matchModuleIdentifier(id, pattern) {
const regexp = new RegExp(`^${escapeRegexp(pattern).replace('\\*', '(.*)')}$`)
const match = id.match(regexp)
return {
match: !!match,
capture: match?.[1]
}
}
export function testModuleIdentifier(id, patterns) {
return asArray(patterns).some(
pattern => matchModuleIdentifier(id, pattern).match
)
}

@@ -1,9 +0,15 @@

import { defineConfig } from 'vite'
import { defineConfig as defineViteConfig } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2'
import { getPostCssConfig } from './postcss.js'
import { getRollupExternalsFromDependencies } from './rollup.js'
import {
getRollupExternalsFromDependencies,
createRollupImportsResolver
} from './rollup.js'
export function getViteConfig({
name,
defineConfig = defineViteConfig,
css = false,
vue = false,
build = true,
minify = !process.argv.includes('--watch'),

@@ -14,28 +20,43 @@ sourcemap = 'inline',

exclude = []
} = {}
} = {},
...rest
} = {}) {
const externals = getRollupExternalsFromDependencies({ include, exclude })
const externals = build && getRollupExternalsFromDependencies({
include,
exclude
})
return defineConfig({
plugins: [
createVuePlugin()
],
esbuild: { minify },
build: {
minify,
sourcemap,
cssCodeSplit: false,
lib: {
name,
format: ['es', 'umd'],
entry: './src/index.js',
fileName: format => `${name}.${format}.js`
},
rollupOptions: {
external: id => !!externals[id],
output: {
manualChunks: undefined,
globals: externals
plugins: vue
? [
createVuePlugin()
]
: null,
resolve: {
alias: [
createRollupImportsResolver()
]
},
esbuild: build
? { minify }
: null,
build: build
? {
minify,
sourcemap,
cssCodeSplit: false,
lib: {
name,
format: ['es', 'umd'],
entry: './src/index.js',
fileName: format => `${name}.${format}.js`
},
rollupOptions: {
external: id => !!externals[id],
output: {
manualChunks: undefined,
globals: externals
}
}
}
},
: null,
css: css

@@ -50,4 +71,5 @@ ? {

}
: null
: null,
...rest
})
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc