This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this function will reside in the webpack.config.js. | |
// It accepts 'browserList' from 'browserList' key in 'package.json' | |
// therefore, no need for .babelrc file anymore | |
const configureBabelLoader = (browserList = []) => { | |
return { | |
test: /\.jsx?$/, | |
exclude: settings.babelLoaderConfig.exclude, | |
use: { | |
loader: "babel-loader", | |
options: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<style> | |
<%= compilation.assets[htmlWebpackPlugin.files.chunks.critical.css[0]].source() %> | |
</style> | |
</head> | |
<body> | |
<div id="app"></div> | |
</body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// webpack.config.js | |
module.exports = { | |
entry: { | |
critical: path.resolve(__dirname, "../src/css/index.scss") // this's a chunk, source from a file with my critical CSS I wanna inline! | |
}, | |
plugins: [ | |
new MiniCssExtractPlugin({ | |
filename: "[name].css" // it's gonna be 'critical.css' | |
}), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
// Target latest version of ECMAScript. | |
"target": "esnext", | |
// Search under node_modules for non-relative imports. | |
"moduleResolution": "node", | |
// Process & infer types from .js files. | |
"allowJs": true, | |
// Don't emit; allow Babel to transform files. | |
"noEmit": true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | |
const CleanWebpackPlugin = require("clean-webpack-plugin"); | |
const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
module.exports = { | |
mode: "production", // this trigger webpack out-of-box prod optimizations | |
entry: "./index.js", | |
output: { | |
filename: `[name].[hash].js`, // [hash] is useful for cache busting! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
module.exports = { | |
mode: "development", // this will trigger some webpack default stuffs for dev | |
entry: "./index.js", // if not set, default path to './src/index.js'. Accepts an object with multiple key-value pairs, with key as your custom bundle filename(substituting the [name]), and value as the corresponding file path | |
output: { | |
filename: "[name].bundle.js", // [name] will take whatever the input filename is. defaults to 'main' if only a single entry value | |
path: path.resolve(__dirname, "dist") // the folder containing you final dist/build files. Default to './dist' | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@font-face { | |
font-family: "fontello"; | |
src: url("./font/fontello.woff2") format("woff2"), | |
url("./font/fontello.woff") format("woff"), | |
url("./font/fontello.ttf") format("truetype"), | |
url("./font/fontello.svg") format("svg"); | |
font-weight: normal; | |
font-style: normal; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// destructure the object given when called in the <Hello />, | |
// then pass those properties to our <CustomComponent /> to be consumed. | |
// The 'isSubmitting' value will be toggled and consumed accordingly too! | |
<Hello> | |
{({ | |
handleThisClick, | |
handleFormSubmit, | |
isSubmitting | |
}) => ( | |
<CustomComponent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hello extends React.Component { | |
state = { isSubmitting: false } | |
handleThisClick = () => { | |
/* do your thing here */ | |
} | |
handleFormSubmit = async event => { | |
event.preventDefault(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function as children pattern | |
// Notice below that the body/children of <Hello /> is a anonymous function definition! | |
<Hello> | |
{ (foo) => (<World foo={foo} />) } | |
</Hello> | |
/* | |
And then we execute the function - this.props.children(), | |
while passing it the 'foo' data as an argument to the function above- | |
(foo) => (<World foo={foo} />), giving us whatever view is rendered inside the <World />! |