2024-08-08 11:13:28 +00:00
|
|
|
const path = require('path');
|
2024-08-08 15:20:12 +00:00
|
|
|
const { version } = require('./package.json');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
|
|
|
|
class PrependVersionPlugin {
|
|
|
|
apply(compiler) {
|
|
|
|
compiler.hooks.emit.tapAsync('PrependVersionPlugin', (compilation, callback) => {
|
|
|
|
Object.keys(compilation.assets).forEach((filename) => {
|
|
|
|
if (filename.endsWith('.js')) {
|
|
|
|
const asset = compilation.assets[filename];
|
|
|
|
|
|
|
|
const headerText = `/*!\n * Part of LiteRyzJS v${version}\n * Copyright 2023-2024 Ray Lam (https://www.hiimray.co.uk)\n *\n */\n`;
|
|
|
|
|
|
|
|
const newContent = headerText + asset.source();
|
|
|
|
|
|
|
|
compilation.assets[filename] = {
|
|
|
|
source: () => newContent,
|
|
|
|
size: () => newContent.length,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-08 11:13:28 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
entry: {
|
|
|
|
extensions: './src/extensions.js',
|
2024-08-14 22:03:58 +00:00
|
|
|
graphics: './src/graphics.js'
|
2024-08-08 11:13:28 +00:00
|
|
|
},
|
|
|
|
output: {
|
2024-08-14 22:03:58 +00:00
|
|
|
filename: `[name].dist.js`,
|
2024-08-08 11:13:28 +00:00
|
|
|
path: path.resolve(__dirname, 'dist'),
|
2024-08-08 15:20:12 +00:00
|
|
|
library: 'LiteRyzJS',
|
2024-08-08 11:13:28 +00:00
|
|
|
libraryTarget: 'umd',
|
|
|
|
globalObject: 'this'
|
|
|
|
},
|
|
|
|
mode: 'production', // development|production
|
2024-08-08 15:20:12 +00:00
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.VERSION': JSON.stringify(version)
|
|
|
|
}),
|
|
|
|
new PrependVersionPlugin()
|
2024-08-14 22:03:58 +00:00
|
|
|
],
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
'css-loader',
|
|
|
|
'sass-loader'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2024-08-08 11:13:28 +00:00
|
|
|
};
|