Skip to content

Commit fa651fc

Browse files
erunionGabe Ratcliff
andauthored
feat: setting up webpack (#4)
* feat: first pass at setting up webpack * chore: adding support for dev-server * chore: prettier linting Co-authored-by: Gabe Ratcliff <gaberatcliff@Meghans-MBP.attlocal.net>
1 parent c42575d commit fa651fc

File tree

8 files changed

+5536
-255
lines changed

8 files changed

+5536
-255
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
dist/
12
node_modules/
23
coverage/

package-lock.json

Lines changed: 5440 additions & 253 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"pretest": "npm run lint && npm run prettier && npm run inspect",
1616
"prettier": "prettier --list-different --write \"./**/**.{js,jsx}\"",
1717
"test": "jest --coverage --runInBand",
18-
"version": "conventional-changelog -i CHANGELOG.md -s && git add CHANGELOG.md"
18+
"version": "conventional-changelog -i CHANGELOG.md -s && git add CHANGELOG.md",
19+
"build": "webpack --config ./webpack.config.js",
20+
"start": "webpack-dev-server --open --config ./webpack.config.dev.js",
21+
"watch": "webpack -w --progress"
1922
},
2023
"license": "ISC",
2124
"repository": "https://github.com/readmeio/syntax-highlighter",
@@ -26,16 +29,22 @@
2629
"@commitlint/config-conventional": "^9.1.2",
2730
"@readme/eslint-config": "^3.2.0",
2831
"babel-jest": "^26.3.0",
32+
"babel-loader": "^8.1.0",
2933
"babel-polyfill": "^6.26.0",
3034
"conventional-changelog-cli": "^2.1.0",
3135
"enzyme": "^3.11.0",
3236
"enzyme-adapter-react-16": "^1.15.4",
3337
"eslint": "^7.0.0",
3438
"glob": "^7.1.6",
39+
"html-webpack-plugin": "^4.4.1",
3540
"husky": "^4.2.5",
3641
"jest": "^26.0.1",
3742
"jsinspect": "^0.12.6",
38-
"prettier": "^2.0.1"
43+
"prettier": "^2.0.1",
44+
"terser-webpack-plugin": "^4.1.0",
45+
"webpack": "^4.44.1",
46+
"webpack-cli": "^3.3.12",
47+
"webpack-dev-server": "^3.11.0"
3948
},
4049
"prettier": "@readme/eslint-config/prettier",
4150
"husky": {

public/favicon.ico

22.4 KB
Binary file not shown.

public/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<head>
2+
<meta charset="UTF-8">
3+
<title>Syntax Highlighter</title>
4+
<link rel="icon" type="image/png" href="./favicon.ico"/>
5+
</head>
6+
<div id="root" />

public/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import ReactDOM from 'react-dom';
2+
import syntaxHighlighter from '../src/index';
3+
4+
ReactDOM.render(
5+
syntaxHighlighter('console.log("Hello, world!");', 'js', { dark: true }),
6+
document.getElementById('root')
7+
);

webpack.config.dev.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const HtmlWebPackPlugin = require('html-webpack-plugin');
2+
const path = require('path');
3+
4+
module.exports = {
5+
entry: ['./public/index.js'],
6+
module: {
7+
rules: [
8+
{
9+
test: /\.js(x?)$/,
10+
use: {
11+
loader: 'babel-loader',
12+
options: {
13+
extends: './.babelrc',
14+
},
15+
},
16+
},
17+
],
18+
},
19+
output: {
20+
path: path.resolve(__dirname, 'dist'),
21+
filename: 'index.js',
22+
publicPath: '/',
23+
},
24+
resolve: {
25+
extensions: ['.js', '.jsx'],
26+
},
27+
plugins: [
28+
new HtmlWebPackPlugin({
29+
template: path.resolve(__dirname, 'public/index.html'),
30+
filename: 'index.html',
31+
}),
32+
],
33+
devServer: {
34+
contentBase: path.join(__dirname, 'dist'),
35+
compress: true,
36+
port: 3400,
37+
hot: true,
38+
watchContentBase: true,
39+
},
40+
};

webpack.config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const TerserPlugin = require('terser-webpack-plugin');
2+
const path = require('path');
3+
4+
module.exports = {
5+
entry: ['./src/index.js'],
6+
module: {
7+
rules: [
8+
{
9+
test: /\.js(x?)$/,
10+
use: {
11+
loader: 'babel-loader',
12+
options: {
13+
extends: './.babelrc',
14+
},
15+
},
16+
},
17+
],
18+
},
19+
optimization: {
20+
minimize: true,
21+
minimizer: [new TerserPlugin()],
22+
},
23+
output: {
24+
path: path.resolve(__dirname, 'dist'),
25+
filename: 'index.js',
26+
libraryTarget: 'commonjs2',
27+
},
28+
resolve: {
29+
extensions: ['.js', '.jsx'],
30+
},
31+
};

0 commit comments

Comments
 (0)