Skip to content

Commit 5d676da

Browse files
authored
Update webpack configuration (#1332)
Separate webpack asset compilation from running the server. In development, this now requires running yarn watch to run webpack in watch mode; in production, yarn build will build the assets for production. Other changes: - Remove webpack-dev-server dependency since we weren't using it - Remove the few remaining external CDN dependencies for CSS files (bootstrap and leaflet), instead bundling them using webpack.
1 parent c2ab526 commit 5d676da

File tree

145 files changed

+249
-2559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+249
-2559
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"@babel/preset-env",
55
{
66
"useBuiltIns": "usage",
7-
"corejs": 3
7+
"corejs": { "version": "3.30", "proposals": true }
88
}
99
],
1010
"@babel/preset-react"

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ cabal.sandbox.config
5252
/public/js/generate/app.js
5353
/public/js/graph/app.js
5454
/public/js/draw/app.js
55+
/public/*.svg
56+
/public/*.png
57+
/public/*.ttf
58+
/public/*.eot
59+
/public/*.woff
60+
/public/*.png
61+
/public/*.woff2
5562

5663
# coverage directory used by tools like istanbul and jest --coverage
5764
coverage

.pnp.cjs

+77-1,344
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

README.md

+5-3

app/DevelopmentConfig.hs

+1-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ module Config (
2222
winterStartDate,
2323
winterEndDate,
2424
outDay,
25-
holidays,
26-
enableCdn
25+
holidays
2726
) where
2827

2928
import Data.Text (Text)
@@ -122,9 +121,3 @@ holidays = ["20221010T", "20221107T", "20221108T",
122121
"20221109T", "20221110T", "20221111T",
123122
"20230220T", "20230221T", "20230222T",
124123
"20200223T", "20230224T"]
125-
126-
-- SCRIPT DEPENDENCIES CONFIGURATION
127-
128-
-- | Enable CDN downloads for js and css dependencies. Should be true on the production server.
129-
enableCdn :: Bool
130-
enableCdn = True

app/Main.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import System.IO (hPutStrLn, stderr)
1717

1818
-- internal dependencies
1919
import Database.Database (setupDatabase)
20-
import Server (runServer, webpackProcess, webpackProductionProcess)
20+
import Server (runServer)
2121
import Svg.Parser (parsePrebuiltSvgs)
2222
import Util.Documentation (generateDocs)
2323

@@ -27,8 +27,7 @@ import DynamicGraphs.WriteRunDot (generatePrereqsForCourses)
2727
-- | A map of command-line arguments to their corresponding IO actions.
2828
taskMap :: Map.Map String ([String] -> IO ())
2929
taskMap = Map.fromList [
30-
("server", const $ runServer webpackProcess),
31-
("prod-server", const $ runServer webpackProductionProcess),
30+
("server", const runServer),
3231
("database", const setupDatabase),
3332
("graphs", const parsePrebuiltSvgs),
3433
("docs", const generateDocs),

app/MasterTemplate.hs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module MasterTemplate
22
(masterTemplate, header) where
33

4-
import Config (enableCdn)
54
import qualified Data.Text as T
65
import Text.Blaze ((!))
76
import qualified Text.Blaze.Html5 as H
@@ -19,13 +18,8 @@ masterTemplate title headers body scripts =
1918
H.title (H.toHtml title)
2019
H.link ! A.rel "icon" ! A.type_ "image/png"
2120
! A.href "/static/res/ico/favicon.png"
22-
H.link ! A.rel "stylesheet" ! A.href "https://unpkg.com/[email protected]/dist/leaflet.css"
2321
sequence_ headers
24-
mapM_ toStylesheet [
25-
if enableCdn
26-
then "//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"
27-
else "/static/style/bootstrap.min.3.1.1.css",
28-
"/static/style/app.css"]
22+
toStylesheet "/static/style/app.css"
2923
H.body $ do
3024
body
3125
scripts

app/Response/NotFound.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ notFoundResponse =
1515
H.title "Courseography - 404!"
1616
H.meta ! A.httpEquiv "Content-Type"
1717
! A.content "text/html;charset=utf-8"
18-
mapM_ toStylesheet [
19-
"//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css",
20-
"/static/style/app.css"]
18+
toStylesheet "/static/style/app.css"
2119

2220
H.body notFoundContent
2321

app/Server.hs

+3-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It also defines all of the allowed server routes, and the corresponding
77
responses.
88
-}
99
module Server
10-
(runServer, webpackProcess, webpackProductionProcess) where
10+
(runServer) where
1111

1212
import Config (markdownPath, serverConf)
1313
import Control.Concurrent (forkIO, killThread)
@@ -19,17 +19,10 @@ import Routes (routeResponses)
1919
import System.Directory (getCurrentDirectory)
2020
import System.IO (BufferMode (LineBuffering), hSetBuffering, stderr, stdout)
2121
import System.Log.Logger (Priority (INFO), rootLoggerName, setLevel, updateGlobalLogger)
22-
import System.Process (CreateProcess, createProcess, shell)
2322

24-
webpackProcess :: CreateProcess
25-
webpackProcess = shell "yarn run watch"
2623

27-
webpackProductionProcess :: CreateProcess
28-
webpackProductionProcess = shell "yarn run build"
29-
30-
runServer :: CreateProcess -> IO ()
31-
runServer buildProcess = do
32-
_ <- createProcess buildProcess
24+
runServer :: IO ()
25+
runServer = do
3326
configureLogger
3427
staticDir <- getStaticDir
3528
aboutContents <- LazyIO.readFile $ markdownPath ++ "README.md"

js/components/draw/main.js

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import "core-js/stable"
2-
import "regenerator-runtime/runtime"
3-
41
import React from "react"
52
import ReactDOM from "react-dom"
63
import { Graph } from "../graph/Graph"

js/components/generate/generate.js

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import "core-js/stable"
2-
import "regenerator-runtime/runtime"
3-
41
import React from "react"
52
import ReactDOM from "react-dom"
63

js/components/graph/Graph.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "ag-grid-community/styles/ag-grid.css"
2-
import "ag-grid-community/styles/ag-theme-alpine.css"
31
import React from "react"
42
import PropTypes from "prop-types"
53
import { CourseModal } from "../common/react_modal.js.jsx"

js/components/graph/main.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "core-js/stable"
2-
import "regenerator-runtime/runtime"
31
import React from "react"
42
import ReactDOM from "react-dom"
53
import Container from "./Container"

js/components/grid/grid.js.jsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "core-js/stable"
2-
import "regenerator-runtime/runtime"
31
import React from "react"
42
import ReactDOM from "react-dom"
53

js/components/post/post.js.jsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import "core-js/stable"
2-
import "regenerator-runtime/runtime"
3-
41
import { SpecialistPost, MajorPost, MinorPost } from "./post_components.js.jsx"
52

63
import React from "react"

js/components/search/search.js.jsx

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "core-js/stable"
2-
import "regenerator-runtime/runtime"
31
import React from "react"
42
import ReactDOM from "react-dom"
53

package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"license": "GPL-3.0",
77
"scripts": {
88
"start": "stack exec courseography",
9-
"watch": "webpack --watch",
10-
"build": "webpack --mode production",
9+
"watch": "webpack --watch --config webpack.dev.js",
10+
"build": "webpack --config webpack.prod.js",
1111
"test": "jest",
1212
"prettier": "prettier --write .",
1313
"eslint": "eslint --fix-dry-run --ignore-path .prettierignore js"
@@ -17,8 +17,10 @@
1717
"*": "prettier --ignore-unknown --write"
1818
},
1919
"dependencies": {
20+
"@babel/runtime": "^7.21.0",
2021
"ag-grid-community": "^29.3.2",
2122
"ag-grid-react": "^29.3.2",
23+
"bootstrap": "^3.1.1",
2224
"core-js": "^3.30.1",
2325
"handlebars": "^4.7.7",
2426
"jquery": "^3.6.0",
@@ -27,9 +29,7 @@
2729
"react": "^17.0.2",
2830
"react-dom": "^17.0.2",
2931
"react-leaflet": "^3.2.5",
30-
"react-modal": "^3.16.1",
31-
"regenerator-runtime": "^0.13.7",
32-
"webpack": "^5.76.3"
32+
"react-modal": "^3.16.1"
3333
},
3434
"devDependencies": {
3535
"@babel/core": "^7.21.3",
@@ -62,8 +62,9 @@
6262
"style-loader": "^3.3.2",
6363
"stylelint": "^15.3.0",
6464
"stylelint-config-sass-guidelines": "^10.0.0",
65-
"webpack-cli": "^5.0.1",
66-
"webpack-dev-server": "^4.13.1"
65+
"webpack": "^5.81.0",
66+
"webpack-cli": "^5.0.2",
67+
"webpack-merge": "^5.8.0"
6768
},
6869
"packageManager": "[email protected]"
6970
}

style/app.scss

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ $graph-overlay-top-margin: 15px;
22
$graph-overlay-side-margin: 15px;
33
@import "ag-grid-community/styles/ag-grid.css";
44
@import "ag-grid-community/styles/ag-theme-alpine.css";
5+
@import "leaflet/dist/leaflet.css";
6+
@import "bootstrap/dist/css/bootstrap.min.css";
57

68
@keyframes spin {
79
0.0% {

webpack.common.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const path = require("path")
2+
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
3+
const webpack = require("webpack")
4+
5+
const presets = [
6+
["@babel/preset-env", { useBuiltIns: "usage", corejs: 3 }],
7+
["@babel/preset-react"],
8+
]
9+
10+
const isDevelopment = process.env.NODE_ENV !== "production"
11+
12+
module.exports = {
13+
mode: isDevelopment ? "development" : "production",
14+
entry: {
15+
"js/search/app": "./js/components/search/search.js.jsx",
16+
"js/grid/app": "./js/components/grid/grid.js.jsx",
17+
"js/graph/app": "./js/components/graph/main.js",
18+
"js/post/app": "./js/components/post/post.js.jsx",
19+
"js/draw/app": "./js/components/draw/main.js",
20+
"js/generate/app": "./js/components/generate/generate.js",
21+
"style/app": "./style/app.js",
22+
},
23+
output: {
24+
path: path.resolve(__dirname, "public"),
25+
publicPath: "./public",
26+
filename: "[name].js",
27+
},
28+
module: {
29+
rules: [
30+
{
31+
test: /\.js$/,
32+
use: {
33+
loader: "babel-loader",
34+
options: { presets },
35+
},
36+
exclude: /node_modules/,
37+
},
38+
{
39+
test: /\.jsx$/,
40+
use: {
41+
loader: "babel-loader",
42+
options: { presets },
43+
},
44+
exclude: /node_modules/,
45+
},
46+
{
47+
test: /\.css$/i,
48+
use: [MiniCssExtractPlugin.loader, "css-loader"],
49+
},
50+
{
51+
test: /\.s[ac]ss$/i,
52+
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
53+
},
54+
],
55+
},
56+
plugins: [
57+
new MiniCssExtractPlugin({
58+
// Options similar to the same options in webpackOptions.output
59+
// both options are optional
60+
filename: "[name].css",
61+
chunkFilename: "[id].css",
62+
}),
63+
new webpack.ProvidePlugin({
64+
$: "jquery",
65+
jQuery: "jquery",
66+
}),
67+
],
68+
}

webpack.dev.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { merge } = require("webpack-merge")
2+
const common = require("./webpack.common.js")
3+
4+
module.exports = merge(common, {
5+
mode: "development",
6+
devtool: "inline-source-map",
7+
})

webpack.prod.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { merge } = require("webpack-merge")
2+
const common = require("./webpack.common.js")
3+
4+
module.exports = merge(common, {
5+
mode: "production",
6+
devtool: "source-map",
7+
})

0 commit comments

Comments
 (0)