diff --git a/generator/src/add-files-plugin.js b/generator/src/add-files-plugin.js new file mode 100644 index 00000000..99d8016f --- /dev/null +++ b/generator/src/add-files-plugin.js @@ -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 + }; + }); + }); + } +}; diff --git a/generator/src/develop.js b/generator/src/develop.js index 677cc910..a7b6eed6 100644 --- a/generator/src/develop.js +++ b/generator/src/develop.js @@ -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 }) {