Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports.pitch = function (request, prevRequest) {
if (this.cacheable) this.cacheable();
const callback = this.async();
if ([".js", ".ts"].indexOf(path.extname(request)) >= 0) {
produce(this, request, callback, loaderUtils.getLoaderConfig(this));
produce(this, request, callback, loaderUtils.getOptions(this));
} else {
const parts = request.split("!");
const filename = parts[parts.length - 1];
Expand All @@ -30,13 +30,15 @@ function produce(loader, request, callback, config) {
const outputOptions = { filename: childFilename };
const childCompiler = getRootCompilation(loader)
.createChildCompiler("value-compiler", outputOptions);
childCompiler.apply(new NodeTemplatePlugin(outputOptions));
childCompiler.apply(new LibraryTemplatePlugin(null, "commonjs2"));
childCompiler.apply(new NodeTargetPlugin());
childCompiler.apply(new SingleEntryPlugin(loader.context, `!!${request}`));
childCompiler.apply(new LimitChunkCountPlugin({ maxChunks: 1 }));
new NodeTemplatePlugin(outputOptions).apply(childCompiler);
new LibraryTemplatePlugin(null, "commonjs2").apply(childCompiler);
new NodeTargetPlugin().apply(childCompiler);
new SingleEntryPlugin(loader.context, `!!${request}`).apply(childCompiler);
new LimitChunkCountPlugin({ maxChunks: 1 }).apply(childCompiler);
const subCache = `subcache ${__dirname} ${request}`;
childCompiler.plugin("compilation", (compilation) => {

const plugin = { name: 'ValueLoader' };
childCompiler.hooks.compilation.tap(plugin, (compilation) => {
if (compilation.cache) {
if (!compilation.cache[subCache])
{ compilation.cache[subCache] = {}; }
Expand All @@ -45,13 +47,13 @@ function produce(loader, request, callback, config) {
});
// We set loaderContext[__dirname] = false to indicate we already in
// a child compiler so we don't spawn another child compilers from there.
childCompiler.plugin("this-compilation", (compilation) => {
compilation.plugin("normal-module-loader", (loaderContext) => {
childCompiler.hooks.thisCompilation.tap(plugin, (compilation) => {
compilation.hooks.normalModuleLoader.tap(plugin, (loaderContext) => {
loaderContext[__dirname] = false;
});
});
let source;
childCompiler.plugin("after-compile", (compilation, callback) => {
childCompiler.hooks.afterCompile.tap(plugin, (compilation) => {
source = compilation.assets[childFilename] && compilation.assets[childFilename].source();

// Remove all chunk assets
Expand All @@ -60,8 +62,6 @@ function produce(loader, request, callback, config) {
delete compilation.assets[file];
});
});

callback();
});

childCompiler.runAsChild((err, entries, compilation) => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"author": "Chi Vinh Le and contributors (https://github.com/wikiwi/value-loader/graphs/contributors)",
"license": "MIT",
"peerDependencies": {
"webpack": "^1.12.9 || ^2.0.0 || ^3.0.0"
"webpack": "^1.12.9 || ^2.0.0 || ^3.0.0 || ^4.0.0"
},
"dependencies": {
"loader-utils": "^0.2.16"
"loader-utils": "^1.2.3"
}
}