|
1 |
| -var webpack = require('webpack'); |
2 |
| -var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin; |
3 |
| -var path = require('path'); |
4 |
| -var env = require('yargs').argv.mode; |
| 1 | +const webpack = require('webpack'); |
| 2 | +const path = require('path'); |
| 3 | +const semver = require('semver'); |
5 | 4 |
|
6 |
| -var libraryName = 'secure-ls'; |
| 5 | +const packageFile = require('./package.json'); |
| 6 | +const libVersion = packageFile.version; |
| 7 | +const libraryName = packageFile.name; |
7 | 8 |
|
8 |
| -var plugins = [], outputFile; |
| 9 | +const PRODUCTION = 'production'; |
9 | 10 |
|
10 |
| -if (env === 'build') { |
11 |
| - plugins.push(new UglifyJsPlugin({ minimize: true })); |
12 |
| - outputFile = libraryName + '.min.js'; |
13 |
| -} else { |
14 |
| - outputFile = libraryName + '.js'; |
| 11 | +let deps = ''; |
| 12 | + |
| 13 | +Object.keys(packageFile.dependencies).map((key, index) => { |
| 14 | + deps += `\n ${index + 1}. ${key} - ${packageFile.dependencies[key]}`; |
| 15 | +}); |
| 16 | + |
| 17 | +let libraryHeaderComment; |
| 18 | + |
| 19 | +function addPlugins(argv) { |
| 20 | + const version = semver.inc(libVersion, argv.env.type) || libVersion; |
| 21 | + |
| 22 | + libraryHeaderComment = `${libraryName} - v${version} |
| 23 | +URL - https://github.com/softvar/secure-ls |
| 24 | +
|
| 25 | +The MIT License (MIT) |
| 26 | +
|
| 27 | +Copyright (c) 2016-2024 Varun Malhotra |
| 28 | +
|
| 29 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 30 | +of this software and associated documentation files (the "Software"), to deal |
| 31 | +in the Software without restriction, including without limitation the rights |
| 32 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 33 | +copies of the Software, and to permit persons to whom the Software is |
| 34 | +furnished to do so, subject to the following conditions: |
| 35 | +
|
| 36 | +The above copyright notice and this permission notice shall be included in all |
| 37 | +copies or substantial portions of the Software. |
| 38 | +
|
| 39 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 40 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 41 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 42 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 43 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 44 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 45 | +SOFTWARE. |
| 46 | +
|
| 47 | +
|
| 48 | +Dependencies used - ${deps}`; |
| 49 | + |
| 50 | + const plugins = [ |
| 51 | + new webpack.BannerPlugin({ |
| 52 | + banner: libraryHeaderComment, |
| 53 | + entryOnly: true, |
| 54 | + stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT, |
| 55 | + }), |
| 56 | + ]; |
| 57 | + |
| 58 | + return plugins; |
15 | 59 | }
|
16 | 60 |
|
17 |
| -var config = { |
18 |
| - entry: __dirname + '/src/index.js', |
19 |
| - devtool: 'source-map', |
20 |
| - output: { |
21 |
| - path: __dirname + '/dist', |
22 |
| - filename: outputFile, |
23 |
| - library: 'SecureLS', |
24 |
| - libraryTarget: 'umd', |
25 |
| - umdNamedDefine: true |
26 |
| - }, |
27 |
| - module: { |
28 |
| - loaders: [ |
29 |
| - { |
30 |
| - test: /(\.jsx|\.js)$/, |
31 |
| - loader: 'babel', |
32 |
| - exclude: /(node_modules|bower_components)/ |
| 61 | +module.exports = function (_env, argv) { |
| 62 | + return { |
| 63 | + entry: { |
| 64 | + [libraryName]: '/src/index.js', |
| 65 | + }, |
| 66 | + devtool: 'source-map', |
| 67 | + mode: argv.mode === PRODUCTION ? 'production' : 'development', |
| 68 | + output: { |
| 69 | + path: path.resolve(__dirname, 'dist'), |
| 70 | + filename: () => { |
| 71 | + if (argv.mode === PRODUCTION) { |
| 72 | + return '[name].min.js'; |
| 73 | + } |
| 74 | + |
| 75 | + return '[name].js'; |
33 | 76 | },
|
34 |
| - { |
35 |
| - test: /(\.jsx|\.js)$/, |
36 |
| - loader: "eslint-loader", |
37 |
| - exclude: /node_modules/ |
38 |
| - } |
39 |
| - ] |
40 |
| - }, |
41 |
| - eslint: { |
42 |
| - failOnWarning: false, |
43 |
| - failOnError: false |
44 |
| - }, |
45 |
| - resolve: { |
46 |
| - root: path.resolve('./src'), |
47 |
| - extensions: ['', '.js'] |
48 |
| - }, |
49 |
| - plugins: plugins |
| 77 | + library: 'SecureLS', |
| 78 | + libraryTarget: 'umd', |
| 79 | + globalObject: 'this', |
| 80 | + auxiliaryComment: { |
| 81 | + root: ' Root', |
| 82 | + commonjs: ' CommonJS', |
| 83 | + commonjs2: ' CommonJS2', |
| 84 | + amd: ' AMD', |
| 85 | + }, |
| 86 | + }, |
| 87 | + module: { |
| 88 | + rules: [ |
| 89 | + { |
| 90 | + test: /\.js$/, |
| 91 | + exclude: /(node_modules|bower_components)/, |
| 92 | + use: { |
| 93 | + loader: 'babel-loader', |
| 94 | + }, |
| 95 | + }, |
| 96 | + ], |
| 97 | + }, |
| 98 | + resolve: { |
| 99 | + extensions: ['.js'], |
| 100 | + }, |
| 101 | + plugins: addPlugins(argv), |
| 102 | + }; |
50 | 103 | };
|
51 |
| - |
52 |
| -module.exports = config; |
|
0 commit comments