19
loading...
This website collects cookies to deliver better user experience
./dist/main.js
for the main output file and to the ./dist
folder for any other generated file.Compiler
graph LR
A[Compiler]-->B[Compilation]
B-->C[Modules]
C--Loaders-->D[Parser]
D-->E[Output]
acorn
library generates the AST
tree for analyzing the relations of modules.IIFE
function.compiler
creates a new compilation
object. It extends the Tapable
class in order to register and call plugins. Most user facing plugins are first registered on the Compiler.compiler.hooks.someHook.tap('MyPlugin', (params) => {
/* ... */
});
compilation.hooks.buildModule.tap(
'SourceMapDevToolModuleOptionsPlugin',
(module) => {
module.useSourceMap = true;
}
);
if (module.hot) {
module.hot.accept('./library.js', function () {
// Do something with the updated library module...
});
}
graph LR
check-->ready
ready-->apply
apply-->dispose
dispose-->apply
apply-->idle
/*
@param {string|Buffer} content Content of the resource file
@param {object} [map] SourceMap data consumable by https://github.com/mozilla/source-map
@param {any} [meta] Meta data, could be anything
*/
module.exports = function webpackLoader(content, map, meta) {
// code of your webpack loader
}
module.exports = function webpackLoader(content, map, meta) {
var callback = this.async();
someAsyncOperation(content, function (err, result) {
if (err) return callback(err);
callback(null, result, map, meta);
})
})
// A JavaScript class.
class MyExampleWebpackPlugin {
// Define `apply` as its prototype method which is supplied with compiler as its argument
apply(compiler) {
// Specify the event hook to attach to
compiler.hooks.emit.tapAsync(
'MyExampleWebpackPlugin',
(compilation, callback) => {
console.log('This is an example plugin!');
console.log(
'Here’s the `compilation` object which represents a single build of assets:',
compilation
);
// Manipulate the build using the plugin API provided by webpack
compilation.addModule(/* ... */);
callback();
}
);
}
}
19