Skip to content

Commit

Permalink
feat: setting up webpack (#4)
Browse files Browse the repository at this point in the history
* feat: first pass at setting up webpack

* chore: adding support for dev-server

* chore: prettier linting

Co-authored-by: Gabe Ratcliff <[email protected]>
  • Loading branch information
erunion and Gabe Ratcliff authored Sep 1, 2020
1 parent c42575d commit fa651fc
Show file tree
Hide file tree
Showing 8 changed files with 5,536 additions and 255 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
node_modules/
coverage/
5,693 changes: 5,440 additions & 253 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"pretest": "npm run lint && npm run prettier && npm run inspect",
"prettier": "prettier --list-different --write \"./**/**.{js,jsx}\"",
"test": "jest --coverage --runInBand",
"version": "conventional-changelog -i CHANGELOG.md -s && git add CHANGELOG.md"
"version": "conventional-changelog -i CHANGELOG.md -s && git add CHANGELOG.md",
"build": "webpack --config ./webpack.config.js",
"start": "webpack-dev-server --open --config ./webpack.config.dev.js",
"watch": "webpack -w --progress"
},
"license": "ISC",
"repository": "https://github.com/readmeio/syntax-highlighter",
Expand All @@ -26,16 +29,22 @@
"@commitlint/config-conventional": "^9.1.2",
"@readme/eslint-config": "^3.2.0",
"babel-jest": "^26.3.0",
"babel-loader": "^8.1.0",
"babel-polyfill": "^6.26.0",
"conventional-changelog-cli": "^2.1.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.4",
"eslint": "^7.0.0",
"glob": "^7.1.6",
"html-webpack-plugin": "^4.4.1",
"husky": "^4.2.5",
"jest": "^26.0.1",
"jsinspect": "^0.12.6",
"prettier": "^2.0.1"
"prettier": "^2.0.1",
"terser-webpack-plugin": "^4.1.0",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
},
"prettier": "@readme/eslint-config/prettier",
"husky": {
Expand Down
Binary file added public/favicon.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<head>
<meta charset="UTF-8">
<title>Syntax Highlighter</title>
<link rel="icon" type="image/png" href="./favicon.ico"/>
</head>
<div id="root" />
7 changes: 7 additions & 0 deletions public/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ReactDOM from 'react-dom';
import syntaxHighlighter from '../src/index';

ReactDOM.render(
syntaxHighlighter('console.log("Hello, world!");', 'js', { dark: true }),
document.getElementById('root')
);
40 changes: 40 additions & 0 deletions webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const HtmlWebPackPlugin = require('html-webpack-plugin');
const path = require('path');

module.exports = {
entry: ['./public/index.js'],
module: {
rules: [
{
test: /\.js(x?)$/,
use: {
loader: 'babel-loader',
options: {
extends: './.babelrc',
},
},
},
],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js',
publicPath: '/',
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
new HtmlWebPackPlugin({
template: path.resolve(__dirname, 'public/index.html'),
filename: 'index.html',
}),
],
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 3400,
hot: true,
watchContentBase: true,
},
};
31 changes: 31 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');

module.exports = {
entry: ['./src/index.js'],
module: {
rules: [
{
test: /\.js(x?)$/,
use: {
loader: 'babel-loader',
options: {
extends: './.babelrc',
},
},
},
],
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js',
libraryTarget: 'commonjs2',
},
resolve: {
extensions: ['.js', '.jsx'],
},
};

0 comments on commit fa651fc

Please sign in to comment.