<commit_before>import path from 'path';
import fs from 'fs';
let cssString = fs.readFileSync(path.join(__dirname, './style.css'), 'utf8');
let jsString = fs.readFileSync(path.join(__dirname, './pluginmain.js'), 'utf8');


export default class VisualizerPlugin {
    constructor(opts = {filename: 'stats.html'}) {
        this.opts = opts;
    }

    apply(compiler) {
        compiler.plugin('emit', (compilation, callback) => {
            let stats = compilation.getStats().toJson({chunkModules: true});
            let stringifiedStats = JSON.stringify(stats);
            stringifiedStats = stringifiedStats.replace(/</g, '&lt;').replace(/</g, '&gt;');

            let html = `<!doctype html>
                <meta charset="UTF-8">
                <title>Webpack Visualizer</title>
                <style>${cssString}</style>
                <div id="App"></div>
                <script>window.stats = ${stringifiedStats};</script>
                <script>${jsString}</script>
            `;

            compilation.assets[this.opts.filename] = {
                source() {
                    return html;
                },
                size() {
                    return html.length;
                }
            };

            callback();
        });
    }
}<commit_msg>feature: stats html file will no longer be listed as a webpack asset<commit_after>import path from 'path';
import fs from 'fs';
let cssString = fs.readFileSync(path.join(__dirname, './style.css'), 'utf8');
let jsString = fs.readFileSync(path.join(__dirname, './pluginmain.js'), 'utf8');


export default class VisualizerPlugin {
    constructor(opts = {filename: 'stats.html'}) {
        this.opts = opts;
    }

    apply(compiler) {
        compiler.plugin('emit', (compilation, callback) => {
            let stats = compilation.getStats().toJson({chunkModules: true});
            let stringifiedStats = JSON.stringify(stats);
            stringifiedStats = stringifiedStats.replace(/</g, '&lt;').replace(/</g, '&gt;');

            let html = `<!doctype html>
                <meta charset="UTF-8">
                <title>Webpack Visualizer</title>
                <style>${cssString}</style>
                <div id="App"></div>
                <script>window.stats = ${stringifiedStats};</script>
                <script>${jsString}</script>
            `;

            fs.writeFile(path.join(compilation.outputOptions.path, this.opts.filename), html, (err) => {
                if (err) {
                    console.log('webpack-visualizer-plugin: error writing stats file'); //eslint-disable-line no-console
                }
                callback();
            });
        });
    }
}
{'fraction_non_alphanumeric': 0.15121042830540038, 'fraction_numerical': 0.0022346368715083797, 'mean_word_length': 1.9646799116997793, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4079610', 'n_tokens_mistral': 755, 'n_tokens_neox': 718, 'n_words': 146}