Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 321b512

Browse files
authored
Merge pull request #1261 from bjones1/cache
Cache webpack files
2 parents 9d26906 + ba43a20 commit 321b512

2 files changed

Lines changed: 37 additions & 26 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Python package
55

66
on:
77
push:
8-
branches: [master]
8+
branches: [master, bookserver]
99
pull_request:
10-
branches: [master]
10+
branches: [master, bookserver]
1111

1212
jobs:
1313
build:

webpack.config.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,26 @@
88

99
const path = require("path");
1010

11-
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
12-
const CopyPlugin = require('copy-webpack-plugin');
13-
const HtmlWebpackPlugin = require('html-webpack-plugin');
14-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
11+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
12+
const CopyPlugin = require("copy-webpack-plugin");
13+
const HtmlWebpackPlugin = require("html-webpack-plugin");
14+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
1515

1616
module.exports = (env, argv) => {
17+
const is_dev_mode = argv.mode === "development";
18+
1719
return {
20+
// Cache build results between builds in development mode, per the `docs <https://webpack.js.org/configuration/cache/>`__.
21+
cache: is_dev_mode
22+
? {
23+
type: "filesystem",
24+
}
25+
: false,
1826
entry: {
1927
runestone: "./webpack.index.js",
2028
},
2129
// See `mode <https://webpack.js.org/configuration/mode/>`_ for the conditional statement below.
22-
devtool: argv.mode === "development" ? "inline-source-map" : "source-map",
30+
devtool: is_dev_mode ? "inline-source-map" : "source-map",
2331
module: {
2432
rules: [
2533
{
@@ -36,10 +44,10 @@ module.exports = (env, argv) => {
3644
resolve: {
3745
fallback: {
3846
// ``sql.js`` wants these in case it's running under node.js. They're not needed by JS in the browser.
39-
"crypto": false,
40-
"fs": false,
41-
"path": false
42-
}
47+
crypto: false,
48+
fs: false,
49+
path: false,
50+
},
4351
},
4452
externals: {
4553
// Use the jQuery that Sphinx provides for jQuery.ui. See `externals <https://webpack.js.org/configuration/externals/>`_.
@@ -54,11 +62,11 @@ module.exports = (env, argv) => {
5462
},
5563
// See https://webpack.js.org/guides/code-splitting/#splitchunksplugin.
5664
optimization: {
57-
moduleIds: 'deterministic',
65+
moduleIds: "deterministic",
5866
// Collect all the webpack import runtime into a single file, which is named ``runtime.bundle.js``. This must be statically imported by all pages containing Runestone components.
59-
runtimeChunk: 'single',
67+
runtimeChunk: "single",
6068
splitChunks: {
61-
chunks: 'all',
69+
chunks: "all",
6270
},
6371
// CSS for production was copied from https://webpack.js.org/plugins/mini-css-extract-plugin/#minimizing-for-production.
6472
minimizer: [
@@ -70,25 +78,28 @@ module.exports = (env, argv) => {
7078
plugins: [
7179
// _`webpack_static_imports`: Instead of HTML, produce a list of static imports as JSON. Sphinx will then read this file and inject these imports when creating each page.
7280
new HtmlWebpackPlugin({
73-
filename: 'webpack_static_imports.json',
81+
filename: "webpack_static_imports.json",
7482
// Don't prepend the ``<head>`` tag and data to the output.
7583
inject: false,
7684
// The template to create JSON.
77-
templateContent: ({ htmlWebpackPlugin }) => JSON.stringify({
78-
js: htmlWebpackPlugin.files.js,
79-
css: htmlWebpackPlugin.files.css,
80-
}),
85+
templateContent: ({ htmlWebpackPlugin }) =>
86+
JSON.stringify({
87+
js: htmlWebpackPlugin.files.js,
88+
css: htmlWebpackPlugin.files.css,
89+
}),
8190
}),
8291
new CopyPlugin({
83-
patterns: [{
84-
// sql.js support: this wasm file will be fetched dynamically when we initialize sql.js. It is important that we do not change its name, and that it is in the same folder as the js.
85-
from: 'node_modules/sql.js/dist/sql-wasm.wasm',
86-
to: '.'
87-
}],
92+
patterns: [
93+
{
94+
// sql.js support: this wasm file will be fetched dynamically when we initialize sql.js. It is important that we do not change its name, and that it is in the same folder as the js.
95+
from: "node_modules/sql.js/dist/sql-wasm.wasm",
96+
to: ".",
97+
},
98+
],
8899
}),
89100
new MiniCssExtractPlugin({
90-
filename: '[name].css?v=[contenthash]',
91-
chunkFilename: '[id].css',
101+
filename: "[name].css?v=[contenthash]",
102+
chunkFilename: "[id].css",
92103
}),
93104
],
94105
};

0 commit comments

Comments
 (0)