-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Morné Louw edited this page Mar 19, 2022
·
11 revisions
- Updated my
.git/gitconfigand added my usual command aliases to work quicker with git.
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branchThis doesn't get pushed to the repo, but my aliases are:
[alias]
st = status
co = checkout
ci = commit
br = branch- Check if you have
npminstalled, by running the line below, you should get a version number printed to the terminal, eg: "8.1.2"
npm -v
- If you don't have
npminstalled yet, then download it here and follow the steps there to install it: https://nodejs.org/en/download/
(see "From Scratch" below)
git clone git@github.com:monello/webpack-sandbox.gitnpm install
- Create a new repo on Github
- Checkout the repo
eg.
git clone git@github.com:monello/new-repo-name-goes-here.git - Add a
.gitignorefile in the root directory and add the following in it so long:
node_modules
package-lock.json
dist
- Initialize
npm- to create thepackage.jsonfile. The-yflag means "Yes, set up thepackage.jsonwith default values and don't ask all the set-up questions"
npm init -y
- Add some NPM run scripts
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack serve --open",
"watch": "webpack --watch",
"build": "webpack --config webpack.config.prod.js"
},- Install
devDependencies
npm install --save-dev webpack webpack-cli webpack-dev-server typescript ts-loader html-webpack-plugin
- Initialize the TypeScript compiler. This will create a
tsconfig.jsonfile
tsc --init
- Open the
tsconfig.jsonfile. Set at least the following:
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"allowJs": true,
"sourceMap": true,
"outDir": "./dist",
"removeComments": true,
"noEmitOnError": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"skipLibCheck": true
},
"exclude": [
"node_modules"
]
}- Create the Development WebPack config file
/webpack.config.js- Add the following content:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: "development",
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
clean: true
},
devtool: 'inline-source-map',
devServer: {
static: './dist',
},
plugins: [
new HtmlWebpackPlugin({
hash: true,
title: 'Webpack TypeScript Setup',
myPageHeader: 'Hello World - using "webpack.config.js"',
template: './src/index.html'
}),
],
};- Create the Production WebPack config file
/webpack.config.prod.js- Add the following content:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: "production",
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
clean: true
},
devServer: {
static: './dist',
},
plugins: [
new HtmlWebpackPlugin({
hash: true,
title: 'Webpack TypeScript Setup',
myPageHeader: 'Hello World - using "webpack.config.prod.js"',
template: './src/index.html'
}),
],
};- Add an
index.htmlfile in the./srcdir, and add something in it so view in the browser - Run
npm startto testwebpack-dev-serverand it should automatically open this app in the browser and display whatever you added in theindex.html.- Change and save what you display in the HTML file and you should see the browser auto-reload and see you update
Now would be a good time to do an initial commit for the project.