Skip to content
This repository was archived by the owner on Mar 22, 2025. It is now read-only.

Commit 8297bc2

Browse files
committed
Generic Configuration
1 parent 5c40c83 commit 8297bc2

File tree

7 files changed

+229
-0
lines changed

7 files changed

+229
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# IDE configuration
2+
.idea
3+
4+
# Build files
5+
/build
6+
/dist
7+
8+
# Node dependencies
9+
/node_modules

config/webpack.common.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
const paths = require('./paths');
2+
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
4+
5+
module.exports = {
6+
entry: {
7+
app: [paths.appIndex],
8+
},
9+
10+
// Extensions Webpack will resolve when files import other files
11+
resolve: {
12+
extensions: ['.tsx', '.ts', '.js'],
13+
plugins: [new TsconfigPathsPlugin({ configFile: paths.tsconfig })],
14+
},
15+
16+
output: {
17+
filename: '[name].[fullhash].js',
18+
},
19+
20+
module: {
21+
rules: [
22+
// Primary Typescript loader, loading .tsx or .ts
23+
{
24+
test: /\.tsx?$/,
25+
use: [
26+
{
27+
loader: 'babel-loader',
28+
options: {
29+
presets: ['@babel/env', '@babel/react'],
30+
},
31+
},
32+
'ts-loader',
33+
],
34+
exclude: "/node_modules/",
35+
},
36+
// MDX loader, loading .mdx
37+
{
38+
test: /\.mdx$/,
39+
use: [
40+
{
41+
loader: 'babel-loader',
42+
options: {
43+
presets: ['@babel/env', '@babel/react']
44+
}
45+
},
46+
{
47+
loader: '@mdx-js/loader',
48+
options: {
49+
providerImportSource: '@mdx-js/react'
50+
}
51+
}
52+
],
53+
exclude: "/node_modules/",
54+
},
55+
// Image and File resources from the site
56+
{
57+
test: /\.(jpg|pdf|png|pptx)$/,
58+
type: 'asset/resource',
59+
generator: {
60+
filename: 'assets/site/[name][ext]'
61+
},
62+
exclude: "/projects/",
63+
},
64+
// Image and File resources from projects
65+
{
66+
test: /\.(jpg|pdf|png|pptx)$/,
67+
type: 'asset/resource',
68+
generator: {
69+
filename: 'assets/projects/[path]/[name][ext]'
70+
},
71+
},
72+
],
73+
},
74+
75+
plugins: [
76+
new HtmlWebpackPlugin({
77+
// Configuration: https://github.com/jantimon/html-webpack-plugin
78+
template: paths.appIndexTemplate,
79+
// base: Not needed, due to publicPath defined in output
80+
// publicPath: Not needed, due to publicPath defined in output
81+
}),
82+
],
83+
};

config/webpack.dev.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const paths = require('./paths');
2+
const webpack = require('webpack');
3+
4+
const { merge } = require('webpack-merge');
5+
const common = require('./webpack.common.js');
6+
7+
module.exports = merge(common, {
8+
mode: 'development',
9+
devtool: 'inline-source-map',
10+
11+
entry: {
12+
app: ['webpack-hot-middleware/client'],
13+
},
14+
15+
output: {
16+
path: paths.appBuildDev,
17+
publicPath: paths.publicPathDev,
18+
},
19+
20+
plugins: [
21+
new webpack.DefinePlugin({
22+
// Quotes around strings for compile-time text substitution
23+
__PUBLICPATH__: "'" + paths.publicPathDev + "'",
24+
}),
25+
// Hot loading
26+
new webpack.HotModuleReplacementPlugin(),
27+
],
28+
});

config/webpack.prod.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const paths = require('./paths');
2+
const webpack = require('webpack');
3+
4+
const { merge } = require('webpack-merge');
5+
const common = require('./webpack.common.js');
6+
7+
module.exports = merge(common, {
8+
mode: 'production',
9+
devtool: 'source-map',
10+
11+
// Disable minification for easier debugging
12+
optimization: {
13+
minimize: false,
14+
},
15+
16+
output: {
17+
path: paths.appBuildProd,
18+
publicPath: paths.publicPathProd,
19+
},
20+
21+
plugins: [
22+
new webpack.DefinePlugin({
23+
// Quotes around strings for compile-time text substitution
24+
__PUBLICPATH__: "'" + paths.publicPathProd + "'",
25+
}),
26+
],
27+
});

scripts/dev_serve.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const express = require('express');
2+
const rimraf = require('rimraf');
3+
const webpack = require('webpack');
4+
const webpackDevMiddleware = require('webpack-dev-middleware');
5+
const webpackHotMiddleware = require('webpack-hot-middleware');
6+
7+
const path = require('path');
8+
const paths = require('../config/paths');
9+
const webpackConfig = require(paths.webpackConfigDev);
10+
11+
console.log(`Starting debug build with hot reloading.`);
12+
13+
const app = express();
14+
const compiler = webpack(webpackConfig);
15+
16+
rimraf.sync(paths.appBuildDev);
17+
18+
app.use(
19+
webpackDevMiddleware(compiler, {
20+
publicPath: webpackConfig.output.publicPath,
21+
writeToDisk: true,
22+
})
23+
);
24+
25+
app.use(webpackHotMiddleware(compiler));
26+
27+
// All queries redirect to home, then app handles routing
28+
app.get('/*', function (req, res) {
29+
res.sendFile(path.join(paths.appBuildDev, 'index.html'));
30+
});
31+
32+
port = 3000;
33+
host = '127.0.0.1'
34+
server = app.listen(port, host);
35+
server.on('listening', function () {
36+
console.log(`Listening on http://${server.address().address}:${server.address().port}/`);
37+
});

scripts/prod_build.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const rimraf = require('rimraf');
2+
const webpack = require('webpack');
3+
const paths = require('../config/paths');
4+
const webpackConfig = require(paths.webpackConfigProd);
5+
6+
console.log(`Building production in ${paths.appBuildProd}.`);
7+
8+
rimraf.sync(paths.appBuildProd);
9+
10+
const compiler = webpack(webpackConfig);
11+
compiler.run();

tsconfig.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"experimentalDecorators": true,
5+
"importHelpers": true,
6+
"jsx": "react",
7+
"lib": ["es6", "dom"],
8+
"module": "commonjs",
9+
"noImplicitAny": true,
10+
"noImplicitThis": true,
11+
"noUnusedLocals": true,
12+
"noUnusedParameters": true,
13+
"paths": {
14+
"src/*": ["src/*"]
15+
},
16+
"preserveConstEnums": true,
17+
"removeComments": true,
18+
"sourceMap": true,
19+
"strictNullChecks": true,
20+
"target": "es6"
21+
},
22+
"include": [
23+
"src/client/**/*",
24+
"src/common/**/*",
25+
"src/components/**/*",
26+
"src/content/**/*",
27+
"src/pages/**/*",
28+
"src/stores/**/*",
29+
"src/types/**/*"
30+
],
31+
"exclude": [
32+
"node_modules"
33+
]
34+
}

0 commit comments

Comments
 (0)