Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 8e7e54e

Browse files
committed
feat(generate-meta-webpack-plugin): introduce new plugin
1 parent 0f9e713 commit 8e7e54e

File tree

7 files changed

+235
-2
lines changed

7 files changed

+235
-2
lines changed

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/fusuma/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@babel/preset-env": "^7.13.9",
3333
"@babel/preset-react": "^7.12.13",
3434
"@fusuma/client": "^2.7.0",
35+
"@fusuma/generate-meta-webpack-plugin": "^1.0.0",
3536
"@fusuma/mdx-loader": "^2.7.0",
3637
"@fusuma/prism-loader": "^2.7.0",
3738
"@soda/friendly-errors-webpack-plugin": "^1.8.0",

packages/fusuma/src/webpack/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = (
3737
const config = (() => {
3838
switch (type) {
3939
case 'production':
40-
return require('./webpack.prod.config')();
40+
return require('./webpack.prod.config')({ meta });
4141
default:
4242
return require('./webpack.dev.config')();
4343
}

packages/fusuma/src/webpack/webpack.prod.config.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@ const TerserPlugin = require('terser-webpack-plugin');
44
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
55
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
66
const CompressionPlugin = require('compression-webpack-plugin');
7+
const MetaPlugin = require('@fusuma/generate-meta-webpack-plugin');
78

8-
function prod() {
9+
function prod({ meta }) {
910
return {
1011
mode: 'production',
1112
output: {
1213
filename: '[name].[chunkhash].bundle.js',
1314
chunkFilename: '[name].[chunkhash].bundle.js',
1415
},
1516
plugins: [
17+
new MetaPlugin({
18+
filename: 'meta.json',
19+
data: {
20+
updatedAt: Date.now(),
21+
meta,
22+
},
23+
}),
1624
new MiniCssExtractPlugin({
1725
filename: '[name].[chunkhash].css',
1826
chunkFilename: '[name].[chunkhash].css',

packages/generate-meta-webpack-plugin/package-lock.json

+154
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@fusuma/generate-meta-webpack-plugin",
3+
"version": "1.0.0",
4+
"description": "webpack plugin for fusuma",
5+
"main": "src/index.js",
6+
"files": [
7+
"src"
8+
],
9+
"publishConfig": {
10+
"access": "public"
11+
},
12+
"author": "hiroppy <git@hiroppy.me> (https://hiroppy.me/)",
13+
"license": "MIT",
14+
"dependencies": {
15+
"schema-utils": "^3.0.0"
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const { writeFile } = require('fs').promises;
4+
const { join } = require('path');
5+
const { validate } = require('schema-utils');
6+
7+
const schema = {
8+
type: 'object',
9+
properties: {
10+
data: {
11+
type: 'object',
12+
properties: {
13+
updatedAt: {
14+
type: 'number',
15+
},
16+
},
17+
},
18+
filename: {
19+
type: 'string',
20+
},
21+
},
22+
};
23+
24+
class GenerateMetaPlugin {
25+
constructor(options = {}) {
26+
this.name = 'generate-meta-webpack-plugin';
27+
this.options = options;
28+
29+
validate(schema, options, this.name);
30+
}
31+
32+
apply(compiler) {
33+
compiler.hooks.done.tapPromise(this.name, async () => {
34+
await writeFile(
35+
join(compiler.outputPath, this.options.filename),
36+
JSON.stringify(this.options.data)
37+
);
38+
});
39+
}
40+
}
41+
42+
module.exports = GenerateMetaPlugin;

0 commit comments

Comments
 (0)