1.初始化
-
npm init 初始化项目,会生成package.json. 此时项目就拥有装有的node_modules运行环境。
-
安装相应的包 npm i webpack vue vue-loader, 并根据提示安装需求的依赖包。如css-loadervue-template-complier
vue无法在浏览器中直接运行,将vue组件挂载到js,然后通过webpack将js、css、图片等所有资源进行打包。
2.新建组件
3.新建index.js文件挂载vue组件
4.新建webpack.config.js
5.由于webpack原生只支持js打包的,超过原生的其他资源,需要在webpack.config.js中进行声明rules
6.编辑package.json
"build": "webpack --config webpack.config.js"