Skip to content

Commit 656d8fd

Browse files
committed
feature: webpack 5
1 parent 33bdf7b commit 656d8fd

File tree

8 files changed

+56
-66
lines changed

8 files changed

+56
-66
lines changed

.madrun.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const is20 = process.version.startsWith('v2');
1616
// https://stackoverflow.com/a/69746937/4536327
1717
const buildEnv = (is17 || is20) && {
1818
NODE_OPTIONS: '--openssl-legacy-provider',
19+
NODE_ENV: 'production',
1920
};
2021

2122
export default {
@@ -56,6 +57,7 @@ export default {
5657
'watch:test:server': async () => `nodemon -w client -w test/client -x ${await run('test:server')}`,
5758
'watch:coverage': async () => [testEnv, `nodemon -w server -w test -w common -x ${await cutEnv('coverage')}`],
5859
'build': async () => run('6to5:*'),
60+
'postbuild': () => 'node .webpack/cp.mjs',
5961
'build:dev': async () => run('build:client:dev'),
6062
'build:client': () => run('6to5:client'),
6163
'build:client:dev': () => run('6to5:client:dev'),

.webpack/cp.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {cpSync} from 'node:fs';
2+
3+
cpSync('./css/columns', './dist-dev/columns', {
4+
recursive: true,
5+
});
6+
7+
cpSync('./css/themes', './dist-dev/themes', {
8+
recursive: true,
9+
});
10+
11+
cpSync('./css/columns', './dist/columns', {
12+
recursive: true,
13+
});
14+
15+
cpSync('./css/themes', './dist/themes', {
16+
recursive: true,
17+
});

.webpack/css.js

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,39 @@
11
'use strict';
22

3-
const {env} = require('node:process');
4-
const fs = require('node:fs');
5-
const {
6-
basename,
7-
extname,
8-
join,
9-
} = require('node:path');
3+
const {env} = require('node:process')
104

11-
const ExtractTextPlugin = require('extract-text-webpack-plugin');
125
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
6+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
137

148
const isDev = env.NODE_ENV === 'development';
159

16-
const extractCSS = (a) => new ExtractTextPlugin(`${a}.css`);
17-
const extractMain = extractCSS('[name]');
18-
19-
const cssNames = [
20-
'nojs',
21-
'view',
22-
'config',
23-
'terminal',
24-
'user-menu',
25-
...getCSSList('columns'),
26-
...getCSSList('themes'),
27-
];
28-
29-
const cssPlugins = cssNames.map(extractCSS);
3010
const clean = (a) => a.filter(Boolean);
3111

3212
const plugins = clean([
33-
...cssPlugins,
34-
extractMain,
13+
new MiniCssExtractPlugin({
14+
filename: '[name].css',
15+
}),
3516
!isDev && new OptimizeCssAssetsPlugin(),
3617
]);
3718

3819
const rules = [{
39-
test: /\.css$/,
40-
exclude: /css\/(nojs|view|config|terminal|user-menu|columns.*|themes.*)\.css/,
41-
use: extractMain.extract(['css-loader']),
42-
}, ...cssPlugins.map(extract), {
43-
test: /\.(png|gif|svg|woff|woff2|eot|ttf)$/,
44-
use: {
45-
loader: 'url-loader',
20+
test: /\.css$/i,
21+
use: [MiniCssExtractPlugin.loader, {
22+
loader: "css-loader",
4623
options: {
47-
limit: 100_000,
24+
url: true,
4825
},
49-
},
50-
}];
26+
}],
27+
}, {
28+
test: /\.(png|gif|svg|woff|woff2|eot|ttf)$/,
29+
type: 'asset/inline',
30+
}]
31+
5132

5233
module.exports = {
5334
plugins,
54-
module: {
55-
rules,
56-
},
35+
module: {
36+
rules,
37+
},
5738
};
5839

59-
function getCSSList(dir) {
60-
const base = (a) => basename(a, extname(a));
61-
const addDir = (name) => `${dir}/${name}`;
62-
const rootDir = join(__dirname, '..');
63-
64-
return fs
65-
.readdirSync(`${rootDir}/css/${dir}`)
66-
.map(base)
67-
.map(addDir);
68-
}
69-
70-
function extract(extractPlugin) {
71-
const {filename} = extractPlugin;
72-
73-
return {
74-
test: RegExp(`css/${filename}`),
75-
use: extractPlugin.extract(['css-loader']),
76-
};
77-
}

