parcel-vue

使用parcel + vue的项目简单介绍

介绍

  • 传统的webpack配置越来越复杂,对于追求简洁的前端工程化来说似乎有点背道而驰,随着其功能越来越强大,也不可避免的越来越臃肿,其配置都要好久,我也是菜鸟,昨天有个老哥给我说了Parcel,今天试了一下,就发出来试试

Parcel

  • Parcel 是一个Web应用程序 打包器(bundler) ,与以往的开发人员使用的打包器有所不同。它利用多核处理提供极快的性能,并且你不需要进行任何配置。(摘自官方文档)
    功能介绍

手动搭建

  • 首先,你需要创建一个项目,我命名为vue-parcel
mkdir vue-parcel
  • 接着安装所需的依赖项
cd vue-parcel //进入项目目录
npm init -y //初始化
npm install --save vue // 安装vue
npm install --save-dev parcel-bundler // 安装parcel
  • 新建一个index.html文件,作为parcel的入口文件
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Vue Parcel Example</title>
</head>
<body>
  <div id="app">
  </div>

  <script src="src/main.js"></script>
</body>
</html>
  • 创建src目录和main.js的文件
import Vue from 'vue';
import App from './App.vue';

new Vue({
  render: h => h(App)
}).$mount('#app')
  • 创建 App.vue和components / HelloWorld.vue
    App.vue
<template>
  <div id="app">
    <HelloWorld />
  </div>
</template>

<script>
import HelloWorld from './components/HelloWorld';

export default {
  components: {
    HelloWorld
  }
}
</script>

HelloWorld.vue

<template>
  <div class="hello-world">
    <h1>Hello World!</h1>
  </div>
</template>

<script>
export default {
  name: 'hello-world',
}
</script>
  • 替换package.json脚本,将启动项目和打包项目替换
"scripts": {
    "start": "parcel index.html",
    "build": "parcel build index.html"
  },
  • 最终如图所示


    项目结构
  • 启动时默认为localhost:1234,而不是常用的8080端口

快速构建

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容