Introduction to Estrella
Estrella is a powerful build tool for JavaScript and TypeScript projects. It simplifies and speeds up the development process with an intuitive API and efficient performance. Below, we introduce some of the most useful APIs provided by Estrella, complete with code snippets to help you get started quickly.
Basic Setup
To begin using Estrella, install it using npm:
npm install estrella --save-dev
Create a build script by adding the following to your package.json:
{
"scripts": {
"build": "estrella build.js"
}
}
Building a Project
Create a build.js
file with the following content to start building your project:
const { build } = require("estrella")
build({
entry: "src/index.ts",
outfile: "dist/bundle.js",
minify: true,
bundle: true
})
Live Reloading
Use the watch
option to enable live reloading:
build({
entry: "src/index.ts",
outfile: "dist/bundle.js",
watch: true
})
Adding Plugins
Estrella supports a range of plugins to extend its functionality. For instance, you can use plugins for CSS or other preprocessors:
const cssPlugin = require("esbuild-css-modules-plugin")
build({
entry: "src/index.ts",
outfile: "dist/bundle.js",
plugins: [cssPlugin()]
})
Code Splitting
Optimize your output with code splitting by setting the splitting
option to true
:
build({
entry: "src/index.ts",
outdir: "dist",
splitting: true,
format: "esm",
bundle: true
})
Using Environment Variables
Access environment variables in your build process:
build({
entry: "src/index.ts",
outfile: "dist/bundle.js",
define: {
"process.env.NODE_ENV": '"production"'
}
})
App Example Using Estrella
Here is a complete example of a simple app using Estrella:
// build.js const { build } = require("estrella")
build({
entry: "src/app.ts",
outfile: "dist/app.bundle.js",
bundle: true,
minify: true,
watch: true
})
// src/app.ts console.log("Hello, world!")
// package.json {
"name": "estrella-app",
"scripts": {
"build": "estrella build.js",
"start": "node dist/app.bundle.js"
},
"devDependencies": {
"estrella": "^1.0.0"
},
"dependencies": {}
}
This setup includes a basic TypeScript entry file, a build configuration file, and necessary scripts in package.json
.
Hash: d9078313c20e82941879e10262ab7a761f29a61e835f9a76a742f3f914cea941