@pplancq/react-template 2.4.5 → 2.6.0

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.
@@ -1,143 +0,0 @@
1
- #!/usr/bin/env node
2
- const { execSync } = require('child_process');
3
- const { rmSync, writeFileSync, readFileSync } = require('fs');
4
- const { resolve } = require('path');
5
-
6
- const NPM = 'npm';
7
- const YARN = 'yarn';
8
- const PNPM = 'pnpm';
9
-
10
- const runCommand = (command, options = { stdio: 'inherit' }) => {
11
- try {
12
- execSync(command, options);
13
- } catch (e) {
14
- console.error(`Failed to execute ${command}`, e);
15
- process.exit(-1);
16
- }
17
- };
18
-
19
- const getPackageManager = () => {
20
- switch (true) {
21
- case process.env.npm_config_user_agent.includes(YARN):
22
- return YARN;
23
- case process.env.npm_config_user_agent.includes(PNPM):
24
- return PNPM;
25
- default:
26
- return NPM;
27
- }
28
- };
29
-
30
- const packageManager = getPackageManager();
31
-
32
- console.info('\nremove webpack ...');
33
- runCommand(`${packageManager} remove @pplancq/webpack-config webpack webpack-cli webpack-dev-server`);
34
- rmSync(resolve(__dirname, '../webpack.config.cjs'));
35
- console.info('\ninstall vite package ...');
36
- runCommand(
37
- `${packageManager} ${packageManager === YARN ? 'add --dev' : 'install --save-dev'} vite vite-plugin-eslint2 vite-plugin-stylelint sass`,
38
- );
39
-
40
- writeFileSync(
41
- resolve(__dirname, '../vite.config.mts'),
42
- `import react from '@vitejs/plugin-react-swc'
43
- import { defineConfig, loadEnv } from 'vite'
44
- import eslintPlugin from 'vite-plugin-eslint2'
45
- import stylelintPlugin from 'vite-plugin-stylelint'
46
- import svgr from 'vite-plugin-svgr'
47
- import viteTsconfigPaths from 'vite-tsconfig-paths'
48
- import packageJson from './package.json'
49
-
50
- const resolveModule = (module: string) => {
51
- try {
52
- require.resolve(module);
53
- return true;
54
- } catch {
55
- return false;
56
- }
57
- };
58
-
59
- export default defineConfig(({ mode }) => {
60
- const env = loadEnv(mode, process.cwd(), '')
61
-
62
- const disableStyleLintPlugin =
63
- (env.DISABLE_STYLELINT_PLUGIN ?? 'false') === 'true' || !resolveModule('stylelint');
64
- const disableEsLintPlugin =
65
- (env.DISABLE_ESLINT_PLUGIN ?? 'false') === 'true' || !resolveModule('eslint');
66
- const publicUrl = env.PUBLIC_URL ?? packageJson.homepage ?? '/';
67
- const publicPath = mode === 'development'
68
- ? '/'
69
- : new URL(publicUrl.endsWith('/') ? publicUrl : \`\${publicUrl}/\`, 'http://localhost').pathname;
70
-
71
- return {
72
- plugins: [
73
- react(),
74
- viteTsconfigPaths(),
75
- svgr(),
76
- !disableEsLintPlugin && eslintPlugin({
77
- emitErrorAsWarning: true,
78
- cache: false
79
- }),
80
- !disableStyleLintPlugin && stylelintPlugin({
81
- emitErrorAsWarning: true,
82
- cache: false
83
- })
84
- ].filter(Boolean),
85
- envPrefix: env.ENV_PREFIX ?? 'FRONT_',
86
- base: publicPath,
87
- server: {
88
- port: parseInt(env.PORT ?? '3000', 10),
89
- open: (env.BROWSER ?? 'false') === 'true'
90
- },
91
- build: {
92
- sourcemap: (env.DISABLE_SOURCE_MAP ?? 'false') !== 'true',
93
- outDir: 'build',
94
- },
95
- }
96
- })
97
- `,
98
- { encoding: 'utf-8' },
99
- );
100
-
101
- let tsconfig = readFileSync(resolve(__dirname, '../tsconfig.json'), { encoding: 'utf-8' });
102
- tsconfig = tsconfig.replace('@pplancq/webpack-config', 'vite/client');
103
- writeFileSync(resolve(__dirname, '../tsconfig.json'), tsconfig, { encoding: 'utf-8' });
104
-
105
- const packagesJson = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), { encoding: 'utf-8' }));
106
- const { start, build, 'migrate:vite': a, 'start:mock': b, ...scripts } = packagesJson.scripts;
107
- packagesJson.scripts = {
108
- start: 'vite',
109
- build: 'vite build',
110
- preview: 'vite preview',
111
- 'start:mock': 'vite --mode mock',
112
- ...scripts,
113
- };
114
- writeFileSync(resolve(__dirname, '../package.json'), JSON.stringify(packagesJson, null, 2), { encoding: 'utf-8' });
115
-
116
- let indexHTML = readFileSync(resolve(__dirname, '../public/index.html'), { encoding: 'utf-8' });
117
- indexHTML = indexHTML.replace(' </body>', ' <script type="module" src="/src/main.ts"></script>\n </body>');
118
- writeFileSync(resolve(__dirname, '../index.html'), indexHTML, { encoding: 'utf-8' });
119
- rmSync(resolve(__dirname, '../public/index.html'));
120
-
121
- let envFile = readFileSync(resolve(__dirname, '../.env'), { encoding: 'utf-8' });
122
- envFile = envFile.replace(
123
- `
124
-
125
- # Specify the type of configuration to use with ESLint.
126
- # - 'eslintrc' is the classic configuration format available in most ESLint versions.
127
- # - 'flat' is the new format introduced in ESLint 8.21.0.
128
- # Default is 'eslintrc'
129
- ESLINT_CONFIG_TYPE='flat'`,
130
- '',
131
- );
132
- writeFileSync(resolve(__dirname, '../.env'), envFile, { encoding: 'utf-8' });
133
-
134
- writeFileSync(
135
- resolve(__dirname, '../.env.mock'),
136
- `FRONT_MOCK_ENABLE=true
137
- `,
138
- { encoding: 'utf-8' },
139
- );
140
-
141
- rmSync(resolve(__dirname, '../scripts/migrateToVite.cjs'));
142
-
143
- console.info('\nThe application has been migrate to vite');
@@ -1,22 +0,0 @@
1
- // const { ModuleFederationPlugin } = require('webpack').container;
2
-
3
- // const deps = require('./package.json').dependencies;
4
-
5
- module.exports = {
6
- extends: [require.resolve('@pplancq/webpack-config')],
7
- // plugins: [
8
- // new ModuleFederationPlugin({
9
- // name: 'reactTemplate',
10
- // filename: 'js/remoteEntry.js',
11
- // remotes: {},
12
- // exposes: {
13
- // './App': './src/bootstrap.tsx',
14
- // },
15
- // shared: {
16
- // react: { singleton: true, requiredVersion: deps.react },
17
- // 'react-dom': { singleton: true, requiredVersion: deps['react-dom'] },
18
- // 'react-router': { singleton: true, requiredVersion: deps['react-router'] },
19
- // },
20
- // }),
21
- // ],
22
- };
File without changes