20
loading...
This website collects cookies to deliver better user experience
$ npx -p @vue/cli vue create esbuild-vue-cli -d
-d
- skips prompts with generating options & use default options - vue version 2npx -p ...
- generates code without global installation$ npm run build
> [email protected] build
> vue-cli-service build
DONE Compiled successfully in 1622ms8:20:58 AM
File Size Gzipped
dist/js/chunk-vendors.5028b17c.js 90.35 KiB 32.40 KiB
dist/js/app.5b09fec2.js 4.58 KiB 1.63 KiB
dist/css/app.fb0c6e1c.css 0.33 KiB 0.23 KiB
Images and other types of assets omitted.
DONE Build complete. The dist directory is ready to be deployed.
INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
$ npm install --save-dev esbuild
added 1 package, and audited 1326 packages in 3s
82 packages are looking for funding
run `npm fund` for details
....
package.json
like this one:{
...
"scripts": {
...
"esbuild": "esbuild src/main.js --bundle --outfile=dist/main.js"
},
...
}
$ npm run esbuild
> [email protected] esbuild
> esbuild src/main.js --bundle --outfile=dist/main.js
> src/main.js:2:16: error: No loader is configured for ".vue" files: src/App.vue
2 │ import App from './App.vue'
╵ ~~~~~~~~~~~
1 error
$ npm install --save-dev esbuild-vue
added 91 packages, and audited 1417 packages in 6s
82 packages are looking for funding
run `npm fund` for details
...
const vuePlugin = require("esbuild-vue");
require("esbuild").build({
entryPoints: ["src/main.js"],
bundle: true,
outfile: "dist/main.js",
logLevel: "info",
plugins: [vuePlugin()],
define: {
"process.env.NODE_ENV": JSON.stringify("development"),
},
});
logLevel: "info",
to get logs about successful builds as wellpackage.json
esbuild script with:{
...
"scripts": {
...
"esbuild": "node build.js"
},
...
}
$ npm run esbuild
> [email protected] esbuild
> node build.js
dist/main.js 200.2kb
⚡ Done in 634ms
dist/index.html
:<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="icon" href="./favicon.ico" />
<title>esbuild-vue-cli</title>
</head>
<body>
<noscript
><strong
>We're sorry but esbuild-vue-cli doesn't work properly without
JavaScript enabled. Please enable it to continue.</strong
></noscript
>
<div id="app"></div>
<script src="./main.js"></script>
</body>
</html>
npm run build
, but tweaked to the files names we used in esbuild. The application works:src="<some-file>"
as file imports - we will need to do it ourself, but this is something to be covered in other article in this series.build.js
:...
require("esbuild").build({
...
minify: true,
...
});
$ npm run esbuild
> [email protected] esbuild
> node build.js
dist/main.js 89.9kb
⚡ Done in 600ms
20