Skip to content

Commit 610d4f0

Browse files
committed
chore: add configuration files for dev environmentl update webpack config
1 parent ab85151 commit 610d4f0

File tree

7 files changed

+134
-45
lines changed

7 files changed

+134
-45
lines changed

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no-install commitlint --edit "$1"

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn lint-staged

.husky/pre-push

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
yarn check:license
2+
yarn lint
3+
yarn test:prod
4+
yarn build

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"printWidth": 120,
4+
"tabWidth": 2,
5+
"useTabs": false,
6+
"singleQuote": true,
7+
"bracketSpacing": true
8+
}

commitlint.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
rules: {
4+
// TODO Add Scope Enum Here
5+
// 'scope-enum': [2, 'always', ['yourscope', 'yourscope']],
6+
'type-enum': [
7+
2,
8+
'always',
9+
['feat', 'fix', 'docs', 'chore', 'style', 'refactor', 'ci', 'test', 'revert', 'perf', 'vercel'],
10+
],
11+
},
12+
};

eslint.config.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
4+
export default [
5+
{languageOptions: { globals: globals.browser }},
6+
pluginJs.configs.recommended,
7+
{
8+
"rules": {
9+
10+
}
11+
}
12+
];

webpack.config.js

Lines changed: 96 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,103 @@
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');
54

6-
var libraryName = 'secure-ls';
5+
const packageFile = require('./package.json');
6+
const libVersion = packageFile.version;
7+
const libraryName = packageFile.name;
78

8-
var plugins = [], outputFile;
9+
const PRODUCTION = 'production';
910

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;
1559
}
1660

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';
3376
},
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+
};
50103
};
51-
52-
module.exports = config;

0 commit comments

Comments
 (0)