Skip to content

Commit c699c1b

Browse files
committed
webpack => rspack
1 parent ae43778 commit c699c1b

File tree

5 files changed

+34
-41
lines changed

5 files changed

+34
-41
lines changed

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ include README.md
33
include requirements.txt
44
include npm_mjs/package.json5
55
include npm_mjs/templates/npm_mjs/static_urls_js.html
6-
include npm_mjs/management/commands/webpack.config.template.js
6+
include npm_mjs/management/commands/rspack.config.template.js

npm_mjs/management/commands/npm_install.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def install_npm(force, stdout, post_npm_signal=True):
2222
change_times.append(os.path.getmtime(path))
2323
settings_change = max(change_times)
2424
package_path = os.path.join(TRANSPILE_CACHE_PATH, "package.json")
25-
webpack_bin_path = os.path.join(TRANSPILE_CACHE_PATH, "node_modules/.bin/webpack")
26-
if os.path.exists(package_path) and os.path.exists(webpack_bin_path):
25+
rspack_bin_path = os.path.join(TRANSPILE_CACHE_PATH, "node_modules/.bin/rspack")
26+
if os.path.exists(package_path) and os.path.exists(rspack_bin_path):
2727
package_change = os.path.getmtime(package_path)
2828
else:
2929
package_change = -1
@@ -36,6 +36,13 @@ def install_npm(force, stdout, post_npm_signal=True):
3636
os.path.getmtime(app_package_path),
3737
app_package_change,
3838
)
39+
else:
40+
app_package_path = os.path.join(config.path, "package.json5")
41+
if os.path.exists(app_package_path):
42+
app_package_change = max(
43+
os.path.getmtime(app_package_path),
44+
app_package_change,
45+
)
3946
npm_install = False
4047
if (
4148
settings_change > get_last_run("npm_install")
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1-
const webpack = require("webpack") // eslint-disable-line no-undef
1+
const rspack = require('@rspack/core') // eslint-disable-line no-undef
22

33
const settings = window.settings // Replaced by django-npm-mjs
44
const transpile = window.transpile // Replaced by django-npm-mjs
55

6-
const baseRule = {
7-
test: /\.(js|mjs)$/,
8-
use: {
9-
loader: "babel-loader",
10-
options: {
11-
presets: ["@babel/preset-env"]
12-
}
13-
}
14-
}
15-
166

177
const predefinedVariables = {
188
transpile_VERSION: transpile.VERSION
199
}
2010

2111
if (settings.DEBUG) {
22-
baseRule.exclude = /node_modules/
12+
//baseRule.exclude = /node_modules/
2313
predefinedVariables.staticUrl = `(url => ${JSON.stringify(
2414
settings.STATIC_URL
2515
)} + url)`
@@ -35,14 +25,14 @@ if (settings.DEBUG) {
3525
module.exports = {
3626
// eslint-disable-line no-undef
3727
mode: settings.DEBUG ? "development" : "production",
38-
module: {
39-
rules: [baseRule]
40-
},
28+
// module: {
29+
// rules: [] // [baseRule]
30+
// },
4131
output: {
4232
path: transpile.OUT_DIR,
4333
chunkFilename: transpile.VERSION + "-[id].js",
4434
publicPath: transpile.BASE_URL
4535
},
46-
plugins: [new webpack.DefinePlugin(predefinedVariables)],
36+
plugins: [new rspack.DefinePlugin(predefinedVariables)],
4737
entry: transpile.ENTRIES
4838
}

npm_mjs/management/commands/transpile.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
# Run this script every time you update an *.mjs file or any of the
2424
# modules it loads.
2525

26-
OLD_WEBPACK_CONFIG_JS = ""
26+
OLD_RSPACK_CONFIG_JS = ""
2727

28-
WEBPACK_CONFIG_JS_PATH = os.path.join(TRANSPILE_CACHE_PATH, "webpack.config.js")
28+
RSPACK_CONFIG_JS_PATH = os.path.join(TRANSPILE_CACHE_PATH, "rspack.config.js")
2929

3030
try:
31-
with open(WEBPACK_CONFIG_JS_PATH) as file:
32-
OLD_WEBPACK_CONFIG_JS = file.read()
31+
with open(RSPACK_CONFIG_JS_PATH) as file:
32+
OLD_RSPACK_CONFIG_JS = file.read()
3333
except OSError:
3434
pass
3535

@@ -199,14 +199,14 @@ def handle(self, *args, **options):
199199
static_base_url = PrefixNode.handle_simple("STATIC_URL")
200200
transpile_base_url = urljoin(static_base_url, "js/")
201201
if (
202-
hasattr(settings, "WEBPACK_CONFIG_TEMPLATE")
203-
and settings.WEBPACK_CONFIG_TEMPLATE
202+
hasattr(settings, "RSPACK_CONFIG_TEMPLATE")
203+
and settings.RSPACK_CONFIG_TEMPLATE
204204
):
205-
webpack_config_template_path = settings.WEBPACK_CONFIG_TEMPLATE
205+
rspack_config_template_path = settings.RSPACK_CONFIG_TEMPLATE
206206
else:
207-
webpack_config_template_path = os.path.join(
207+
rspack_config_template_path = os.path.join(
208208
os.path.dirname(os.path.realpath(__file__)),
209-
"webpack.config.template.js",
209+
"rspack.config.template.js",
210210
)
211211
entries = {}
212212
for mainfile in mainfiles:
@@ -242,8 +242,8 @@ def handle(self, *args, **options):
242242
urljoin(static_base_url, x) for x in static_frontend_files
243243
],
244244
}
245-
with open(webpack_config_template_path) as f:
246-
webpack_config_template = f.read()
245+
with open(rspack_config_template_path) as f:
246+
rspack_config_template = f.read()
247247
settings_dict = {}
248248
for var in dir(settings):
249249
if var in ["DATABASES", "SECRET_KEY"]:
@@ -253,15 +253,15 @@ def handle(self, *args, **options):
253253
settings_dict[var] = getattr(settings, var)
254254
except AttributeError:
255255
pass
256-
webpack_config_js = webpack_config_template.replace(
256+
rspack_config_js = rspack_config_template.replace(
257257
"window.transpile",
258258
json.dumps(transpile),
259259
).replace("window.settings", json.dumps(settings_dict, default=lambda x: False))
260260

261-
if webpack_config_js is not OLD_WEBPACK_CONFIG_JS:
262-
with open(WEBPACK_CONFIG_JS_PATH, "w") as f:
263-
f.write(webpack_config_js)
264-
call(["./node_modules/.bin/webpack"], cwd=TRANSPILE_CACHE_PATH)
261+
if rspack_config_js is not OLD_RSPACK_CONFIG_JS:
262+
with open(RSPACK_CONFIG_JS_PATH, "w") as f:
263+
f.write(rspack_config_js)
264+
call(["./node_modules/.bin/rspack"], cwd=TRANSPILE_CACHE_PATH)
265265
end = int(round(time.time()))
266266
self.stdout.write("Time spent transpiling: " + str(end - start) + " seconds")
267267
signals.post_transpile.send(sender=None)

npm_mjs/package.json5

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
description: "Install dependencies for ES6 transpilation",
66
private: true,
77
dependencies: {
8-
"@babel/preset-env": "^7.24.6",
9-
"@babel/core": "^7.24.6",
10-
"@babel/cli": "^7.24.6",
11-
"babel-loader": "9.1.3",
12-
webpack: "5.91.0",
13-
"webpack-cli": "5.1.4",
8+
"@rspack/core": "1.0.5",
9+
"@rspack/cli": "1.0.5"
1410
},
1511
}

0 commit comments

Comments
 (0)