Skip to content

Commit 98a972c

Browse files
committed
1 parent 135b2a6 commit 98a972c

File tree

3 files changed

+245
-3
lines changed

3 files changed

+245
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dependencies": {
66
"react": "^16.7.0",
77
"react-dom": "^16.7.0",
8+
"react-syntax-highlighter": "^10.1.2",
89
"styled-components": "^4.1.3"
910
},
1011
"scripts": {

src/index.js

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,74 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import styled from 'styled-components';
44

5+
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
6+
import js from 'react-syntax-highlighter/dist/languages/hljs/javascript';
7+
import railscasts from 'react-syntax-highlighter/dist/styles/hljs/railscasts';
8+
9+
SyntaxHighlighter.registerLanguage('javascript', js);
10+
511
const Title = styled.h1`
612
font-family: sans-serif;
713
padding: 2em;
814
background: papayawhip;
9-
font-size: 4em;
15+
font-size: 2em;
1016
text-align: center;
1117
color: palevioletred;
1218
margin: 0;
1319
`;
1420

21+
const codeString = `
22+
module.exports = {
23+
devtool: 'inline-source-map',
24+
entry: './src/index.js',
25+
output: {
26+
path: path.join(__dirname, '/build'),
27+
publicPath: '/',
28+
filename: 'bundle.js'
29+
},
30+
optimization: {
31+
splitChunks: {
32+
chunks: 'all'
33+
}
34+
},
35+
devServer: {
36+
contentBase: './build'
37+
},
38+
module: {
39+
rules: [
40+
{
41+
test: /\.(js|jsx)$/,
42+
exclude: /node_modules/,
43+
use: ['babel-loader', 'eslint-loader']
44+
}
45+
]
46+
},
47+
plugins: [
48+
new HtmlWebpackPlugin({
49+
template: path.resolve('./index.html')
50+
}),
51+
new BundleAnalyzerPlugin({
52+
analyzerMode: 'disabled',
53+
generateStatsFile: true,
54+
statsOptions: { source: false },
55+
statsFilename: path.join(__dirname, 'stats/stats.json')
56+
})
57+
],
58+
performance: { hints: false }
59+
};
60+
61+
`;
62+
1563
class Welcome extends React.Component {
1664
render() {
17-
return <Title>Hello World</Title>;
65+
return (
66+
<React.Fragment>
67+
<Title>JavaScript</Title>
68+
<SyntaxHighlighter language="javascript" style={railscasts} customStyle={{ fontSize: '1.25rem' }}>
69+
{codeString}
70+
</SyntaxHighlighter>
71+
</React.Fragment>
72+
);
1873
}
1974
}
2075

0 commit comments

Comments
 (0)