修改npm源为淘宝源
npm config set registry "https://registry.npm.taobao.org"
vue脚手架
- npm install -g vue-cli
- vue list
- vue init webpack name
- cd name
- npm install
- npm run dev
React+Webpack+ES6环境搭建
- npm install -g webpack 全局安装webpack
- npm init 自定义创建package.json
npm init -yes 可以创建默认的package.json - npm install webpack --save-dev 项目内安装webpack
- npm install react react-dom --save-dev 安装react
- npm install babel-loader babel-preset-es2015 babel-preset-react --save-dev
安装babel插件 - webpack.config.js配置
var path = require('path'); var webpack = require('webpack'); module.exports = { entry: ['webpack/hot/dev-server', path.resolve(__dirname, './app/main.js')], output: { path: path.resolve(__dirname, './build'), filename: 'bundle.js' }, devServer: { inline: true, port: 8181 }, module: { loaders: [ { test: /.js?$/, exclude: /(node_modules|bower_components)/, loader: 'babel', query: { presets: ['es2015', 'react'] } } ] }, plugins: [ new webpack.HotModuleReplacementPlugin() ] };
- npm install webpack-dev-server --save-dev
- 在package.json文件中为scripts添加
"scripts": { "build": "webpack", "dev": "webpack-dev-server --devtool eval --progress --colors --content-base build" }
react脚手架
npm install -g create-react-app
create-react-app react-cli-demo
- npm install -g yo 安装yo
- yo --version 是否安装成功
- npm install -g generator-reactpackage
- 创建项目 新建项目文件夹 yo reactpackage
- npm run dev //项目开发过程使用,启动服务,实时刷新
npm run build //开发完成之后打包文件(js、css分开打包)
generator-react-webpack
- npm install -g yo
- npm install -g generator-react-webpack
- 新建项目文件夹 "cd进去" yo react-webpack