parcel
一個快速,零配置的 Web 應用程序打包工具,這裏我介紹下如何和vue
結合進行開發,強烈建議node8
以上,具體代碼:https://github.com/zlxbuzz/pa...css
mkdir parcel-demo && cd parcel-demo && yarn init -y
yarn add parcel-bundler parcel-plugin-vue babel-preset-env less --dev yarn add vue-router
其中parcel-bundler
是主要的工具,對於vue
結尾的單文件,須要單獨處理文件類型,parcel-plugin-vue
這個插件會經過vueify
來生成對應的代碼,parcel
會自動加載parcel-plugin
開頭的依賴。html
//postcss.config.js module.exports = { plugins: [ require('autoprefixer')({ browsers: [ 'last 20 versions', 'IE 9', 'iOS >= 8']})] }
//.babelrc { "presets": [ ["env"] ] }
這裏引用了mint
來方便展現頁面vue
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name=viewport content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1"> <title>parcel-vue-demo</title> <!-- 引入樣式 --> <link rel="stylesheet" href="https://cdn.bootcss.com/mint-ui/2.2.13/style.css"> <script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script> <!-- 引入組件庫 --> <script src="https://cdn.bootcss.com/mint-ui/2.2.13/index.js"></script> </head> <body> <app></app> <script src="./src/index.js"></script> </body> </html>
和基於webpack開發的目錄結構一致,具體代碼能夠參考 https://github.com/zlxbuzz/pa...node
src ├── app.vue ├── index.js ├── index.less ├── router.js └── views ├── detail.vue └── index.vue
//index.js import app from './app.vue' import router from './router' import './index.less' window.onload = function(){ new Vue({ router, el: 'app', components: { app } }); }
{ "name": "h5", "version": "1.0.0", "main": "index.js", "license": "MIT", "scripts": { "dev": "parcel index.html", "build": "parcel build index.html --public-url /" }, "devDependencies": { "babel-preset-env": "^1.6.1", "less": "^2.7.3", "parcel-bundler": "^1.2.0", "parcel-plugin-vue": "^1.0.1" }, "dependencies": { "vue-router": "^3.0.1" } }
只須要執行npm run dev
和 npm run build
就能夠進行開發和構建,public-url
就至關於資源的引用路徑。webpack