const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
module: {
rules: [
{
oneOf: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
/* your loader here */
})
}
]
}
]
}
};
loader: ExtractTextPlugin.extract({
use: [
{
loader: require.resolve("css-loader"),
options: {
minimize: true
}
}
]
});
const webpack = require("webpack");
module.exports = {
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
]
};
const webpack = require("webpack");
module.exports = {
plugins: [
new webpack.optimize.UglifyJsPlugin({
/* settings */
})
]
};
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
module.exports = {
plugins: [new BundleAnalyzerPlugin()]
};
const webpack = require("webpack");
module.exports = {
entry: {
client: "./src/index.js",
vendor: ["react", "react-dom", "react-router", "react-router-dom"]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
filename: "vendor.[chunkhash].js"
})
]
};
const webpack = require("webpack");
const path = require("path");
const buildPath = path.resolve("build");
module.exports = {
output: {
path: buildPath,
filename: "[name].[chunkhash:8].js",
chunkFilename: "[name].[chunkhash:8].chunk.js"
}
};
// home.js
import React from "react";
export default () => (
<div className="wrapper">
<h2>Home</h2>
</div>
);
// home-container.js
import Loadable from "react-loadable";
import Spinner from "../Common/Spinner";
export default Loadable({
loader: () => import("./Home" /*webpackChunkName: 'home' */),
loading: Spinner
});
export default class extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
return true;
}
}
export default class extends React.PureComponent {
shouldComponentUpdate(nextProps, nextState) {
return !(
shallowEqual(nextProps, this.props) && shallowEqual(nextState, this.state)
);
}
}
const arr1 = [1, 2, 3];
const arr2 = [1, 2, 3];
arr1 === arr2; // false
const obj1 = { foo: "bar" };
const obj2 = { foo: "bar" };
obj1 === obj2; // false
class Todo extends React.Component {
render() {
return (
<li className="todo" onClick={this.props.onClick}>
{this.props.todo}
</li>
);
}
}
render() {
return (
<ul>
{this.props.todos.map(todo => (
<Todo todo={todo} onClick={() => this.props.onTodoClick(todo.id)} />
))}
</ul>
);
}
class Todo extends React.Component {
handleClick = e => {
this.props.onClick(this.props.todo.id);
};
render() {
return (
<li className="todo" onClick={this.handleClick}>
{this.props.todo}
</li>
);
}
}
class TodoList extends React.PureComponent {
render() {
return (
<ul>
{this.props.todos.map(todo => (
<Todo todo={todo} onClick={this.props.onTodoClick} />
))}
</ul>
);
}
}
render() {
return (
<ul>
{this.props.todos.map(todo => (
<Todo
todo={todo}
onClick={this.props.handleClick.bind(this)}
/>
))}
</ul>
);
}
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick = todoId => {
this.setState({
[todoId]: { clicked: true }
});
};
export default class extends React.PureComponent {
render() {
return (
<TodoList
options={{
wrap: false,
maximizeOnFoucs: true
}}
/>
);
}
}
const TODO_LIST_OPTIONS = {
wrap: false,
maximizeOnFoucs: true
};
export default class extends React.PureComponent {
render() {
return <TodoList options={TODO_LIST_OPTIONS} />;
}
}
// You have this 4 components
const elements = [
{ type: "div", key: 0, textContent: "Container #0" },
{ type: "div", key: 1, textContent: "Container #1" },
{ type: "div", key: 2, textContent: "Container #2" },
{ type: "div", key: 3, textContent: "Container #3" }
];
// Delete Container #1
const elements = [
{ type: "div", key: 0, textContent: "Container #0" },
// Components with text Container #2 and Container #3 has new indexes
{ type: "div", key: 1, textContent: "Container #2" },
{ type: "div", key: 2, textContent: "Container #3" }
];
const TodoFactory = ({ todo, onClick }) => (
<li className="todo" onClick={onClick}>
{todo.title}
</li>
);
export default ({ todos }) => (
<ul>{todos.map(todo => TodoFactory({ todo, onClick: console.log }))}</ul>
);