mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-03 01:16:14 +03:00
Extract plugin to module.
This commit is contained in:
parent
ae1f805510
commit
4f1a8cd205
23
generator/src/add-files-plugin.js
Normal file
23
generator/src/add-files-plugin.js
Normal file
@ -0,0 +1,23 @@
|
||||
const path = require("path");
|
||||
|
||||
module.exports = class AddFilesPlugin {
|
||||
constructor(filesList) {
|
||||
this.filesList = filesList;
|
||||
}
|
||||
apply(compiler) {
|
||||
compiler.hooks.afterCompile.tap("AddFilesPlugin", compilation => {
|
||||
this.filesList.forEach(file => {
|
||||
// Couldn't find this documented in the webpack docs,
|
||||
// but I found the example code for it here:
|
||||
// https://github.com/jantimon/html-webpack-plugin/blob/35a154186501fba3ecddb819b6f632556d37a58f/index.js#L470-L478
|
||||
|
||||
const filename = path.join(file.name, "content.txt");
|
||||
compilation.fileDependencies.add(filename);
|
||||
compilation.assets[filename] = {
|
||||
source: () => file.content,
|
||||
size: () => file.content.length
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
@ -9,28 +9,7 @@ const merge = require("webpack-merge");
|
||||
const { GenerateSW } = require("workbox-webpack-plugin");
|
||||
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
|
||||
const webpackDevServer = require("webpack-dev-server");
|
||||
|
||||
class AddFilesPlugin {
|
||||
constructor(filesList) {
|
||||
this.filesList = filesList;
|
||||
}
|
||||
apply(compiler) {
|
||||
compiler.hooks.afterCompile.tap("AddFilesPlugin", compilation => {
|
||||
this.filesList.forEach(file => {
|
||||
// Couldn't find this documented in the webpack docs,
|
||||
// but I found the example code for it here:
|
||||
// https://github.com/jantimon/html-webpack-plugin/blob/35a154186501fba3ecddb819b6f632556d37a58f/index.js#L470-L478
|
||||
|
||||
const filename = path.join(file.name, "content.txt");
|
||||
compilation.fileDependencies.add(filename);
|
||||
compilation.assets[filename] = {
|
||||
source: () => file.content,
|
||||
size: () => file.content.length
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
const AddFilesPlugin = require("./add-files-plugin.js");
|
||||
|
||||
module.exports = { start, run };
|
||||
function start({ routes, debug, manifestConfig }) {
|
||||
|
Loading…
Reference in New Issue
Block a user