.webpack/js.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const {
77
} = require('node:path');
88

99
const {env} = require('node:process');
10-
const {EnvironmentPlugin} = require('webpack');
10+
const {EnvironmentPlugin, NormalModuleReplacementPlugin} = require('webpack');
1111
const WebpackBar = require('webpackbar');
1212

13-
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
13+
//const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
1414

1515
const modules = './modules';
1616
const dirModules = './client/modules';
@@ -46,13 +46,18 @@ const rules = clean([
4646
]);
4747

4848
const plugins = [
49+
new NormalModuleReplacementPlugin(/^node:/, (resource) => {
50+
resource.request = resource.request.replace(/^node:/, '');
51+
}),
4952
new EnvironmentPlugin({
5053
NODE_ENV,
5154
}),
55+
/*
5256
new ServiceWorkerWebpackPlugin({
5357
entry: join(__dirname, '..', 'client', 'sw', 'sw.js'),
5458
excludes: ['*'],
5559
}),
60+
*/
5661
new WebpackBar(),
5762
];
5863

@@ -68,13 +73,19 @@ module.exports = {
6873
'node:process': 'process',
6974
'node:path': 'path',
7075
},
76+
fallback: {
77+
"path": require.resolve("path-browserify"),
78+
"process": require.resolve("process/browser")
79+
}
7180
},
7281
devtool,
7382
optimization: {
7483
splitChunks,
7584
},
7685
entry: {
86+
'nojs': './css/nojs.css',
7787
cloudcmd: `${dir}/cloudcmd.js`,
88+
sw: `${dir}/sw/sw.js`,
7889
[`${modules}/edit`]: `${dirModules}/edit.js`,
7990
[`${modules}/edit-file`]: `${dirModules}/edit-file.js`,
8091
[`${modules}/edit-file-vim`]: `${dirModules}/edit-file-vim.js`,

client/css.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
require('../css/main.css');
4-
require('../css/nojs.css');
4+
//require('../css/nojs.css');
55
require('../css/columns/name-size-date.css');
66
require('../css/columns/name-size.css');
77
require('../css/themes/light.css');

client/modules/config/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ module.exports.init = async () => {
5252

5353
showLoad();
5454

55-
const {prefix} = CloudCmd;
55+
const {DIR_MODULES} = CloudCmd;
5656

5757
[Template] = await Promise.all([
5858
Files.get('config-tmpl'),
5959
loadSocket(),
60-
loadCSS(`${prefix}/dist/config.css`),
60+
loadCSS(`${DIR_MODULES}/config.css`),
6161
CloudCmd.View(),
6262
]);
6363

client/modules/view/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ function check(src) {
329329
* @callback - executes, when everything loaded
330330
*/
331331
async function loadAll() {
332-
const {DIR_DIST} = CloudCmd;
332+
const {DIR_MODULES} = CloudCmd;
333333

334334
time(`${Name} load`);
335335

336336
Loading = true;
337-
await loadCSS(`${DIR_DIST}/view.css`);
337+
await loadCSS(`${DIR_MODULES}/view.css`);
338338
Loading = false;
339339
}
340340

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"watch:lint": "madrun watch:lint",
5353
"fresh:lint": "madrun fresh:lint",
5454
"lint:fresh": "madrun lint:fresh",
55-
"spell": "madrun spell",
5655
"fix:lint": "madrun fix:lint",
5756
"lint:stream": "madrun lint:stream",
5857
"test": "madrun test",
@@ -66,8 +65,6 @@
6665
"6to5": "madrun 6to5",
6766
"6to5:client": "madrun 6to5:client",
6867
"6to5:client:dev": "madrun 6to5:client:dev",
69-
"pre6to5:client": "madrun pre6to5:client",
70-
"pre6to5:client:dev": "madrun pre6to5:client:dev",
7168
"watch:client": "madrun watch:client",
7269
"watch:client:dev": "madrun watch:client:dev",
7370
"watch:server": "madrun watch:server",
@@ -76,6 +73,7 @@
7673
"watch:test:server": "madrun watch:test:server",
7774
"watch:coverage": "madrun watch:coverage",
7875
"build": "madrun build",
76+
"postbuild": "madrun postbuild",
7977
"build:dev": "madrun build:dev",
8078
"build:client": "madrun build:client",
8179
"build:client:dev": "madrun build:client:dev",

0 commit comments

Comments
 (0)