proteum 1.0.0-1
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/.dockerignore +10 -0
- package/Rte.zip +0 -0
- package/cli/app/config.ts +54 -0
- package/cli/app/index.ts +195 -0
- package/cli/bin.js +11 -0
- package/cli/commands/build.ts +34 -0
- package/cli/commands/deploy/app.ts +29 -0
- package/cli/commands/deploy/web.ts +60 -0
- package/cli/commands/dev.ts +109 -0
- package/cli/commands/init.ts +85 -0
- package/cli/compiler/client/identite.ts +72 -0
- package/cli/compiler/client/index.ts +334 -0
- package/cli/compiler/common/babel/index.ts +170 -0
- package/cli/compiler/common/babel/plugins/index.ts +0 -0
- package/cli/compiler/common/babel/plugins/services.ts +579 -0
- package/cli/compiler/common/babel/routes/imports.ts +127 -0
- package/cli/compiler/common/babel/routes/routes.ts +1130 -0
- package/cli/compiler/common/files/autres.ts +39 -0
- package/cli/compiler/common/files/images.ts +35 -0
- package/cli/compiler/common/files/style.ts +78 -0
- package/cli/compiler/common/index.ts +154 -0
- package/cli/compiler/index.ts +532 -0
- package/cli/compiler/server/index.ts +211 -0
- package/cli/index.ts +189 -0
- package/cli/paths.ts +165 -0
- package/cli/print.ts +12 -0
- package/cli/tsconfig.json +38 -0
- package/cli/utils/index.ts +22 -0
- package/cli/utils/keyboard.ts +78 -0
- package/client/app/component.tsx +54 -0
- package/client/app/index.ts +142 -0
- package/client/app/service.ts +34 -0
- package/client/app.tsconfig.json +28 -0
- package/client/components/Button.tsx +298 -0
- package/client/components/Dialog/Manager.tsx +309 -0
- package/client/components/Dialog/card.tsx +208 -0
- package/client/components/Dialog/index.less +151 -0
- package/client/components/Dialog/status.less +176 -0
- package/client/components/Dialog/status.tsx +48 -0
- package/client/components/index.ts +2 -0
- package/client/components/types.d.ts +3 -0
- package/client/data/input.ts +32 -0
- package/client/global.d.ts +5 -0
- package/client/hooks.ts +22 -0
- package/client/index.ts +6 -0
- package/client/pages/_layout/index.less +6 -0
- package/client/pages/_layout/index.tsx +43 -0
- package/client/pages/bug.tsx.old +60 -0
- package/client/pages/useHeader.tsx +50 -0
- package/client/services/captcha/index.ts +67 -0
- package/client/services/router/components/Link.tsx +46 -0
- package/client/services/router/components/Page.tsx +55 -0
- package/client/services/router/components/router.tsx +218 -0
- package/client/services/router/index.tsx +521 -0
- package/client/services/router/request/api.ts +267 -0
- package/client/services/router/request/history.ts +5 -0
- package/client/services/router/request/index.ts +53 -0
- package/client/services/router/request/multipart.ts +147 -0
- package/client/services/router/response/index.tsx +128 -0
- package/client/services/router/response/page.ts +86 -0
- package/client/services/socket/index.ts +147 -0
- package/client/utils/dom.ts +77 -0
- package/common/app/index.ts +9 -0
- package/common/data/chaines/index.ts +54 -0
- package/common/data/dates.ts +179 -0
- package/common/data/markdown.ts +73 -0
- package/common/data/rte/nodes.ts +83 -0
- package/common/data/stats.ts +90 -0
- package/common/errors/index.tsx +326 -0
- package/common/router/index.ts +213 -0
- package/common/router/layouts.ts +93 -0
- package/common/router/register.ts +55 -0
- package/common/router/request/api.ts +77 -0
- package/common/router/request/index.ts +35 -0
- package/common/router/response/index.ts +45 -0
- package/common/router/response/page.ts +128 -0
- package/common/utils/rte.ts +183 -0
- package/common/utils.ts +7 -0
- package/doc/TODO.md +71 -0
- package/doc/front/router.md +27 -0
- package/doc/workspace/workspace.png +0 -0
- package/doc/workspace/workspace2.png +0 -0
- package/doc/workspace/workspace_26.01.22.png +0 -0
- package/package.json +171 -0
- package/server/app/commands.ts +141 -0
- package/server/app/container/config.ts +203 -0
- package/server/app/container/console/index.ts +550 -0
- package/server/app/container/index.ts +137 -0
- package/server/app/index.ts +273 -0
- package/server/app/service/container.ts +88 -0
- package/server/app/service/index.ts +235 -0
- package/server/app.tsconfig.json +28 -0
- package/server/context.ts +4 -0
- package/server/index.ts +4 -0
- package/server/services/auth/index.ts +250 -0
- package/server/services/auth/old.ts +277 -0
- package/server/services/auth/router/index.ts +95 -0
- package/server/services/auth/router/request.ts +54 -0
- package/server/services/auth/router/service.json +6 -0
- package/server/services/auth/service.json +6 -0
- package/server/services/cache/commands.ts +41 -0
- package/server/services/cache/index.ts +297 -0
- package/server/services/cache/service.json +6 -0
- package/server/services/cron/CronTask.ts +86 -0
- package/server/services/cron/index.ts +112 -0
- package/server/services/cron/service.json +6 -0
- package/server/services/disks/driver.ts +103 -0
- package/server/services/disks/drivers/local/index.ts +188 -0
- package/server/services/disks/drivers/local/service.json +6 -0
- package/server/services/disks/drivers/s3/index.ts +301 -0
- package/server/services/disks/drivers/s3/service.json +6 -0
- package/server/services/disks/index.ts +90 -0
- package/server/services/disks/service.json +6 -0
- package/server/services/email/index.ts +188 -0
- package/server/services/email/utils.ts +53 -0
- package/server/services/fetch/index.ts +201 -0
- package/server/services/fetch/service.json +7 -0
- package/server/services/models.7z +0 -0
- package/server/services/prisma/Facet.ts +142 -0
- package/server/services/prisma/index.ts +201 -0
- package/server/services/prisma/service.json +6 -0
- package/server/services/router/http/index.ts +217 -0
- package/server/services/router/http/multipart.ts +102 -0
- package/server/services/router/http/session.ts.old +40 -0
- package/server/services/router/index.ts +801 -0
- package/server/services/router/request/api.ts +87 -0
- package/server/services/router/request/index.ts +184 -0
- package/server/services/router/request/service.ts +21 -0
- package/server/services/router/request/validation/zod.ts +180 -0
- package/server/services/router/response/index.ts +338 -0
- package/server/services/router/response/mask/Filter.ts +323 -0
- package/server/services/router/response/mask/index.ts +60 -0
- package/server/services/router/response/mask/selecteurs.ts +92 -0
- package/server/services/router/response/page/document.tsx +160 -0
- package/server/services/router/response/page/index.tsx +196 -0
- package/server/services/router/service.json +6 -0
- package/server/services/router/service.ts +36 -0
- package/server/services/schema/index.ts +44 -0
- package/server/services/schema/request.ts +49 -0
- package/server/services/schema/router/index.ts +28 -0
- package/server/services/schema/router/service.json +6 -0
- package/server/services/schema/service.json +6 -0
- package/server/services/security/encrypt/aes/index.ts +85 -0
- package/server/services/security/encrypt/aes/service.json +6 -0
- package/server/services/socket/index.ts +162 -0
- package/server/services/socket/scope.ts +226 -0
- package/server/services/socket/service.json +6 -0
- package/server/services_old/SocketClient.ts +92 -0
- package/server/services_old/Token.old.ts +97 -0
- package/server/utils/slug.ts +79 -0
- package/tsconfig.common.json +45 -0
- package/tsconfig.json +3 -0
- package/types/aliases.d.ts +54 -0
- package/types/global/modules.d.ts +49 -0
- package/types/global/utils.d.ts +103 -0
- package/types/icons.d.ts +1 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// Npm
|
|
6
|
+
import webpack from 'webpack';
|
|
7
|
+
import fs from 'fs-extra';
|
|
8
|
+
|
|
9
|
+
// Plugins
|
|
10
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
11
|
+
// Optimisations
|
|
12
|
+
const BrotliCompression = require("brotli-webpack-plugin");
|
|
13
|
+
import CompressionPlugin from "compression-webpack-plugin";
|
|
14
|
+
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
|
|
15
|
+
const imageminWebp = require('imagemin-webp');
|
|
16
|
+
const { extendDefaultPlugins } = require("svgo");
|
|
17
|
+
// Ressources
|
|
18
|
+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
|
19
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
20
|
+
import WebpackAssetsManifest from 'webpack-assets-manifest';
|
|
21
|
+
// Dev
|
|
22
|
+
import PreactRefreshPlugin from '@prefresh/webpack';
|
|
23
|
+
|
|
24
|
+
// Core
|
|
25
|
+
import createCommonConfig, { TCompileMode, regex } from '../common';
|
|
26
|
+
import identityAssets from './identite';
|
|
27
|
+
import cli from '../..';
|
|
28
|
+
|
|
29
|
+
// Type
|
|
30
|
+
import type { App } from '../../app';
|
|
31
|
+
|
|
32
|
+
const debug = false;
|
|
33
|
+
|
|
34
|
+
/*----------------------------------
|
|
35
|
+
- CONFIG
|
|
36
|
+
----------------------------------*/
|
|
37
|
+
export default function createCompiler( app: App, mode: TCompileMode ): webpack.Configuration {
|
|
38
|
+
|
|
39
|
+
console.info(`Creating compiler for client (${mode}).`);
|
|
40
|
+
const dev = mode === 'dev';
|
|
41
|
+
|
|
42
|
+
const commonConfig = createCommonConfig(app, 'client', mode);
|
|
43
|
+
|
|
44
|
+
// Pas besoin d'attendre que les assets soient générés pour lancer la compilation
|
|
45
|
+
identityAssets(app);
|
|
46
|
+
|
|
47
|
+
// Symlinks to public
|
|
48
|
+
/*const publicDirs = fs.readdirSync(app.paths.root + '/public');
|
|
49
|
+
for (const publicDir of publicDirs)
|
|
50
|
+
fs.symlinkSync(
|
|
51
|
+
app.paths.root + '/public/' + publicDir,
|
|
52
|
+
app.paths.public + '/' + publicDir
|
|
53
|
+
);*/
|
|
54
|
+
|
|
55
|
+
// Convert tsconfig cli.paths to webpack aliases
|
|
56
|
+
const { aliases } = app.aliases.client.forWebpack({
|
|
57
|
+
modulesPath: app.paths.root + '/node_modules'
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// We're not supposed in any case to import server libs from client
|
|
61
|
+
delete aliases["@server"];
|
|
62
|
+
delete aliases["@/server"];
|
|
63
|
+
|
|
64
|
+
debug && console.log("client aliases", aliases);
|
|
65
|
+
const config: webpack.Configuration = {
|
|
66
|
+
|
|
67
|
+
...commonConfig,
|
|
68
|
+
|
|
69
|
+
name: 'client',
|
|
70
|
+
target: 'web',
|
|
71
|
+
entry: {
|
|
72
|
+
client: [
|
|
73
|
+
/*...(dev ? [
|
|
74
|
+
process.env.framework + '/cli/compilation/webpack/libs/webpackHotDevClient.js',
|
|
75
|
+
// https://github.com/webpack-contrib/webpack-hot-middleware#config
|
|
76
|
+
cli.paths.core.root + '/node_modules' + '/webpack-hot-middleware/client?name=client&reload=true',
|
|
77
|
+
] : []),*/
|
|
78
|
+
cli.paths.core.root + '/client/index.ts'
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
output: {
|
|
83
|
+
|
|
84
|
+
pathinfo: dev,
|
|
85
|
+
path: app.paths.bin + '/public',
|
|
86
|
+
filename: '[name].js', // Output client.js
|
|
87
|
+
assetModuleFilename: '[hash][ext]',
|
|
88
|
+
|
|
89
|
+
chunkFilename: dev
|
|
90
|
+
? '[name].js'
|
|
91
|
+
: '[id].[hash:8].js'
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
resolve: {
|
|
95
|
+
|
|
96
|
+
...commonConfig.resolve,
|
|
97
|
+
|
|
98
|
+
alias: aliases,
|
|
99
|
+
|
|
100
|
+
// RAPPEL: on a besoin de résoudre les node_modules
|
|
101
|
+
extensions: [".mjs", '.ts', '.tsx', ".jsx", ".js", ".json", ".sql"],
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
module: {
|
|
105
|
+
// Make missing exports an error instead of warning
|
|
106
|
+
strictExportPresence: true,
|
|
107
|
+
|
|
108
|
+
rules: [
|
|
109
|
+
{
|
|
110
|
+
test: regex.scripts,
|
|
111
|
+
include: [
|
|
112
|
+
|
|
113
|
+
app.paths.root + '/client',
|
|
114
|
+
cli.paths.core.root + '/client',
|
|
115
|
+
|
|
116
|
+
app.paths.root + '/common',
|
|
117
|
+
cli.paths.core.root + '/common',
|
|
118
|
+
|
|
119
|
+
app.paths.root + '/server/.generated/models.ts',
|
|
120
|
+
|
|
121
|
+
],
|
|
122
|
+
rules: require('../common/babel')(app, 'client', dev)
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
// Les pages étan tà la fois compilées dans le bundle client et serveur
|
|
126
|
+
// On ne compile les ressources (css) qu'une seule fois
|
|
127
|
+
{
|
|
128
|
+
test: regex.style,
|
|
129
|
+
rules: require('../common/files/style')(app, dev, true),
|
|
130
|
+
|
|
131
|
+
// Don't consider CSS imports dead code even if the
|
|
132
|
+
// containing package claims to have no side effects.
|
|
133
|
+
// Remove this when webpack adds a warning or an error for this.
|
|
134
|
+
// See https://github.com/webpack/webpack/issues/6571
|
|
135
|
+
sideEffects: true,
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
...require('../common/files/images')(app, dev, true),
|
|
139
|
+
|
|
140
|
+
...require('../common/files/autres')(app, dev, true),
|
|
141
|
+
|
|
142
|
+
// Exclude dev modules from production build
|
|
143
|
+
/*...(dev ? [] : [
|
|
144
|
+
{
|
|
145
|
+
test: app.paths.root + '/node_modules/react-deep-force-update/lib/index.js'),
|
|
146
|
+
loader: 'null-loader',
|
|
147
|
+
},
|
|
148
|
+
]),*/
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
plugins: [
|
|
153
|
+
|
|
154
|
+
...(commonConfig.plugins || []),
|
|
155
|
+
|
|
156
|
+
new MiniCssExtractPlugin({
|
|
157
|
+
|
|
158
|
+
}),
|
|
159
|
+
|
|
160
|
+
// Emit a file with assets cli.paths
|
|
161
|
+
// https://github.com/webdeveric/webpack-assets-manifest#options
|
|
162
|
+
new WebpackAssetsManifest({
|
|
163
|
+
output: app.paths.root + `/bin/asset-manifest.json`,
|
|
164
|
+
publicPath: true,
|
|
165
|
+
writeToDisk: true, // Force la copie du fichier sur e disque, au lieu d'en mémoire en mode dev
|
|
166
|
+
customize: ({ key, value }) => {
|
|
167
|
+
// You can prevent adding items to the manifest by returning false.
|
|
168
|
+
if (key.toLowerCase().endsWith('.map')) return false;
|
|
169
|
+
return { key, value };
|
|
170
|
+
},
|
|
171
|
+
done: (manifest, stats) => {
|
|
172
|
+
// Write chunk-manifest.json.json
|
|
173
|
+
const chunkFileName = app.paths.root + `/bin/chunk-manifest.json`;
|
|
174
|
+
try {
|
|
175
|
+
const fileFilter = file => !file.endsWith('.map');
|
|
176
|
+
const addPath = file => manifest.getPublicPath(file);
|
|
177
|
+
const chunkFiles = stats.compilation.chunkGroups.reduce((acc, c) => {
|
|
178
|
+
acc[c.name] = [
|
|
179
|
+
...(acc[c.name] || []),
|
|
180
|
+
...c.chunks.reduce(
|
|
181
|
+
(files, cc) => [
|
|
182
|
+
...files,
|
|
183
|
+
...[...cc.files].filter(fileFilter).map(addPath),
|
|
184
|
+
],
|
|
185
|
+
[],
|
|
186
|
+
),
|
|
187
|
+
];
|
|
188
|
+
return acc;
|
|
189
|
+
}, Object.create(null));
|
|
190
|
+
fs.writeFileSync(chunkFileName, JSON.stringify(chunkFiles, null, 4));
|
|
191
|
+
} catch (err) {
|
|
192
|
+
console.error(`ERROR: Cannot write ${chunkFileName}: `, err);
|
|
193
|
+
if (!dev) process.exit(1);
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
197
|
+
|
|
198
|
+
...(dev ? [
|
|
199
|
+
|
|
200
|
+
// HMR pour preact
|
|
201
|
+
//new PreactRefreshPlugin(),
|
|
202
|
+
|
|
203
|
+
] : [
|
|
204
|
+
|
|
205
|
+
/*new MomentLocalesPlugin({
|
|
206
|
+
localesToKeep: ['fr'],
|
|
207
|
+
}),*/
|
|
208
|
+
|
|
209
|
+
/*new CompressionPlugin({
|
|
210
|
+
cache: true,
|
|
211
|
+
minRatio: 0.99
|
|
212
|
+
}),
|
|
213
|
+
|
|
214
|
+
new BrotliCompression({
|
|
215
|
+
algorithm: 'gzip',
|
|
216
|
+
test: /\.js$|\.css$|\.html$/,
|
|
217
|
+
threshold: 10240,
|
|
218
|
+
minRatio: 0.8,
|
|
219
|
+
})*/
|
|
220
|
+
|
|
221
|
+
/*new webpack.HashedModuleIdsPlugin({
|
|
222
|
+
hashFunction: 'sha256',
|
|
223
|
+
hashDigest: 'hex',
|
|
224
|
+
hashDigestLength: 20,
|
|
225
|
+
}),*/
|
|
226
|
+
|
|
227
|
+
/*new PurgecssPlugin({}),*/
|
|
228
|
+
]),
|
|
229
|
+
],
|
|
230
|
+
|
|
231
|
+
// https://webpack.js.org/configuration/devtool/#devtool
|
|
232
|
+
devtool: 'source-map',
|
|
233
|
+
/*devServer: {
|
|
234
|
+
hot: true,
|
|
235
|
+
},*/
|
|
236
|
+
|
|
237
|
+
optimization: {
|
|
238
|
+
|
|
239
|
+
// Code splitting serveur = même que client
|
|
240
|
+
// La décomposition des chunks doit toujours être la même car le rendu des pages dépend de cette organisation
|
|
241
|
+
|
|
242
|
+
// https://webpack.js.org/plugins/split-chunks-plugin/#configuration
|
|
243
|
+
splitChunks: {
|
|
244
|
+
|
|
245
|
+
// This indicates which chunks will be selected for optimization
|
|
246
|
+
chunks: 'async',
|
|
247
|
+
// Minimum size, in bytes, for a chunk to be generated.
|
|
248
|
+
// Pour les imports async (ex: pages), on crée systématiquemen un chunk séparé
|
|
249
|
+
// Afin que le css d'une page ne soit appliqué qu'à la page concernée
|
|
250
|
+
cacheGroups: {
|
|
251
|
+
defaultVendors: {
|
|
252
|
+
test: (module) => {
|
|
253
|
+
// Check if the module is in node_modules but not in node_modules/proteum
|
|
254
|
+
return /[\\/]node_modules[\\/]/.test(module.context) && !/[\\/]node_modules[\\/]proteum[\\/]/.test(module.context);
|
|
255
|
+
},
|
|
256
|
+
priority: -10,
|
|
257
|
+
reuseExistingChunk: true,
|
|
258
|
+
},
|
|
259
|
+
default: {
|
|
260
|
+
minChunks: 2,
|
|
261
|
+
priority: -20,
|
|
262
|
+
reuseExistingChunk: true,
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
// Production
|
|
268
|
+
...(dev ? {} : {
|
|
269
|
+
|
|
270
|
+
// https://github.com/react-boilerplate/react-boilerplate/blob/master/internals/webpack/webpack.prod.babel.js
|
|
271
|
+
minimize: true,
|
|
272
|
+
removeAvailableModules: true,
|
|
273
|
+
minimizer: [
|
|
274
|
+
new TerserPlugin({
|
|
275
|
+
terserOptions: {
|
|
276
|
+
parse: {
|
|
277
|
+
// We want terser to parse ecma 8 code. However, we don't want it
|
|
278
|
+
// to apply any minification steps that turns valid ecma 5 code
|
|
279
|
+
// into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
280
|
+
// sections only apply transformations that are ecma 5 safe
|
|
281
|
+
// https://github.com/facebook/create-react-app/pull/4234
|
|
282
|
+
ecma: 8,
|
|
283
|
+
},
|
|
284
|
+
compress: {
|
|
285
|
+
ecma: 5,
|
|
286
|
+
warnings: false,
|
|
287
|
+
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
288
|
+
// https://github.com/facebook/create-react-app/issues/2376
|
|
289
|
+
// Pending further investigation:
|
|
290
|
+
// https://github.com/mishoo/UglifyJS2/issues/2011
|
|
291
|
+
comparisons: false,
|
|
292
|
+
// Disabled because of an issue with Terser breaking valid code:
|
|
293
|
+
// https://github.com/facebook/create-react-app/issues/5250
|
|
294
|
+
// Pending further investigation:
|
|
295
|
+
// https://github.com/terser-js/terser/issues/120
|
|
296
|
+
inline: 2,
|
|
297
|
+
},
|
|
298
|
+
mangle: {
|
|
299
|
+
safari10: true,
|
|
300
|
+
},
|
|
301
|
+
output: {
|
|
302
|
+
ecma: 5,
|
|
303
|
+
comments: false,
|
|
304
|
+
// Turned on because emoji and regex is not minified properly using default
|
|
305
|
+
// https://github.com/facebook/create-react-app/issues/2488
|
|
306
|
+
ascii_only: true,
|
|
307
|
+
},
|
|
308
|
+
}
|
|
309
|
+
}),
|
|
310
|
+
|
|
311
|
+
...(dev ? [] : [
|
|
312
|
+
new CssMinimizerPlugin()
|
|
313
|
+
]),
|
|
314
|
+
|
|
315
|
+
/*new ImageMinimizerPlugin({
|
|
316
|
+
// (optional) add generators; you can also just import &format=webp (see below)
|
|
317
|
+
generator: [
|
|
318
|
+
{
|
|
319
|
+
preset: "webp",
|
|
320
|
+
implementation: ImageMinimizerPlugin.imageminGenerate,
|
|
321
|
+
options: { plugins: ["imagemin-webp"] }
|
|
322
|
+
}
|
|
323
|
+
]
|
|
324
|
+
})*/
|
|
325
|
+
],
|
|
326
|
+
nodeEnv: 'production',
|
|
327
|
+
sideEffects: true,
|
|
328
|
+
}),
|
|
329
|
+
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
return config;
|
|
334
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// Npm
|
|
6
|
+
import type webpack from 'webpack';
|
|
7
|
+
import PresetBabel, { Options } from '@babel/preset-env';
|
|
8
|
+
|
|
9
|
+
import cli from '@cli';
|
|
10
|
+
import type { TAppSide, App } from '@cli/app';
|
|
11
|
+
|
|
12
|
+
/*----------------------------------
|
|
13
|
+
- REGLES
|
|
14
|
+
----------------------------------*/
|
|
15
|
+
module.exports = (app: App, side: TAppSide, dev: boolean): webpack.RuleSetRule[] => {
|
|
16
|
+
|
|
17
|
+
const babelPresetEnvConfig: Options = side === 'client' ? {
|
|
18
|
+
|
|
19
|
+
// Ajoute automatiquement les polyfills babel
|
|
20
|
+
// https://stackoverflow.com/a/61517521/12199605
|
|
21
|
+
"useBuiltIns": "usage", // alternative mode: "entry"
|
|
22
|
+
"corejs": 3, // default would be 2
|
|
23
|
+
|
|
24
|
+
targets: {
|
|
25
|
+
browsers: dev
|
|
26
|
+
? 'last 2 versions'
|
|
27
|
+
: app.packageJson.browserslist,
|
|
28
|
+
},
|
|
29
|
+
forceAllTransforms: !dev, // for UglifyJS
|
|
30
|
+
modules: false,
|
|
31
|
+
debug: false,
|
|
32
|
+
bugfixes: !dev
|
|
33
|
+
} : {
|
|
34
|
+
targets: {
|
|
35
|
+
node: true,//pkg.engines.node.match(/(\d+\.?)+/)[0],
|
|
36
|
+
},
|
|
37
|
+
modules: false,
|
|
38
|
+
useBuiltIns: false,
|
|
39
|
+
debug: false,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return [{
|
|
43
|
+
loader: require.resolve('babel-loader'),
|
|
44
|
+
exclude: (filePath) => {
|
|
45
|
+
// 1) If not in "node_modules" at all => transpile it
|
|
46
|
+
if (!filePath.includes('node_modules')) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 2) If it’s "node_modules/proteum" but NOT "node_modules/proteum/node_modules",
|
|
51
|
+
// then transpile. Otherwise, exclude.
|
|
52
|
+
if (
|
|
53
|
+
filePath.includes('node_modules/proteum') &&
|
|
54
|
+
!filePath.includes('node_modules/proteum/node_modules')
|
|
55
|
+
) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 3) Everything else in node_modules is excluded
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
options: {
|
|
63
|
+
|
|
64
|
+
// https://github.com/babel/babel-loader#options
|
|
65
|
+
|
|
66
|
+
// ATTENTION: Ne prend pas toujours compte des màj des plugins babel
|
|
67
|
+
cacheDirectory: cli.args.cache === true,
|
|
68
|
+
// Désactive car ralenti compilation
|
|
69
|
+
cacheCompression: false,
|
|
70
|
+
|
|
71
|
+
compact: !dev,
|
|
72
|
+
|
|
73
|
+
// https://babeljs.io/docs/usage/options/
|
|
74
|
+
babelrc: false,
|
|
75
|
+
presets: [
|
|
76
|
+
|
|
77
|
+
// https://github.com/babel/babel-preset-env
|
|
78
|
+
[PresetBabel, babelPresetEnvConfig],
|
|
79
|
+
|
|
80
|
+
[require("@babel/preset-typescript"), {
|
|
81
|
+
useDefineForClassFields: true,
|
|
82
|
+
//jsxPragma: "h"
|
|
83
|
+
}],
|
|
84
|
+
|
|
85
|
+
// JSX
|
|
86
|
+
// https://github.com/babel/babel/tree/master/packages/babel-preset-react
|
|
87
|
+
[require('@babel/preset-react'), {
|
|
88
|
+
//pragma: "h"
|
|
89
|
+
development: dev
|
|
90
|
+
}],
|
|
91
|
+
|
|
92
|
+
],
|
|
93
|
+
plugins: [
|
|
94
|
+
|
|
95
|
+
// NOTE: On résoud les plugins et presets directement ici
|
|
96
|
+
// Autrement, babel-loader les cherchera dans projet/node_modules
|
|
97
|
+
|
|
98
|
+
[require("@babel/plugin-proposal-decorators"), { "legacy": true }],
|
|
99
|
+
|
|
100
|
+
[require('@babel/plugin-proposal-class-properties'), { "loose": true }],
|
|
101
|
+
|
|
102
|
+
[require('@babel/plugin-proposal-private-methods'), { "loose": true }],
|
|
103
|
+
|
|
104
|
+
// Masque erreur associée à @babel/plugin-proposal-decorators legacy: true
|
|
105
|
+
[require('@babel/plugin-proposal-private-property-in-object'), { "loose": true }],
|
|
106
|
+
|
|
107
|
+
...(dev ? [
|
|
108
|
+
|
|
109
|
+
...(side === 'client' ? [
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
] : [])
|
|
113
|
+
|
|
114
|
+
] : [
|
|
115
|
+
|
|
116
|
+
// Les 3 plugins suivants sont tirés de https://github.com/jamiebuilds/babel-react-optimize
|
|
117
|
+
|
|
118
|
+
// Remove unnecessary React propTypes from the production build
|
|
119
|
+
// https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types
|
|
120
|
+
[require('babel-plugin-transform-react-remove-prop-types')],
|
|
121
|
+
// Treat React JSX elements as value types and hoist them to the highest scope
|
|
122
|
+
// https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-constant-elements
|
|
123
|
+
[require('@babel/plugin-transform-react-constant-elements')],
|
|
124
|
+
|
|
125
|
+
// Pour du tree shaking manuel
|
|
126
|
+
// https://www.npmjs.com/package/babel-plugin-transform-imports
|
|
127
|
+
[require("babel-plugin-transform-imports"), {
|
|
128
|
+
"lodash": {
|
|
129
|
+
"transform": "lodash/${member}",
|
|
130
|
+
"preventFullImport": true
|
|
131
|
+
}
|
|
132
|
+
}],
|
|
133
|
+
|
|
134
|
+
...(side === 'client' ? [
|
|
135
|
+
|
|
136
|
+
[require('babel-plugin-transform-remove-console')],
|
|
137
|
+
|
|
138
|
+
] : [])
|
|
139
|
+
]),
|
|
140
|
+
|
|
141
|
+
require('./routes/routes')({ side, app, debug: false }),
|
|
142
|
+
|
|
143
|
+
...(side === 'client' ? [
|
|
144
|
+
|
|
145
|
+
] : [
|
|
146
|
+
|
|
147
|
+
require('./plugins/services')({ side, app, debug: false }),
|
|
148
|
+
|
|
149
|
+
]),
|
|
150
|
+
|
|
151
|
+
// Allow to import multiple fiels with one import statement thanks to glob patterns
|
|
152
|
+
require('babel-plugin-glob-import')({
|
|
153
|
+
debug: false,
|
|
154
|
+
removeAliases: (source: string) => app.paths.withoutAlias(source, side)
|
|
155
|
+
}, [
|
|
156
|
+
// Routes imports on frontend side
|
|
157
|
+
require('./routes/imports')(app, side, dev)
|
|
158
|
+
])
|
|
159
|
+
],
|
|
160
|
+
|
|
161
|
+
overrides: [
|
|
162
|
+
|
|
163
|
+
...(side === 'client' ? [
|
|
164
|
+
|
|
165
|
+
] : [
|
|
166
|
+
]),
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
}]
|
|
170
|
+
}
|
|
File without changes
|