Un projet très simple :
- Le fichier d'entrée est
index.js
- Un module
foo.js
-
index.js
importationsfoo.js
- Une base
webpack.config.js
- Un plugin personnalisé -
HelloWorldPlugin
Fichiers :
// ./src/foo.js
export default {
foo: 'foo'
}
// ./src/index.js
import foo from './foo'
console.log(foo);
// webpack.config.js
const path = require('path');
var HelloWorldPlugin = require('./hello-world-plugin');
module.exports = {
entry: './src/index.js',
plugins: [
new HelloWorldPlugin({ options: true })
]
};
// HelloWorldPlugin.js
class HelloWorldPlugin {
apply(compiler) {
compiler.hooks.afterEmit.tapAsync("HelloWorldPlugin", (compilation, next) => {
console.log(arguments);
// let foo = the module as imported from ./src/foo.js i.e. {foo: 'foo'}
next();
});
}
}
module.exports = HelloWorldPlugin;
La question est :
Est-il possible d'accéder {foo:'foo'}
de la foo-module
à l'intérieur de HelloWorldPlugin
?