Socket
Socket
Sign inDemoInstall

esbuild-loader

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-loader - npm Package Compare versions

Comparing version 1.3.1 to 2.0.0

src/loader.js

10

package.json
{
"name": "esbuild-loader",
"version": "1.3.1",
"version": "2.0.0",
"main": "src/index.js",

@@ -8,3 +8,4 @@ "author": "EGOIST",

"scripts": {
"test": "jest --env node"
"test": "jest --env node",
"lint": "prettier --write src test/*.js"
},

@@ -17,4 +18,6 @@ "files": [

"jest": "^26.0.1",
"memfs": "^3.2.0",
"prettier": "^2.0.5",
"typescript": "^3.8.3",
"unionfs": "^4.4.0",
"webpack": "^4.43.0"

@@ -24,4 +27,5 @@ },

"esbuild": "^0.5.16",
"loader-utils": "^2.0.0"
"loader-utils": "^2.0.0",
"webpack-sources": "^1.4.3"
}
}

@@ -5,2 +5,4 @@ # esbuild-loader

You might also like [maho](https://github.com/egoist/maho), a React framework powered by esbuild.
## Install

@@ -14,2 +16,3 @@

### Transpiling
In `webpack.config.js`:

@@ -27,17 +30,63 @@

options: {
// All options are optional
target: 'es2015', // default, or 'es20XX', 'esnext'
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
sourceMap: false // Enable sourcemap
},
},
{
test: /\.tsx$/,
loader: 'esbuild-loader',
options: {
loader: 'tsx',
target: 'es2015',
},
},
],
},
plugins: [new ESBuildPlugin()],
plugins: [
new ESBuildPlugin()
]
}
```
### Minifying
In `webpack.config.js`:
```js
const { ESBuildPlugin, ESBuildMinifyPlugin } = require('esbuild-loader')
module.exports = {
optimization: {
minimize: true,
minimizer: [
new ESBuildMinifyPlugin()
],
},
plugins: [
new ESBuildPlugin()
],
}
```
## Options
### Loader
The loader supports options from [esbuild](https://github.com/evanw/esbuild#command-line-usage).
- `target` `<String>` (`es2015`) - Environment target (e.g. es2017, chrome80, esnext)
- `loader` `<String>` (`js`) - Which loader to use to handle file. Possible values: `js, jsx, ts, tsx, json, text, base64, file, dataurl, binary`
- `jsxFactory` `<String>` - What to use instead of React.createElement
- `jsxFragment` `<String>` - What to use instead of React.Fragment
- Enable source-maps via [`devtool`](https://webpack.js.org/configuration/devtool/)
### MinifyPlugin
- `minify` `<Boolean>` (`true`) - Sets all `--minify-*` flags
- `minifyWhitespace` `<Boolean>` - Remove whitespace
- `minifyIdentifiers` `<Boolean>` - Shorten identifiers
- `minifySyntax` `<Boolean>` - Use equivalent but shorter syntax
- `sourcemap` `<Boolean>` (defaults to Webpack `devtool`)- Whether to emit sourcemaps
## License
MIT &copy; [EGOIST (Kevin Titor)](https://github.com/sponsors/egoist)

@@ -1,70 +0,3 @@

const path = require('path')
const esbuild = require('esbuild')
const { getOptions } = require('loader-utils')
const getLoader = (ext) => {
if (ext === '.json') {
return 'json'
}
return 'tsx'
}
module.exports = async function (source) {
const done = this.async()
const options = getOptions(this)
/** @type {import('esbuild').Service} */
const service = this._compiler.$esbuildService
if (!service) {
return done(
new Error(
`[esbuild-loader] You need to add ESBuildPlugin to your webpack config first`
)
)
}
try {
const ext = path.extname(this.resourcePath)
const result = await service.transform(source, {
target: options.target || 'es2015',
loader: getLoader(ext),
jsxFactory: options.jsxFactory,
jsxFragment: options.jsxFragment,
sourcemap: options.sourceMap,
})
done(null, result.js, result.jsSourceMap)
} catch (err) {
done(err)
}
}
module.exports.ESBuildPlugin = class ESBuildPlugin {
/**
* @param {import('webpack').Compiler} compiler
*/
apply(compiler) {
let watching = false
const startService = async () => {
if (!compiler.$esbuildService) {
compiler.$esbuildService = await esbuild.startService()
}
}
compiler.hooks.run.tapPromise('esbuild', async () => {
await startService()
})
compiler.hooks.watchRun.tapPromise('esbuild', async () => {
watching = true
await startService()
})
compiler.hooks.done.tap('esbuild', () => {
if (!watching && compiler.$esbuildService) {
compiler.$esbuildService.stop()
compiler.$esbuildService = undefined
}
})
}
}
module.exports = require('./loader')
module.exports.ESBuildPlugin = require('./plugin')
module.exports.ESBuildMinifyPlugin = require('./minify-plugin')
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