从零构建一个Vue UI组件库(一)
Hello Ninecat-ui
index.js
import Vue from 'vue'
import App from './index.vue'
new Vue({
render: h => h(App)
}).$mount('#app')
内容好了,现在需要简单的配置一下webpack让项目运行起来。
在跟目录下新建一个build目录,里面新增一个webpack配置文件webpack.config.base.js
'use strict'
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader')
const path = require('path')
module.exports = {
entry: path.resolve(__dirname, '../src/index.js'),
output: {
path: path.resolve(__dirname, '../dist'),
filename: "index.js"
},
module: {
rules: [
{
test: /\.js$/,
loader: "babel-loader",
exclude: /node_modules/
},
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
filename: 'index.html',
}),
new VueLoaderPlugin(),
]
}
如果有同学还不懂这些基本的配置,应该去翻一下webpack的官方文档了哦,给出链接:https://www.webpackjs.com/
进行如上配置,一个基本的VUE项目就搭建差不多了,然后我们需要配置一下项目的启动脚本。在package.json里面scripts下进行如下配置:
"scripts": {
"start": "webpack-dev-server --config build/webpack.config.base.js"
},
最后来看一下我们的项目目录结构:
image
然后运行一下我们的项目:yarn start
image
OK,到这里基本的一个vue项目搭建好了,我们后面就可以开始构建组件了。
第一节源码在ninecat-ui/ninecat-train tag1.0.0
下一章:
从零构建一个Vue UI组件库(二)
