Я правильно.Вы не можете получить информацию о входе в модули.Я думаю, что вы можете решить, может быть, не используя точку входа.Поскольку модули кэшируются после загрузки, мы можем использовать встроенный запрос ресурса
a.js
const haha = 'hello';
console.log(haha);
export default haha;
less.js
import haha from './a?change=e'; // will be "import hehe from 'a';" in the bundle
console.log(haha); // will be "console.log(hehe);" in the bundle
lots.js
import haha from './a?change=o'; // will be "import hehe from 'a';" in the bundle
console.log(haha); // will be "console.log(hoho);" in the bundle
пользовательский загрузчик -> transformer.js
module.exports = function(source) {
let queryval = "";
if (this.resourceQuery && this.resourceQuery.indexOf('change')) {
queryval = this.resourceQuery.substr(this.resourceQuery.indexOf("change"+ 1));
// console.log("queryval: ", queryval);
if (queryval) {
const replacedCode = source.replace(/[a]/g, queryval); // this replace every thing but need own logic even default -> def_ult _ is query val :P
console.log("replacedCode: ", replacedCode);
return replacedCode;
}
}
return source;
}
webpack.config.js
const path = require('path');
module.exports = {
mode: 'development',
entry: {
aa: './src/few.js',
aaaa: './src/lots.js'
},
module: {
rules: [
{
test: /\.js$/,
oneOf: [
{
resourceQuery: /change/,
use: [
{
loader: path.resolve('./src/transformer.js'),
options: {
replaceWith: true
}
}
],
},
{
loader: path.resolve('./src/transformer.js'),
}
],
}
]
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
},
optimization: {
runtimeChunk: "single"
}
};