Skip to content

Instantly share code, notes, and snippets.

@IrenaYuan
Last active March 15, 2018 08:06
Show Gist options
  • Save IrenaYuan/91143bacfcec5b4ab13322387149981a to your computer and use it in GitHub Desktop.
Save IrenaYuan/91143bacfcec5b4ab13322387149981a to your computer and use it in GitHub Desktop.
webpack3 with React
{
"presets": ['env', 'react']
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component{
render() {
console.log("it's work");
return (
<div>Hello word</div>
)
}
}
ReactDOM.render(<App /> , document.getElementById('app'));
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --open",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.18",
"html-webpack-plugin": "^2.30.1",
"webpack": "^3.11.0",
"webpack-dev-server": "^2.11.1"
},
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0"
}
}
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
entry: {
app: './src/index.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js'
},
devtool: 'inline-source-map',
devServer: {
contentBase: './dist',
hot: false
},
module: {
rules: [
{
test: /\.js[x]?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
template: "./src/index.html"
})
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment