Skip to content

Commit

Permalink
Add webpack for library packaging and enable multiple html
Browse files Browse the repository at this point in the history
  • Loading branch information
afgalvan committed Mar 13, 2021
1 parent 3505842 commit 4a3a682
Show file tree
Hide file tree
Showing 18 changed files with 4,381 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
1 change: 1 addition & 0 deletions build/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>About</title><link href="css/app.bundle.css" rel="stylesheet"></head><body><h1>About</h1><script defer="defer" src="js/about.bundle.js"></script></body></html>
1 change: 1 addition & 0 deletions build/css/app.bundle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{margin:0;padding:0;background-color:3d3d3d}
1 change: 1 addition & 0 deletions build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Index</title><script defer="defer" src="js/app.bundle.js"></script><script defer="defer" src="js/about.bundle.js"></script><link href="css/app.bundle.css" rel="stylesheet"></head><body><h1>Index</h1></body></html>
1 change: 1 addition & 0 deletions build/js/about.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/js/app.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,35 @@
"@types/util.promisify": "^1.0.4"
},
"devDependencies": {
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.17",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"babel-loader": "^8.2.2",
"css-loader": "^5.1.2",
"css-minimizer-webpack-plugin": "^1.2.0",
"eslint": "^7.16.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.0",
"html-loader": "^2.1.2",
"html-webpack-plugin": "^5.3.1",
"jest": "^26.6.3",
"mini-css-extract-plugin": "^1.3.9",
"prettier": "^2.2.1",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^5.1.1",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"typescript": "^4.1.3",
"webpack": "^5.25.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
},
"scripts": {
"dev": "webpack serve --open --mode=development",
"build": "webpack --mode=production",
"test": "jest",
"start": "ts-node src/index.ts"
},
Expand Down
12 changes: 12 additions & 0 deletions src/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>About</title>
</head>
<body>
<h1>About</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions src/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
exports.__esModule = true;
require("./styles/main.css");
console.log('about');
3 changes: 3 additions & 0 deletions src/about.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './styles/main.css';

console.log('about');
12 changes: 12 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index</title>
</head>
<body>
<h1>Index</h1>
</body>
</html>
19 changes: 19 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";
exports.__esModule = true;
exports.Numbers = void 0;
require("./styles/main.css");
console.log('about');
var Numbers = /** @class */ (function () {
function Numbers() {
}
Numbers.prototype.isOdd = function (numbers) {
var answer = numbers.map(function (value) {
if (value % 2 == 0)
return false;
return true;
});
return answer;
};
return Numbers;
}());
exports.Numbers = Numbers;
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import './styles/main.css';

console.log('about');
export class Numbers {
public isOdd(numbers: number[]): boolean[] {
const answer = numbers.map((value: number) => {
Expand Down
8 changes: 8 additions & 0 deletions src/styles/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/styles/main.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/styles/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
margin: 0;
padding: 0;
color: white;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: #3d3d3d;
}
75 changes: 75 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
entry: {
app: './src/index.js',
about: './src/about.js'
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'js/[name].bundle.js',
},

devServer: {
port: 3000,
},

module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.html$/i,
loader: 'html-loader',
},
],
},

optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: true,
terserOptions: {
compress: true,
},
}),
new CssMinimizerPlugin({
sourceMap: true,
}),
],
},

plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
minify: {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
},
}),
new HtmlWebpackPlugin({
template: './src/about.html',
inject: 'body',
chunks: ['about'],
filename: 'about.html',
}),
new MiniCssExtractPlugin({
filename: 'css/app.bundle.css',
}),
],
};

0 comments on commit 4a3a682

Please sign in to comment.