Problem
The "sass" bundle contains a module, sass.dart.js: https://runpkg.com/?sass@1.21.0/sass.dart.js
Amongst other things, this contains dynamic usage of require (many lines redacted):
var self = Object.create(global);
self.require = require;
//...
u($,"N0","Hq",function(){return self.require("readline")})
u($,"Mr","cN",function(){return self.require("fs")})
u($,"MN","Ho",function(){return self.require("chokidar")})
This use of require prevents static analysis by webpack, resulting in the error in the output (also in this gist) and a webpackEmptyContext being created in the bundle. This naturally doesn't work :)
Options Tried
I've seen the ContextReplacementPlugin, I don't think this applies here as the usage is not a direct require call.
I've seen noParse, but that feels like the nuclear approach, and I don't know what the potential negative side effects may be.
Reproduction code
Also in this gist
index.js:
const sass = require("sass");
console.log(sass);
webpack.config.js:
module.exports = (env) => ({
entry: "./index.js",
mode: "development",
target: "node"
});
package.json:
{
"devDependencies": {
"webpack": "^4.34.0",
"webpack-cli": "^3.3.4"
},
"dependencies": {
"sass": "^1.21.0"
},
"scripts": {
"build": "webpack-cli"
}
}
Goal
How can I configure the context for this particular module to specifically list readline/fs/chokidar as dependencies, possibly to produce some context that only provides those values?
I don't mind if the solution is a little brittle and would require pinning of the version of dart-sass.