ericclemmons / ericclemmons/terse-webpack

Server externals are complicated. Abstract away with features?

Open
#29 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
213
Forks
10
PR merge metrics
No merged PRs in 30d

Description

To summarize:
- Short-circuit anything in `node_modules`
- Skip relative paths or non-valid names (e.g. `webpack/hot/poll?1000`)
- Folder or file (`.js`) has to exist in `node_modules`

This solves any problems with server-side `externals` and `alias`.

``` diff
diff --git a/webpack.config.test.js b/webpack.config.test.js
index 87af92b..094abbb 100644
--- a/webpack.config.test.js
+++ b/webpack.config.test.js
@@ -1,3 +1,17 @@
+/* eslint-disable no-var */
+var fs = require("fs");
+var path = require("path");
+
+function nodeModuleExists(request) {
+ try {
+ fs.accessSync(path.resolve(process.cwd(), "node_modules", request));
+ } catch (e) {
+ return false;
+ }
+
+ return true;
+}
+
module.exports = require("./webpack.config.defaults")
.externals(
/^@?\w[a-z\-0-9\./]+$/,
@@ -6,7 +20,24 @@ module.exports = require("./webpack.config.defaults")
"react/lib/ReactContext"
)
.loader("babel", ".js", {
- exclude: /node_modules/,
+ function(context, request, callback) {
+ if (
+ /node_modules/.test(context)
+ || (
+ /^@?\w[a-z\-0-9\./]+$/.test(request)
+ &&
+ (
+ nodeModuleExists(request)
+ ||
+ nodeModuleExists(`${request}.js`)
+ )
+ )
+ ) {
+ return callback(null, `commonjs ${request}`);
+ }
+
+ callback();
+ },
query: { cacheDirectory: true },
})
.loader("null", ".css")
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with webpack.config.test.js and the existing externals and loader configuration. Check how server-side externals and aliases are currently handled, then compare the proposed node_modules checks and request filtering against the stated requirements. Done means those cases are abstracted into the project’s configuration without breaking valid module resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.