framework/js-packages/webpack-config/tests/compiler.js
Sami Mazouz 016503d8c3
feat: export registry (#3842)
* feat: registry first iteration

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>

* feat: improve webpack auto export loader

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>

* chore: remove `compat` API

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>

* chore: cleanup

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>

---------

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
2023-06-29 18:57:53 +01:00

49 lines
1.2 KiB
JavaScript

import path from 'path';
import webpack from 'webpack';
import { createFsFromVolume, Volume } from 'memfs';
import * as fs from 'fs';
export default (fixture, options = {}) => {
const compiler = webpack({
context: __dirname,
entry: `./${fixture}`,
output: {
path: path.resolve(__dirname),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: path.resolve(__dirname, '../src/autoExportLoader.cjs'),
options: {
...options,
composerPath: '../../composer.json',
},
},
},
],
},
optimization: {
minimize: false,
minimizer: [],
},
});
compiler.outputFileSystem = createFsFromVolume(new Volume());
compiler.outputFileSystem.join = path.join.bind(path);
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err) reject(err);
if (stats.hasErrors()) reject(stats.toJson().errors);
const outputFilepath = path.join(compiler.options.output.path, compiler.options.output.filename);
stats.finalOutput = compiler.outputFileSystem.readFileSync(outputFilepath, 'utf-8');
resolve(stats);
});
});
};