@lightscale/webpack-config 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +137 -0
- package/package.json +43 -0
- package/readme.md +0 -0
package/index.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
3
|
+
import NotifierPlugin from 'webpack-notifier';
|
|
4
|
+
import ManifestPlugin from 'webpack-assets-manifest';
|
|
5
|
+
import StylelintPlugin from 'stylelint-webpack-plugin';
|
|
6
|
+
import EsLintPlugin from 'eslint-webpack-plugin';
|
|
7
|
+
import WebpackbarPlugin from 'webpackbar';
|
|
8
|
+
import CleanTerminalPlugin from 'clean-terminal-webpack-plugin';
|
|
9
|
+
import {CleanWebpackPlugin} from 'clean-webpack-plugin';
|
|
10
|
+
import SvgChunkWebpackPlugin from 'svg-chunk-webpack-plugin';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export class Paths {
|
|
14
|
+
#jsSourcePath;
|
|
15
|
+
#scssSourcePath;
|
|
16
|
+
|
|
17
|
+
constructor({dir, source, target, js, scss}) {
|
|
18
|
+
this.sourcePath = path.resolve(dir, source);
|
|
19
|
+
this.targetPath = path.resolve(dir, target);
|
|
20
|
+
this.jsSourcePath = js;
|
|
21
|
+
this.scssSourcePath = scss;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
jsEntry(path) {
|
|
25
|
+
return `${this.jsSourcePath}/${path}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
scssEntry(path) {
|
|
29
|
+
return `${this.scssSourcePath}/${path}`;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const makeConfig = (env, argv, options) => {
|
|
34
|
+
const isProd = argv.mode === 'production',
|
|
35
|
+
isDev = argv.mode === 'development',
|
|
36
|
+
isWatch = typeof argv.watch !== 'undefined' && argv.watch === true,
|
|
37
|
+
{paths, entry, plugins = [], manifestCustomize = (e) => e} = options;
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
entry,
|
|
41
|
+
output: {
|
|
42
|
+
filename: 'js/[name].[contenthash:8].js',
|
|
43
|
+
path: paths.targetPath,
|
|
44
|
+
},
|
|
45
|
+
context: paths.sourcePath,
|
|
46
|
+
devtool: isDev ? 'source-map' : false,
|
|
47
|
+
watchOptions: {
|
|
48
|
+
ignored: ['node_modules/**']
|
|
49
|
+
},
|
|
50
|
+
performance: {
|
|
51
|
+
hints: false
|
|
52
|
+
},
|
|
53
|
+
plugins: [
|
|
54
|
+
new ManifestPlugin({
|
|
55
|
+
customize(entry) {
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
entry.key.startsWith('svg/') ||
|
|
59
|
+
entry.key.endsWith('.map')
|
|
60
|
+
) return false;
|
|
61
|
+
|
|
62
|
+
const srcdir = path.dirname(entry.key),
|
|
63
|
+
destdir = path.dirname(entry.value);
|
|
64
|
+
|
|
65
|
+
if (srcdir !== destdir) {
|
|
66
|
+
entry.key = destdir + '/' + path.basename(entry.key);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return manifestCustomize(entry);
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
new CleanWebpackPlugin({
|
|
73
|
+
cleanStaleWebpackAssets: !isWatch
|
|
74
|
+
}),
|
|
75
|
+
new MiniCssExtractPlugin({
|
|
76
|
+
filename: 'css/[name].[contenthash:8].css',
|
|
77
|
+
chunkFilename: '[id].[contenthash:8].css'
|
|
78
|
+
}),
|
|
79
|
+
new StylelintPlugin({
|
|
80
|
+
failOnError: !isWatch,
|
|
81
|
+
}),
|
|
82
|
+
new EsLintPlugin({
|
|
83
|
+
overrideConfig: {
|
|
84
|
+
rules: {
|
|
85
|
+
"no-console": isProd ? 2 : 1,
|
|
86
|
+
"no-debugger": isProd ? 2 : 1,
|
|
87
|
+
"no-empty": isProd ? 2 : 1,
|
|
88
|
+
"no-unused-vars": isProd ? 2 : 1,
|
|
89
|
+
"no-constant-condition": isProd ? 2 : 1,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
new NotifierPlugin(),
|
|
94
|
+
new WebpackbarPlugin(),
|
|
95
|
+
new CleanTerminalPlugin(),
|
|
96
|
+
new SvgChunkWebpackPlugin({
|
|
97
|
+
filename: '[name].[contenthash].svg',
|
|
98
|
+
svgstoreConfig: {inline: false},
|
|
99
|
+
}),
|
|
100
|
+
|
|
101
|
+
...plugins,
|
|
102
|
+
],
|
|
103
|
+
|
|
104
|
+
externals: {
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
module: {
|
|
108
|
+
rules: [
|
|
109
|
+
{
|
|
110
|
+
test: /\.js$/i,
|
|
111
|
+
include: paths.sourcePath,
|
|
112
|
+
use: [
|
|
113
|
+
'babel-loader'
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
test: /\.s[ac]ss$/i,
|
|
118
|
+
include: paths.sourcePath,
|
|
119
|
+
use: [
|
|
120
|
+
MiniCssExtractPlugin.loader,
|
|
121
|
+
'css-loader',
|
|
122
|
+
'postcss-loader',
|
|
123
|
+
'sass-loader',
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
test: /.svg$/i,
|
|
128
|
+
include: paths.sourcePath,
|
|
129
|
+
use: [
|
|
130
|
+
{loader: SvgChunkWebpackPlugin.loader}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
};
|
|
137
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lightscale/webpack-config",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Basic webpack config with js babel, postcss, scss, svg",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"auther": "Sam Light",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@babel/core": "^7.12.10",
|
|
11
|
+
"@babel/eslint-parser": "^7.16.0",
|
|
12
|
+
"@babel/preset-env": "^7.12.11",
|
|
13
|
+
"ajv": "^8.12.0",
|
|
14
|
+
"autoprefixer": "^10.4.0",
|
|
15
|
+
"babel-loader": "^9.1.2",
|
|
16
|
+
"babel-plugin-polyfill-corejs3": "^0.10.0",
|
|
17
|
+
"clean-terminal-webpack-plugin": "^3.0.0",
|
|
18
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
19
|
+
"css-loader": "^7.0.0",
|
|
20
|
+
"eslint": "^9.0.0",
|
|
21
|
+
"eslint-webpack-plugin": "^4.0.1",
|
|
22
|
+
"glob": "^11.0.0",
|
|
23
|
+
"mini-css-extract-plugin": "^2.4.2",
|
|
24
|
+
"postcss": "^8.4.5",
|
|
25
|
+
"postcss-loader": "^8.0.0",
|
|
26
|
+
"postcss-preset-env": "^10.0.0",
|
|
27
|
+
"postcss-scss": "^4.0.2",
|
|
28
|
+
"sass": "^1.32.0",
|
|
29
|
+
"sass-loader": "^16.0.0",
|
|
30
|
+
"style-loader": "^4.0.0",
|
|
31
|
+
"stylelint": "^16.0.0",
|
|
32
|
+
"stylelint-config-recommended-scss": "^14.0.0",
|
|
33
|
+
"stylelint-config-standard": "^36.0.0",
|
|
34
|
+
"stylelint-scss": "^6.0.0",
|
|
35
|
+
"stylelint-webpack-plugin": "^5.0.0",
|
|
36
|
+
"svg-chunk-webpack-plugin": "^6.0.0",
|
|
37
|
+
"webpack": "^5.11.1",
|
|
38
|
+
"webpack-assets-manifest": "^5.0.6",
|
|
39
|
+
"webpack-cli": "^5.1.1",
|
|
40
|
+
"webpack-notifier": "^1.12.0",
|
|
41
|
+
"webpackbar": "^6.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/readme.md
ADDED
|
File without changes
|