question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to integrate it in webpack.config.js file?

See original GitHub issue

I may have missed a document somewhere, but how should I integrate this plugin in webpack.config.js file? I export one or an array of webpack configs, but I don’t directly call webpack().

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jscheidcommented, Mar 16, 2018

I suggest you ask the maintainers of the other plugin to include the original asset here and here (the original asset from compilation, not the one from stats).

Then you could just do something like:

new ManifestPlugin({ generate: (seed, files) => files.reduce(
    (manifest, { name, path, asset: { integrity } = {} }) => (
         { ...manifest, [name]: { path, integrity } }
    ), seed) });
1reaction
shakibacommented, Mar 15, 2018

Thanks, I wrote this to get it done:

var JsonFile = require('jsonfile');
var path = require('path');

var sriJsonPlugin = {
  apply: (compiler) => {
    compiler.plugin("done", stats => {
      // extract SRI values from compiler
      var assets = stats.compilation.assets;
      var newIntegrityMap = {};
      Object.keys(assets).forEach(key => {
        newIntegrityMap[key] = assets[key].integrity;
      });
      // load current SRI values from file
      var integrityFile = path.resolve(compiler.outputPath, 'integrity.json');
      var integrityJson;
      try {
        integrityJson = JsonFile.readFileSync(integrityFile);
      } catch (e) {
        integrityJson = {};
      }
      // merge them and write them back
      var newIntegrityJson = Object.assign({}, integrityJson, newIntegrityMap);
      integrityJson = JsonFile.writeFileSync(integrityFile, newIntegrityJson, {spaces: 2});
    });
  },
};

It would be great if we can add a similar basic option to this plugin!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration - webpack
config.js file in the root folder and webpack will automatically use it. All the available configuration options are specified below. tip.
Read more >
How can I use ES6 in webpack.config.js? - Stack Overflow
Try naming your config as webpack.config.babel.js . You should have babel-register included in the project. Example at react-router-bootstrap.
Read more >
webpack-interview-questions/answers.md at master - GitHub
Answer: webpack's config file is javascript file in commonjs module pattern. Question: Is it possible to have multiple entry points in a singe...
Read more >
How to Create a Production-Ready Webpack 4 Config From ...
To use it, we'll simply require the plugin in our webpack.config.js file and then include it in the plugins array in our config...
Read more >
How to create a React application with Webpack - Educative.io
1. Create a folder and initialize NPM · 2. Install the following packages · 3. Create .babelrc file · 4. Create a webpack.config.js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found