Created
January 21, 2019 22:34
-
-
Save beriberikix/492f5d4c2a060509b45ad1a4e68e9433 to your computer and use it in GitHub Desktop.
webpack tl;dr blog post
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
import _ from 'lodash'; | |
import printMe from './print.js'; | |
import './style.css'; | |
import Icon from './icon.png'; | |
function component() { | |
let element = document.createElement('div'); | |
var btn = document.createElement('button'); | |
element.innerHTML = _.join(['Hello', 'webpack'], ' '); | |
element.classList.add('hello'); | |
btn.innerHTML = 'Click me and check the console!'; | |
btn.onclick = printMe; | |
element.appendChild(btn); | |
var myIcon = new Image(); | |
myIcon.src = Icon; | |
element.appendChild(myIcon); | |
return element; | |
} | |
document.body.appendChild(component()); |
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
{ | |
"name": "webpack-demo", | |
"version": "1.0.0", | |
"description": "", | |
"private": true, | |
"scripts": { | |
"build": "webpack --config webpack.prod.js", | |
"start": "webpack-dev-server --open --config webpack.dev.js" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"clean-webpack-plugin": "^1.0.0", | |
"css-loader": "^2.1.0", | |
"file-loader": "^3.0.1", | |
"html-webpack-plugin": "^3.2.0", | |
"style-loader": "^0.23.1", | |
"webpack": "^4.29.0", | |
"webpack-cli": "^3.2.1", | |
"webpack-dev-server": "^3.1.14", | |
"webpack-merge": "^4.2.1" | |
}, | |
"dependencies": { | |
"lodash": "^4.17.11" | |
} | |
} |
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
export default function printMe() { | |
console.log('I get called from print.js!'); | |
} |
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: 'FiraCode'; | |
src: url('./FiraCode-Regular.woff2') format('woff2'), | |
url('./FiraCode-Regular.woff') format('woff'); | |
font-weight: 600; | |
font-style: normal; | |
} | |
.hello { | |
color: blue; | |
font-family: 'FiraCode'; | |
background: url('./icon.png'); | |
} |
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 CleanWebpackPlugin = require('clean-webpack-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
module.exports = { | |
entry: { | |
app: './src/index.js' | |
}, | |
plugins: [ | |
new CleanWebpackPlugin(['dist']), | |
new HtmlWebpackPlugin({ | |
title: 'Production' | |
}) | |
], | |
output: { | |
filename: '[name].bundle.js', | |
path: path.resolve(__dirname, 'dist') | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.css$/, | |
use: [ | |
'style-loader', | |
'css-loader' | |
] | |
}, | |
{ | |
test: /\.(png|svg|jpg|gif)$/, | |
use: [ | |
'file-loader' | |
] | |
}, | |
{ | |
test: /\.(woff|woff2|eot|ttf|otf)$/, | |
use: [ | |
'file-loader' | |
] | |
} | |
] | |
} | |
}; |
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 merge = require('webpack-merge'); | |
const common = require('./webpack.common.js'); | |
module.exports = merge(common, { | |
mode: 'development', | |
devtool: 'inline-source-map', | |
devServer: { | |
contentBase: './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
const merge = require('webpack-merge'); | |
const common = require('./webpack.common.js'); | |
module.exports = merge(common, { | |
mode: 'production', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment