做者:robert 倉庫地址:gitee.com/dawwdadfrf/…css
最近在學習element的源碼,想着學習element的時候來順便把webpack,css,ts方面的知識也學一學,由於是第一次分享,過程當中可能存在着不少的不足之處。請你們多多指教。本項目適用於小夥伴入門,文章將持續更新html
網址:gitee.com/vue
git init
複製代碼
當前頁面在左邊會多了一堆3K+的東西。node
node_modules/
dist/
package-lock.json
複製代碼
此時旁邊的圈住的個數變成了個位數了webpack
git add .
git commit -m "[feature]第一次提交"
git remote add origin **********************
git push -u origin master
複製代碼
npm install --save-dev webpack-dev-server
"scripts": {
"dev": "webpack-dev-server --watch -inline --progress --config build/webpack.config.js",
"build": "webpack --config build/webpack.config.js"
},
複製代碼
devServer: {
host: '127.0.0.1',
port: 8085,
publicPath: '/',
hot: true,
stats: 'errors-only'
},
複製代碼
npm run dev
複製代碼
運行後發現頁面中如今是這樣一個目錄,下一個部分就是帶你們在頁面中展現對應的html內容 git
git add .
git commit -m '[feature]webpack服務安裝成功'
git push
複製代碼
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, '../dist')
},
devServer: {
host: '127.0.0.1',
port: 8085,
publicPath: '/',
hot: true
},
}
複製代碼
{
"name": "share-ui",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack-dev-server --watch -inline --progress --config build/webpack.config.js",
"build": "webpack --config build/webpack.config.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
}
}
複製代碼
舒適提示: 第二部份內容只對package.json和webpack.config.js裏的文件作了修改
npm install --save-dev webpack-dev-server
web
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Element - The world's most popular Vue UI framework</title> <meta name="description" content="Element,一套爲開發者、設計師和產品經理準備的基於 Vue 2.0 的桌面端組件庫" /> </head> <body> <div id="app"></div> </body> </html> 複製代碼
const HtmlWebpackPlugin = require('html-webpack-plugin');
plugins: [
new HtmlWebpackPlugin({
template: './examples/index.tpl',
})
]
複製代碼
提示每次修改完webpack.config.js中的內容都須要從新運行命令vue-cli
git add .
git commit -m '[feature]引入html模版'
git push
複製代碼
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, '../dist')
},
devServer: {
host: '127.0.0.1',
port: 8085,
publicPath: '/',
hot: true
},
plugins: [
new HtmlWebpackPlugin({ //打包生成新的html文件
template: './examples/index.tpl',
})
]
}
複製代碼
npm install vue
npm install --save-dev vue-loader
npm install --save-dev vue-template-compiler
複製代碼
<template>
<div>
{{name}}
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
name: '嘿嘿嘿'
}
}
}
</script>
複製代碼
import Vue from 'vue';
import entry from './app.vue'
new Vue({
el: "#app",
render: h => h(entry)
})
複製代碼
const VueLoaderPlugin = require('vue-loader/lib/plugin');
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
plugins: [
new VueLoaderPlugin(),
]
複製代碼
entry: './src/index.js',
複製代碼
變動爲npm
entry: './examples/main.js',
複製代碼
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
module.exports = {
entry: './examples/main.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, '../dist')
},
devServer: {
host: '127.0.0.1',
port: 8085,
publicPath: '/',
hot: true
},
plugins: [
new HtmlWebpackPlugin({ //打包生成新的html文件
template: './examples/index.tpl',
}),
new VueLoaderPlugin(),
],
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
}
複製代碼
git add .
git commit -m '[feature]引入vue文件'
git push
複製代碼
以上內容若有遺漏錯誤,歡迎留言 ✍️指出,一塊兒進步💪💪💪
若是以爲本文對你有幫助,🏀🏀留下你寶貴的 👍