


How to achieve extremely fast zero-configuration packaging in Parcel.js + Vue 2.x
This article mainly introduces the relevant information of Parcel.js Vue 2.x extremely fast zero-configuration packaging experience. Friends who need it can refer to it
Following Browserify and Webpack, Parcel is another packaging tool. Kong Chu Shi
The official website of Parcel.js has this self-introduction as "Extremely fast zero-configuration web application packaging tool"
After a brief contact, in terms of efficiency, it is indeed better than webpack There are quite a few, but there are also many pitfalls. It should gradually become more popular after future upgrades
Official documentation: https://parceljs.org/getting_started.html
Official GitHub: https://github .com/parcel-bundler/parcel
1. Basic usage
Parcel can be installed using npm or yarn. I am used to using npm. This is This blog will explain based on npm
First you need to install Parcel.js globally //The current version is 1.3.0
npm install -g parcel-bundler
Then write a configuration file... No, this is not webpack, this is parcel , Zero configuration packaging
Create the project directory directly, write a simple traditional page
Then open the command line tool in the project root directory, enter the following command
parcel index.html -p 3030
Then Open http://localhost:3030/ in the browser to open the page you just developed
In the above command, -p is used to set the port number. If not set, the 1234 port will be started by default
parcel supports hot update, and will monitor changes in html, css, and js and render them immediately
// In fact, css and js introduced through src cannot be hot updated
After the development is completed, Enter the following command to package
parcel build index.html
The dist directory will be generated after packaging
Qiaodou sack, what about the package? Why are there still so many files?
Don’t worry, this is a page written in traditional writing. It doesn’t even have package.json. Next, transform it into a modular project and you can see the effect of packaging
Okay, let me open index.html manually first to see the effect...wait...why is the css not loaded?
This is because the packaged paths are all absolute paths, so it is no problem to put them on the server. If you need to open them locally, you have to manually change them to relative paths
II , applied in modular projects
Start the main film, first transform the above project into a modular project
Through thenpm init -y
command Create a default package.json and modify the startup and packaging commands
so that you can directly start the project through npm run dev
, npm run build
execute the packaging
Before, it was a globally installed parcel. In actual practice, it is recommended to add dependencies in the project.
npm install parcel-bundler -S
The above is a traditional page, using the css introduced by link
Since it needs to be transformed into a module project, then you only need to introduce a main.js, and then introduce other css and js files in main.js
So you need to use ES6 syntax such as import, then install a babel
npm install babel-preset-env -S
Then create a .babelrc file in the root directory and add the following configuration:
{ "presets": ["env"] }
Install a css conversion tool, such as autoprefixer
npm install postcss-modules autoprefixer -S
Create a .postcssrc file:
{ "modules": true, "plugins": { "autoprefixer": { "grid": true } } }
The official document also recommends a plug-in PostHTML for compiling html resources, but there is no need to
modify the code by yourself for the time being. Finally, npm run build
Packaging
can See that js and css have been integrated, and their content has been compiled by babel and autoprefixer
3. Use Parcel in the Vue project
The official document gives a formula suitable for react projects
But I usually use vue. After researching for a long time, I finally found a method
Still using index.html as the entry and introducing main with script .js:
<!-- index.html --> <body> <p id="app"></p> <script src="./src/main.js"></script> </body> // main.js import 'babel-polyfill' import Vue from 'vue' import App from './App.vue' import router from './router' import './css/common.css' Vue.config.productionTip = false const vm = new Vue({ el: '#app', router, render: h => h(App) })
Here I would like to recommend a very powerful plug-in parcel-plugin-vue, which allows parcel and vue to successfully join hands
In addition to the previously mentioned babel and autoprefixer, the final package.json is like this:
{ "name": "ParcelVue", "version": "1.0.0", "description": "The project of parcel & vue created by Wise Wrong", "main": "main.js", "scripts": { "dev": "parcel index.html -p 3030", "build": "parcel build index.html" }, "keywords": [ "parcel", "vue" ], "author": "wisewrong", "license": "ISC", "devDependencies": { "autoprefixer": "^7.2.3", "babel-polyfill": "^6.26.0", "babel-preset-env": "^1.6.1", "parcel-bundler": "^1.3.0", "parcel-plugin-vue": "^1.4.0", "postcss-modules": "^1.1.0", "vue-loader": "^13.6.1", "vue-style-loader": "^3.0.3", "vue-template-compiler": "^2.5.13" }, "dependencies": { "vue": "^2.5.13", "vue-router": "^3.0.1" } }
Be sure to create .postcssrc and .babelrc files in the root directory
Then npm install installs dependencies, npm run dev starts the project, npm run build packages the project
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to solve the problem of invalid static resource images after vue packaging
How to deploy vue-router and express projects to the server
Solution to using axios express local request 404 under Vue 2.5.2
Use vue and react to achieve expansion, collapse and other effects
How to implement webpack packaging optimization in vue
Detailed explanation of vue coding style
The above is the detailed content of How to achieve extremely fast zero-configuration packaging in Parcel.js + Vue 2.x. For more information, please follow other related articles on the PHP Chinese website!

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment