Skip to content

Commit ddd1229

Browse files
committed
webpack-app basic done
1 parent 54d4824 commit ddd1229

File tree

7 files changed

+87
-6
lines changed

7 files changed

+87
-6
lines changed

packages/webpack-app/.babelrc

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"presets": ["@babel/preset-env", "@babel/preset-react"],
3-
"plugins": [
4-
"@babel/plugin-syntax-dynamic-import",
5-
"@babel/plugin-proposal-class-properties"
6-
]
7-
}
2+
"presets": ["@babel/preset-env", "@babel/preset-react"],
3+
"plugins": [
4+
"@babel/plugin-syntax-dynamic-import",
5+
"@babel/plugin-proposal-class-properties"
6+
]
7+
}

packages/webpack-app/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"main": "index.js",
66
"license": "MIT",
77
"private": true,
8+
"scripts": {
9+
"start": "webpack-dev-server"
10+
},
811
"dependencies": {
912
"react": "^17.0.2",
1013
"react-dom": "^17.0.2"
3.78 KB
Binary file not shown.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
</link>
9+
<title>webpack-for-react</title>
10+
</head>
11+
12+
<body>
13+
<div id="root"></div>
14+
</body>
15+
16+
</html>

packages/webpack-app/src/App.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react'
2+
3+
const App = () => {
4+
return <div>Hello React and Webpack</div>
5+
}
6+
7+
export default App

packages/webpack-app/src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom'
3+
import App from './App'
4+
5+
ReactDOM.render(<App />, document.getElementById('root'))
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const webpack = require('webpack')
2+
const HtmlWebpackPlugin = require('html-webpack-plugin')
3+
4+
const port = process.env.PORT || 3000
5+
6+
module.exports = {
7+
mode: 'development',
8+
entry: './src/index.js',
9+
output: {
10+
filename: 'bundle.[hash].js',
11+
},
12+
devtool: 'inline-source-map',
13+
module: {
14+
rules: [
15+
{
16+
test: /\.(js)$/,
17+
exclude: /node_modules/,
18+
use: ['babel-loader'],
19+
},
20+
{
21+
test: /\.css$/,
22+
use: [
23+
{
24+
loader: 'style-loader',
25+
},
26+
{
27+
loader: 'css-loader',
28+
options: {
29+
modules: true,
30+
localsConvention: 'camelCase',
31+
sourceMap: true,
32+
},
33+
},
34+
],
35+
},
36+
],
37+
},
38+
plugins: [
39+
new HtmlWebpackPlugin({
40+
template: 'public/index.html',
41+
favicon: 'public/favicon.ico',
42+
}),
43+
],
44+
devServer: {
45+
host: 'localhost',
46+
port: port,
47+
historyApiFallback: true,
48+
open: true,
49+
},
50+
}

0 commit comments

Comments
 (0)