mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 11:16:39 +08:00
016503d8c3
* 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>
49 lines
1.2 KiB
JavaScript
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);
|
|
});
|
|
});
|
|
};
|