|
| 1 | +const webpack = require('webpack'); |
| 2 | +const CopyPlugin = require('copy-webpack-plugin'); |
| 3 | +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); |
| 4 | +const ZipFilesPlugin = require('webpack-zip-files-plugin'); |
| 5 | + |
| 6 | +const path = require('path'); |
| 7 | +const packageFile = require('./package.json'); |
| 8 | + |
| 9 | +const libraryName = 'enhanced-github'; |
| 10 | +const libVersion = packageFile.version; |
| 11 | +const license = packageFile.license; |
| 12 | +const destination = path.resolve(__dirname, 'dist'); |
| 13 | +const zipDestination = path.resolve(__dirname, 'enhanced-github'); |
| 14 | + |
| 15 | +let deps = ''; |
| 16 | +Object.keys(packageFile.dependencies).map((key, index) => { |
| 17 | + deps += `\n ${index + 1}. ${key} - ${packageFile.dependencies[key]}`; |
| 18 | +}); |
| 19 | + |
| 20 | +const libraryHeaderComment = `${libraryName} - v${libVersion}\n |
| 21 | +URL - https://github.com/softvar/ehanced-github\n |
| 22 | +${license} License, Copyright Varun Malhotra |
| 23 | +
|
| 24 | +Dependencies used - ${deps}`; |
| 25 | + |
| 26 | +const plugins = [ |
| 27 | + new webpack.BannerPlugin({ |
| 28 | + banner: libraryHeaderComment, |
| 29 | + entryOnly: true |
| 30 | + }), |
| 31 | + new CleanWebpackPlugin({ |
| 32 | + default: [destination] |
| 33 | + }), |
| 34 | + new CopyPlugin([ |
| 35 | + { from: 'options.js', to: destination }, |
| 36 | + { from: 'popup.js', to: destination }, |
| 37 | + { from: '*html', to: destination }, |
| 38 | + { from: 'manifest.json', to: destination }, |
| 39 | + { from: 'icons/*.png', to: destination } |
| 40 | + ]), |
| 41 | + new ZipFilesPlugin({ |
| 42 | + entries: [ |
| 43 | + { src: destination, dist: zipDestination } |
| 44 | + ], |
| 45 | + output: zipDestination, |
| 46 | + format: 'zip', |
| 47 | + }), |
| 48 | +]; |
| 49 | + |
| 50 | +module.exports = function(_env, argv) { |
| 51 | + return { |
| 52 | + entry: { |
| 53 | + [libraryName]: './src/inject.js' |
| 54 | + }, |
| 55 | + mode: argv.mode, |
| 56 | + output: { |
| 57 | + path: destination, |
| 58 | + filename: 'src/inject.js', |
| 59 | + library: libraryName, |
| 60 | + libraryTarget: 'global' |
| 61 | + }, |
| 62 | + module: { |
| 63 | + rules: [ |
| 64 | + { |
| 65 | + test: /\.js$/, |
| 66 | + exclude: /node_modules|dist/, |
| 67 | + use: { |
| 68 | + loader: 'babel-loader' |
| 69 | + } |
| 70 | + } |
| 71 | + ] |
| 72 | + }, |
| 73 | + plugins |
| 74 | + }; |
| 75 | +}; |
0 commit comments