@@ -58,9 +58,10 @@
});
};
const context = compiler.context;
+ if (localOptions.__filename) {
if (localOptions.__filename === "mock") {
setConstant("__filename", "/index.js");
- } else if (localOptions.__filename) {
+ } else {
setModuleConstant("__filename", module =>
path.relative(context, module.resource)
);
@@ -75,9 +76,11 @@
i < 0 ? resource : resource.substr(0, i)
)(expr);
});
+ }
+ if (localOptions.__dirname) {
if (localOptions.__dirname === "mock") {
setConstant("__dirname", "/");
- } else if (localOptions.__dirname) {
+ } else {
setModuleConstant("__dirname", module =>
path.relative(context, module.context)
);
@@ -90,15 +93,7 @@
parser.state.module.context
)(expr);
});
- parser.hooks.expression
- .for("require.main")
- .tap(
- "NodeStuffPlugin",
- ParserHelpers.toConstantDependencyWithWebpackRequire(
- parser,
- "__webpack_require__.c[__webpack_require__.s]"
- )
- );
+ }
parser.hooks.expression
.for("require.extensions")
.tap(
@@ -108,80 +103,6 @@
"require.extensions is not supported by webpack. Use a loader instead."
)
);
- parser.hooks.expression
- .for("require.main.require")
- .tap(
- "NodeStuffPlugin",
- ParserHelpers.expressionIsUnsupported(
- parser,
- "require.main.require is not supported by webpack."
- )
- );
- parser.hooks.expression
- .for("module.parent.require")
- .tap(
- "NodeStuffPlugin",
- ParserHelpers.expressionIsUnsupported(
- parser,
- "module.parent.require is not supported by webpack."
- )
- );
- parser.hooks.expression
- .for("module.loaded")
- .tap("NodeStuffPlugin", expr => {
- parser.state.module.buildMeta.moduleConcatenationBailout =
- "module.loaded";
- return ParserHelpers.toConstantDependency(parser, "module.l")(
- expr
- );
- });
- parser.hooks.expression
- .for("module.id")
- .tap("NodeStuffPlugin", expr => {
- parser.state.module.buildMeta.moduleConcatenationBailout =
- "module.id";
- return ParserHelpers.toConstantDependency(parser, "module.i")(
- expr
- );
- });
- parser.hooks.expression
- .for("module.exports")
- .tap("NodeStuffPlugin", () => {
- const module = parser.state.module;
- const isHarmony =
- module.buildMeta && module.buildMeta.exportsType;
- if (!isHarmony) return true;
- });
- parser.hooks.evaluateIdentifier
- .for("module.hot")
- .tap(
- "NodeStuffPlugin",
- ParserHelpers.evaluateToIdentifier("module.hot", false)
- );
- parser.hooks.expression.for("module").tap("NodeStuffPlugin", () => {
- const module = parser.state.module;
- const isHarmony = module.buildMeta && module.buildMeta.exportsType;
- let moduleJsPath = path.join(
- __dirname,
- "..",
- "buildin",
- isHarmony ? "harmony-module.js" : "module.js"
- );
- if (module.context) {
- moduleJsPath = path.relative(
- parser.state.module.context,
- moduleJsPath
- );
- if (!/^[A-Z]:/i.test(moduleJsPath)) {
- moduleJsPath = `./${moduleJsPath.replace(/\\/g, "/")}`;
- }
- }
- return ParserHelpers.addParsedVariableToModule(
- parser,
- "module",
- `require(${JSON.stringify(moduleJsPath)})(module)`
- );
- });
};
normalModuleFactory.hooks.parser