@unsetsoft/ryunix-presets 0.0.6 → 1.0.14
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/package.json +55 -7
- package/rspack/index.js +92 -92
- package/vite/index.js +18 -18
- package/webpack/bin/compiler.mjs +6 -0
- package/webpack/bin/index.mjs +115 -0
- package/webpack/bin/prerender.mjs +138 -0
- package/webpack/bin/serve.mjs +101 -0
- package/webpack/config.d.ts +85 -0
- package/webpack/eslint.config.mjs +31 -0
- package/webpack/index.js +6 -0
- package/webpack/template/index.html +19 -0
- package/webpack/utils/config.cjs +190 -0
- package/webpack/utils/envExist.cjs +14 -0
- package/webpack/utils/index.mjs +203 -0
- package/webpack/utils/settingfile.cjs +33 -0
- package/webpack/webpack.config.mjs +279 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url'
|
|
2
|
+
import { dirname, join } from 'path'
|
|
3
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
|
4
|
+
import TerserPlugin from 'terser-webpack-plugin'
|
|
5
|
+
import webpack from 'webpack'
|
|
6
|
+
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
|
|
7
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
|
8
|
+
import CopyWebpackPlugin from 'copy-webpack-plugin'
|
|
9
|
+
import ESLintPlugin from 'eslint-webpack-plugin'
|
|
10
|
+
import eslintConfig from './eslint.config.mjs'
|
|
11
|
+
import {
|
|
12
|
+
getPackageManager,
|
|
13
|
+
ENV_HASH,
|
|
14
|
+
getEnviroment,
|
|
15
|
+
resolveApp,
|
|
16
|
+
RYUNIX_APP,
|
|
17
|
+
} from './utils/index.mjs'
|
|
18
|
+
import fs from 'fs'
|
|
19
|
+
import config from './utils/config.cjs'
|
|
20
|
+
import Dotenv from 'dotenv-webpack'
|
|
21
|
+
import { getPackageVersion } from './utils/index.mjs'
|
|
22
|
+
|
|
23
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
24
|
+
|
|
25
|
+
const __dirname = dirname(__filename)
|
|
26
|
+
|
|
27
|
+
let dir
|
|
28
|
+
|
|
29
|
+
const manager = getPackageManager()
|
|
30
|
+
if (manager === 'yarn' || manager === 'npm' || manager === 'bun') {
|
|
31
|
+
dir = process.cwd()
|
|
32
|
+
} else if (manager === 'pnpm') {
|
|
33
|
+
throw new Error(`The manager ${manager} is not supported.`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getAlias(object) {
|
|
37
|
+
const output = Object.entries(object)
|
|
38
|
+
.filter(([k, v]) => {
|
|
39
|
+
return true // some irrelevant conditions here
|
|
40
|
+
})
|
|
41
|
+
.reduce((accum, [k, v]) => {
|
|
42
|
+
accum[k] = resolveApp(dir, v)
|
|
43
|
+
return accum
|
|
44
|
+
}, {})
|
|
45
|
+
return output
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { version } = await getPackageVersion()
|
|
49
|
+
|
|
50
|
+
export default {
|
|
51
|
+
// context: src
|
|
52
|
+
experiments: {
|
|
53
|
+
lazyCompilation: config.webpack.experiments.lazyCompilation,
|
|
54
|
+
},
|
|
55
|
+
context: resolveApp(dir, config.webpack.root),
|
|
56
|
+
entry: './main.ryx',
|
|
57
|
+
devtool: config.webpack.production ? 'source-map' : false,
|
|
58
|
+
output: {
|
|
59
|
+
// path: .ryunix
|
|
60
|
+
path: resolveApp(dir, `${config.webpack.output.buildDirectory}/static`),
|
|
61
|
+
publicPath: '/',
|
|
62
|
+
chunkFilename: './assets/js/[name].[fullhash:8].bundle.js',
|
|
63
|
+
assetModuleFilename: './assets/media/[name].[hash][ext]',
|
|
64
|
+
filename: './assets/js/[name].[fullhash:8].bundle.js',
|
|
65
|
+
devtoolModuleFilenameTemplate: 'ryunix/[resource-path]',
|
|
66
|
+
clean: config.experimental.ssg.prerender.length > 0 ? false : true,
|
|
67
|
+
},
|
|
68
|
+
target: config.webpack.target,
|
|
69
|
+
devServer: {
|
|
70
|
+
watchFiles: [resolveApp(dir, 'src/**/*')],
|
|
71
|
+
hot: true,
|
|
72
|
+
historyApiFallback: {
|
|
73
|
+
index: '/',
|
|
74
|
+
disableDotRule: true,
|
|
75
|
+
},
|
|
76
|
+
liveReload: false,
|
|
77
|
+
headers: {
|
|
78
|
+
'Access-Control-Allow-Origin': '*',
|
|
79
|
+
'Access-Control-Allow-Methods': '*',
|
|
80
|
+
'Access-Control-Allow-Headers': '*',
|
|
81
|
+
},
|
|
82
|
+
allowedHosts: config.webpack.devServer.allowedHosts,
|
|
83
|
+
port: config.webpack.devServer.port,
|
|
84
|
+
proxy: config.webpack.devServer.proxy,
|
|
85
|
+
},
|
|
86
|
+
optimization: {
|
|
87
|
+
moduleIds: 'deterministic',
|
|
88
|
+
runtimeChunk: 'single',
|
|
89
|
+
splitChunks: {
|
|
90
|
+
chunks: 'all',
|
|
91
|
+
minSize: 20000,
|
|
92
|
+
maxSize: 70000,
|
|
93
|
+
},
|
|
94
|
+
minimize: config.webpack.production === true,
|
|
95
|
+
minimizer: config.webpack.production
|
|
96
|
+
? [
|
|
97
|
+
new TerserPlugin({
|
|
98
|
+
parallel: true,
|
|
99
|
+
terserOptions: {
|
|
100
|
+
compress: {
|
|
101
|
+
dead_code: true,
|
|
102
|
+
passes: 2,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
new CssMinimizerPlugin(),
|
|
107
|
+
]
|
|
108
|
+
: [],
|
|
109
|
+
},
|
|
110
|
+
cache: {
|
|
111
|
+
type: 'filesystem',
|
|
112
|
+
version: ENV_HASH(getEnviroment()),
|
|
113
|
+
cacheDirectory: resolveApp(
|
|
114
|
+
dir,
|
|
115
|
+
`${config.webpack.output.buildDirectory}/cache/webpack`,
|
|
116
|
+
),
|
|
117
|
+
store: 'pack',
|
|
118
|
+
buildDependencies: {
|
|
119
|
+
defaultWebpack: ['webpack/lib/'],
|
|
120
|
+
config: [__filename],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
infrastructureLogging: {
|
|
124
|
+
level: 'none',
|
|
125
|
+
},
|
|
126
|
+
stats: 'errors-warnings',
|
|
127
|
+
module: {
|
|
128
|
+
rules: [
|
|
129
|
+
{
|
|
130
|
+
test: /\.(js|jsx|ryx)$/,
|
|
131
|
+
exclude: /node_modules/,
|
|
132
|
+
use: [
|
|
133
|
+
'thread-loader',
|
|
134
|
+
{
|
|
135
|
+
loader: 'babel-loader',
|
|
136
|
+
options: {
|
|
137
|
+
presets: [
|
|
138
|
+
[
|
|
139
|
+
'@babel/preset-env',
|
|
140
|
+
{
|
|
141
|
+
targets: 'defaults and not IE 11',
|
|
142
|
+
useBuiltIns: false,
|
|
143
|
+
modules: false,
|
|
144
|
+
bugfixes: true,
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
'@babel/preset-react',
|
|
148
|
+
],
|
|
149
|
+
cacheDirectory: resolveApp(
|
|
150
|
+
dir,
|
|
151
|
+
`${config.webpack.output.buildDirectory}/cache/babel`,
|
|
152
|
+
),
|
|
153
|
+
plugins: [
|
|
154
|
+
[
|
|
155
|
+
'@babel/plugin-transform-react-jsx',
|
|
156
|
+
{
|
|
157
|
+
pragma: 'Ryunix.createElement',
|
|
158
|
+
pragmaFrag: 'Ryunix.Fragment',
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
test: /\.s[ac]ss|css$/i,
|
|
168
|
+
exclude: /node_modules/,
|
|
169
|
+
use: [
|
|
170
|
+
config.webpack.production ? MiniCssExtractPlugin.loader : 'style-loader',
|
|
171
|
+
'css-loader',
|
|
172
|
+
'sass-loader',
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
test: /\.(jpg|jpeg|png|gif|svg|ico)$/,
|
|
177
|
+
exclude: /node_modules/,
|
|
178
|
+
type: 'asset/resource',
|
|
179
|
+
generator: {
|
|
180
|
+
filename: 'assets/images/[name].[hash][ext]',
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
test: /\.(mp3|mp4|pdf)$/,
|
|
185
|
+
exclude: /node_modules/,
|
|
186
|
+
type: 'asset/resource',
|
|
187
|
+
generator: {
|
|
188
|
+
filename: 'assets/files/[name].[hash][ext]',
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
...config.webpack.module.rules,
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
resolve: {
|
|
195
|
+
alias:
|
|
196
|
+
config.webpack.resolve.alias && getAlias(config.webpack.resolve.alias),
|
|
197
|
+
extensions: [
|
|
198
|
+
'.*',
|
|
199
|
+
'.js',
|
|
200
|
+
'.jsx',
|
|
201
|
+
'.ryx',
|
|
202
|
+
...config.webpack.resolve.extensions,
|
|
203
|
+
],
|
|
204
|
+
fallback: config.webpack.resolve.fallback,
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
plugins: [
|
|
208
|
+
new webpack.HotModuleReplacementPlugin(),
|
|
209
|
+
fs.existsSync(resolveApp(dir, '.env')) &&
|
|
210
|
+
new Dotenv({
|
|
211
|
+
path: resolveApp(dir, '.env'),
|
|
212
|
+
prefix: 'ryunix.env.RYUNIX_APP_',
|
|
213
|
+
systemvars: false,
|
|
214
|
+
ignoreStub: true,
|
|
215
|
+
}),
|
|
216
|
+
new webpack.DefinePlugin({
|
|
217
|
+
'ryunix.config.env': JSON.stringify(config.experimental.env),
|
|
218
|
+
}),
|
|
219
|
+
new ESLintPlugin({
|
|
220
|
+
cwd: dir,
|
|
221
|
+
files: ['**/*.ryx', ...config.eslint.files],
|
|
222
|
+
extensions: ['js', 'ryx', 'jsx'],
|
|
223
|
+
emitError: true,
|
|
224
|
+
emitWarning: true,
|
|
225
|
+
failOnWarning: false,
|
|
226
|
+
failOnError: false,
|
|
227
|
+
overrideConfigFile: true,
|
|
228
|
+
overrideConfig: eslintConfig[0],
|
|
229
|
+
}),
|
|
230
|
+
new HtmlWebpackPlugin({
|
|
231
|
+
pageLang: config.static.seo.pageLang,
|
|
232
|
+
title: config.static.seo.title,
|
|
233
|
+
favicon: config.static.favicon
|
|
234
|
+
? join(dir, 'public', 'favicon.png')
|
|
235
|
+
: false,
|
|
236
|
+
meta: config.static.seo.meta,
|
|
237
|
+
template: config.static.customTemplate
|
|
238
|
+
? join(dir, 'public', 'index.html')
|
|
239
|
+
: join(__dirname, 'template', 'index.html'),
|
|
240
|
+
info: {
|
|
241
|
+
framework: 'Ryunix',
|
|
242
|
+
version,
|
|
243
|
+
mode: config.webpack.production ? 'production' : 'dev',
|
|
244
|
+
},
|
|
245
|
+
}),
|
|
246
|
+
config.webpack.production &&
|
|
247
|
+
new MiniCssExtractPlugin({
|
|
248
|
+
filename: 'assets/css/[name].[contenthash].css',
|
|
249
|
+
}),
|
|
250
|
+
new CopyWebpackPlugin({
|
|
251
|
+
patterns: [
|
|
252
|
+
{
|
|
253
|
+
from: resolveApp(dir, 'public'),
|
|
254
|
+
to: resolveApp(dir, `${config.webpack.output.buildDirectory}/static`),
|
|
255
|
+
// Exclude any html files (index.html or others) to avoid duplicate emission
|
|
256
|
+
// when HtmlWebpackPlugin also generates index.html from a template.
|
|
257
|
+
globOptions: {
|
|
258
|
+
ignore: ['**/template.html', '**/index.html', '**/*.html', '**/favicon.png'],
|
|
259
|
+
},
|
|
260
|
+
filter: (resourcePath) => {
|
|
261
|
+
try {
|
|
262
|
+
return !resourcePath.toLowerCase().endsWith('.html')
|
|
263
|
+
} catch (e) {
|
|
264
|
+
return true
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
noErrorOnMissing: true,
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
}),
|
|
271
|
+
...config.webpack.plugins,
|
|
272
|
+
].filter(Boolean),
|
|
273
|
+
externals: [
|
|
274
|
+
{
|
|
275
|
+
ryunix: '@unsetsoft/ryunixjs',
|
|
276
|
+
},
|
|
277
|
+
...config.webpack.externals,
|
|
278
|
+
],
|
|
279
|
+
}
|