File size: 2,586 Bytes
61d39e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Multiple things attempted when trying to add icons to the bundle.

None of this worked - eventually just prepended text on emit instead.

```javascript

    // compilation.hooks.processAssets.tap(

    //     {

    //         name: 'AddImportPlugin',

    //         stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,

    //     },

    //     (assets) => {

    //         for (const assetName of Object.keys(assets)) {

    //             if (assetName.endsWith('.js')) {

    //                 const source = assets[assetName].source();

    //                 const newSource = `${icons}\n${source}`;

    //                 compilation.updateAsset(assetName, new compiler.webpack.sources.RawSource(newSource));

    //             }

    //         }

    //     }

    // );



    // Inject into bundle

    // console.log('adding this:' + icons);

    // compilation.assets['icons-thing'] = {

    //     source: () => icons,

    //     size: () => icons.length,

    // };



    // compilation.addModule({

    //   identifier() {

    //     return 'icons-thing';

    //   },

    //   build() {

    //     this._source = {

    //       source() {

    //         return content;

    //       },

    //       size() {

    //         return content.length;

    //       }

    //     };

    //   }

    // });





    // Add the generated module to Webpack's internal modules

    // compilation.hooks.optimizeModules.tap('IconsPlugin', (modules) => {

    //     const virtualModule = {

    //     identifier: () => 'icons.js',

    //     readableIdentifier: () => 'icons.js',

    //     build: () => {},

    //     source: () => icons,

    //     size: () => icons.length,

    //     chunks: [],

    //     assets: [],

    //     hash: () => 'icons',

    //     };



    //     modules.push(virtualModule);

    // });



});

// this.hooks.entryOption.tap('IconsPlugin', (context, entry) => {

//     entry.main.import.push('icons-thing');

// });

// this.hooks.make.tapAsync('InjectTextEntryPlugin', (compilation, callback) => {

//     // Create a new asset (fake module) from the generated content

//     const content = `console.log('${this.options.text}');`;



//     callback();

// });

// this.hooks.entryOption.tap('IconsPlugin', (context, entry) => {

// });

// this.hooks.entryOption.tap('InjectTextEntryPlugin', (context, entry) => {

//     // Add this as an additional entry point

//     this.options.entry = {

//       ...this.options.entry,

//       'generated-entry': '// FINDME\n'

//     };

// });

```