标签:script 结果 asc uil clu curl 创建项目 关注 运行
安装homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install node
node -v npm -v
mkdir react-demo //创建app目录 用来存放项目源文件 cd react-demo //进入react-demo目录 mkdir dist // 创建dist目录 用来存放打包好的文件 touch webpack.config.js //创建webpack的配置文件 mkdir src //创建源码目录 cd src //进入到src目录 mkdir components //存放组件目录 touch index.js //在app目录中创建 index文件 入口文件 cd .. //返回到 react-demo目录 npm init -y //初始化项目
npm install webpack --save-dev
module.exports = { context:__dirname+"/src", //源文件目录 entry:{ index:"./index.js" //在源文件目录下去找index.js 文件作为打包的入口文件 }, output:{ path:__dirname+"/dist", //生成的文件存放目录 filename:"[name].bundle.js" //生成的文件 name 表示entry下面的app } }
{ "name": "ES6-demo", "version": "1.0.0", "description": "", "main": "webpack.config.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build":"./node_modules/.bin/webpack" }, }, "keywords": [], "author": "", "license": "ISC", "dependencies": {}, "devDependencies": { "webpack": "^2.6.1" } }
<!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"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <script src="index.bundle.js"></script> </body> </html>
alert(1)
npm run build
npm install babel-loader babel-core babel-preset-es2015 --save-dev
module.exports = { context:__dirname+"/app", entry:{ index:"./index.js" }, output:{ path:__dirname+"/dist", filename:"[name].bundle.js" }, module:{ rules:[ { test:/\.jsx?$/, exclude: /node_modules/, use: [{ loader: "babel-loader", options: { presets: ["es2015"] } }], }, ] } }
npm install webpack-dev-server --save-dev
"scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build":"./node_modules/.bin/webpack", "dev": "./node_modules/.bin/webpack-dev-server --content-base dist" //这里是新添加内容 },
npm install react react-dom --save npm install babel-preset-react --save-dev
module.exports = { context:__dirname+"/app", entry:{ index:"./index.js" }, output:{ path:__dirname+"/dist", filename:"[name].bundle.js" }, module:{ rules:[ { test:/\.jsx?$/, exclude: /node_modules/, use: [{ loader: "babel-loader", options: { presets: ["react","es2015"] } }], }, ] } }
import React from ‘react‘; import ReactDOM from ‘react-dom‘; ReactDOM.render(<h1>hello</h1>,document.querySelector("#container"))
<div id="container"></div>
npm run dev
npm install css-loader style-loader --save-dev
module.exports = { context:__dirname+"/app", entry:{ app:"./index.js" }, output:{ path:__dirname+"/dist", filename:"[name].bundle.js" }, module:{ rules:[ { test:/\.jsx?$/, exclude: /node_modules/, use: [{ loader: "babel-loader", options: { presets: ["react","es2015"] } }], }, { //这里的内容是新增加的对样式的支持 test: /\.css$/, use: ["style-loader", "css-loader"], }, ] } }
body{ background-color: green }
import ‘./css/index.css‘
标签:script 结果 asc uil clu curl 创建项目 关注 运行
原文地址:http://www.cnblogs.com/dadifeihong/p/6964908.html