From 824672add04738b5e2b84bdc62fb3d0c39a43ece Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 8 Aug 2024 16:20:12 +0100 Subject: [PATCH] Added build script --- package.json | 2 ++ webpack.config.js | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index dd14f46..daf304f 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,6 @@ { + "name": "LiteRyzJS", + "version": "0.1.0.154", "devDependencies": { "webpack": "^5.93.0", "webpack-cli": "^5.1.4" diff --git a/webpack.config.js b/webpack.config.js index eefb0c7..b372ac0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,31 @@ const path = require('path'); +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(); + }); + } +} + module.exports = { entry: { @@ -7,11 +34,17 @@ module.exports = { project: './src/project.js' }, output: { - filename: '[name].js', + filename: `[name].min.js`, path: path.resolve(__dirname, 'dist'), - library: 'LiteRyzJS', // The global variable name under which the classes will be exposed + library: 'LiteRyzJS', libraryTarget: 'umd', globalObject: 'this' }, mode: 'production', // development|production + plugins: [ + new webpack.DefinePlugin({ + 'process.env.VERSION': JSON.stringify(version) + }), + new PrependVersionPlugin() + ] }; \ No newline at end of file