shakapacker 9.0.0.beta.6 → 9.0.0.beta.8
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.
- checksums.yaml +4 -4
- data/.eslintrc.fast.js +40 -0
- data/.eslintrc.js +48 -0
- data/.github/workflows/generator.yml +6 -0
- data/.gitignore +1 -4
- data/.npmignore +56 -0
- data/CHANGELOG.md +64 -1
- data/CONTRIBUTING.md +75 -21
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/TODO.md +15 -16
- data/docs/transpiler-migration.md +191 -0
- data/docs/typescript-migration.md +378 -0
- data/lib/install/template.rb +54 -7
- data/lib/shakapacker/version.rb +1 -1
- data/package/.npmignore +4 -0
- data/package/babel/preset.ts +56 -0
- data/package/config.ts +23 -10
- data/package/env.ts +15 -2
- data/package/environments/{development.js → development.ts} +30 -8
- data/package/environments/{production.js → production.ts} +18 -4
- data/package/environments/test.ts +53 -0
- data/package/environments/types.ts +90 -0
- data/package/esbuild/index.ts +42 -0
- data/package/optimization/rspack.ts +36 -0
- data/package/optimization/{webpack.js → webpack.ts} +12 -4
- data/package/plugins/{rspack.js → rspack.ts} +20 -5
- data/package/plugins/{webpack.js → webpack.ts} +2 -2
- data/package/rspack/{index.js → index.ts} +17 -10
- data/package/rules/{babel.js → babel.ts} +1 -1
- data/package/rules/{coffee.js → coffee.ts} +1 -1
- data/package/rules/{css.js → css.ts} +1 -1
- data/package/rules/{erb.js → erb.ts} +1 -1
- data/package/rules/{esbuild.js → esbuild.ts} +2 -2
- data/package/rules/{file.js → file.ts} +11 -6
- data/package/rules/{jscommon.js → jscommon.ts} +4 -4
- data/package/rules/{less.js → less.ts} +3 -3
- data/package/rules/raw.ts +25 -0
- data/package/rules/{rspack.js → rspack.ts} +21 -11
- data/package/rules/{sass.js → sass.ts} +1 -1
- data/package/rules/{stylus.js → stylus.ts} +3 -7
- data/package/rules/{swc.js → swc.ts} +2 -2
- data/package/rules/{webpack.js → webpack.ts} +1 -1
- data/package/swc/index.ts +54 -0
- data/package/types/README.md +87 -0
- data/package/types/index.ts +60 -0
- data/package/utils/errorCodes.ts +219 -0
- data/package/utils/errorHelpers.ts +68 -2
- data/package/utils/pathValidation.ts +139 -0
- data/package/utils/typeGuards.ts +161 -47
- data/package.json +26 -4
- data/scripts/remove-use-strict.js +45 -0
- data/scripts/type-check-no-emit.js +27 -0
- data/test/package/rules/raw.test.js +40 -7
- data/test/package/rules/webpack.test.js +21 -2
- data/test/package/transpiler-defaults.test.js +127 -0
- data/test/scripts/remove-use-strict.test.js +125 -0
- data/test/typescript/build.test.js +3 -2
- data/test/typescript/environments.test.js +107 -0
- data/test/typescript/pathValidation.test.js +142 -0
- data/test/typescript/securityValidation.test.js +182 -0
- data/tsconfig.eslint.json +16 -0
- data/tsconfig.json +9 -10
- data/yarn.lock +415 -6
- metadata +50 -28
- data/package/babel/preset.js +0 -48
- data/package/environments/base.js +0 -103
- data/package/environments/test.js +0 -19
- data/package/esbuild/index.js +0 -40
- data/package/optimization/rspack.js +0 -29
- data/package/rules/raw.js +0 -15
- data/package/swc/index.js +0 -50
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shakapacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.0.0.beta.
|
4
|
+
version: 9.0.0.beta.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -132,6 +132,7 @@ extensions: []
|
|
132
132
|
extra_rdoc_files: []
|
133
133
|
files:
|
134
134
|
- ".eslintignore"
|
135
|
+
- ".eslintrc.fast.js"
|
135
136
|
- ".eslintrc.js"
|
136
137
|
- ".github/FUNDING.yml"
|
137
138
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
@@ -147,6 +148,7 @@ files:
|
|
147
148
|
- ".github/workflows/test-bundlers.yml"
|
148
149
|
- ".gitignore"
|
149
150
|
- ".node-version"
|
151
|
+
- ".npmignore"
|
150
152
|
- ".rspec"
|
151
153
|
- ".rubocop.yml"
|
152
154
|
- ".yalcignore"
|
@@ -180,8 +182,10 @@ files:
|
|
180
182
|
- docs/sprockets.md
|
181
183
|
- docs/style_loader_vs_mini_css.md
|
182
184
|
- docs/subresource_integrity.md
|
185
|
+
- docs/transpiler-migration.md
|
183
186
|
- docs/transpiler-performance.md
|
184
187
|
- docs/troubleshooting.md
|
188
|
+
- docs/typescript-migration.md
|
185
189
|
- docs/typescript.md
|
186
190
|
- docs/using_esbuild_loader.md
|
187
191
|
- docs/using_swc_loader.md
|
@@ -248,47 +252,52 @@ files:
|
|
248
252
|
- lib/tasks/shakapacker/verify_config.rake
|
249
253
|
- lib/tasks/shakapacker/verify_install.rake
|
250
254
|
- package.json
|
251
|
-
- package
|
255
|
+
- package/.npmignore
|
256
|
+
- package/babel/preset.ts
|
252
257
|
- package/config.ts
|
253
258
|
- package/dev_server.ts
|
254
259
|
- package/env.ts
|
255
|
-
- package/environments/base.js
|
256
260
|
- package/environments/base.ts
|
257
|
-
- package/environments/development.
|
258
|
-
- package/environments/production.
|
259
|
-
- package/environments/test.
|
260
|
-
- package/
|
261
|
+
- package/environments/development.ts
|
262
|
+
- package/environments/production.ts
|
263
|
+
- package/environments/test.ts
|
264
|
+
- package/environments/types.ts
|
265
|
+
- package/esbuild/index.ts
|
261
266
|
- package/index.d.ts
|
262
267
|
- package/index.ts
|
263
268
|
- package/loaders.d.ts
|
264
|
-
- package/optimization/rspack.
|
265
|
-
- package/optimization/webpack.
|
266
|
-
- package/plugins/rspack.
|
267
|
-
- package/plugins/webpack.
|
268
|
-
- package/rspack/index.
|
269
|
-
- package/rules/babel.
|
270
|
-
- package/rules/coffee.
|
271
|
-
- package/rules/css.
|
272
|
-
- package/rules/erb.
|
273
|
-
- package/rules/esbuild.
|
274
|
-
- package/rules/file.
|
275
|
-
- package/rules/jscommon.
|
276
|
-
- package/rules/less.
|
277
|
-
- package/rules/raw.
|
278
|
-
- package/rules/rspack.
|
279
|
-
- package/rules/sass.
|
280
|
-
- package/rules/stylus.
|
281
|
-
- package/rules/swc.
|
282
|
-
- package/rules/webpack.
|
283
|
-
- package/swc/index.
|
269
|
+
- package/optimization/rspack.ts
|
270
|
+
- package/optimization/webpack.ts
|
271
|
+
- package/plugins/rspack.ts
|
272
|
+
- package/plugins/webpack.ts
|
273
|
+
- package/rspack/index.ts
|
274
|
+
- package/rules/babel.ts
|
275
|
+
- package/rules/coffee.ts
|
276
|
+
- package/rules/css.ts
|
277
|
+
- package/rules/erb.ts
|
278
|
+
- package/rules/esbuild.ts
|
279
|
+
- package/rules/file.ts
|
280
|
+
- package/rules/jscommon.ts
|
281
|
+
- package/rules/less.ts
|
282
|
+
- package/rules/raw.ts
|
283
|
+
- package/rules/rspack.ts
|
284
|
+
- package/rules/sass.ts
|
285
|
+
- package/rules/stylus.ts
|
286
|
+
- package/rules/swc.ts
|
287
|
+
- package/rules/webpack.ts
|
288
|
+
- package/swc/index.ts
|
284
289
|
- package/types.ts
|
290
|
+
- package/types/README.md
|
291
|
+
- package/types/index.ts
|
285
292
|
- package/utils/configPath.ts
|
286
293
|
- package/utils/debug.ts
|
287
294
|
- package/utils/defaultConfigPath.ts
|
295
|
+
- package/utils/errorCodes.ts
|
288
296
|
- package/utils/errorHelpers.ts
|
289
297
|
- package/utils/getStyleRule.ts
|
290
298
|
- package/utils/helpers.ts
|
291
299
|
- package/utils/inliningCss.ts
|
300
|
+
- package/utils/pathValidation.ts
|
292
301
|
- package/utils/requireOrError.ts
|
293
302
|
- package/utils/snakeToCamelCase.ts
|
294
303
|
- package/utils/typeGuards.ts
|
@@ -296,6 +305,8 @@ files:
|
|
296
305
|
- package/webpack-types.d.ts
|
297
306
|
- package/webpackDevServerConfig.ts
|
298
307
|
- prettier.config.js
|
308
|
+
- scripts/remove-use-strict.js
|
309
|
+
- scripts/type-check-no-emit.js
|
299
310
|
- shakapacker.gemspec
|
300
311
|
- test/helpers.js
|
301
312
|
- test/package/config.test.js
|
@@ -318,18 +329,24 @@ files:
|
|
318
329
|
- test/package/rules/webpack.test.js
|
319
330
|
- test/package/staging.test.js
|
320
331
|
- test/package/test.test.js
|
332
|
+
- test/package/transpiler-defaults.test.js
|
321
333
|
- test/peer-dependencies.sh
|
322
334
|
- test/resolver.js
|
335
|
+
- test/scripts/remove-use-strict.test.js
|
323
336
|
- test/typescript/build.test.js
|
337
|
+
- test/typescript/environments.test.js
|
338
|
+
- test/typescript/pathValidation.test.js
|
339
|
+
- test/typescript/securityValidation.test.js
|
324
340
|
- tools/README.md
|
325
341
|
- tools/css-modules-v9-codemod.js
|
342
|
+
- tsconfig.eslint.json
|
326
343
|
- tsconfig.json
|
327
344
|
- yarn.lock
|
328
345
|
homepage: https://github.com/shakacode/shakapacker
|
329
346
|
licenses:
|
330
347
|
- MIT
|
331
348
|
metadata:
|
332
|
-
source_code_uri: https://github.com/shakacode/shakapacker/tree/v9.0.0.beta.
|
349
|
+
source_code_uri: https://github.com/shakacode/shakapacker/tree/v9.0.0.beta.8
|
333
350
|
rdoc_options: []
|
334
351
|
require_paths:
|
335
352
|
- lib
|
@@ -369,6 +386,11 @@ test_files:
|
|
369
386
|
- test/package/rules/webpack.test.js
|
370
387
|
- test/package/staging.test.js
|
371
388
|
- test/package/test.test.js
|
389
|
+
- test/package/transpiler-defaults.test.js
|
372
390
|
- test/peer-dependencies.sh
|
373
391
|
- test/resolver.js
|
392
|
+
- test/scripts/remove-use-strict.test.js
|
374
393
|
- test/typescript/build.test.js
|
394
|
+
- test/typescript/environments.test.js
|
395
|
+
- test/typescript/pathValidation.test.js
|
396
|
+
- test/typescript/securityValidation.test.js
|
data/package/babel/preset.js
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
const { moduleExists, packageFullVersion } = require("../utils/helpers")
|
2
|
-
|
3
|
-
const coreJsVersion = () => {
|
4
|
-
try {
|
5
|
-
return packageFullVersion("core-js").match(/^\d+\.\d+/)[0]
|
6
|
-
} catch (e) {
|
7
|
-
if (e.code !== "MODULE_NOT_FOUND") {
|
8
|
-
throw e
|
9
|
-
}
|
10
|
-
|
11
|
-
return "3.8"
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
/** @param api {import("@babel/core").ConfigAPI} */
|
16
|
-
module.exports = function config(api) {
|
17
|
-
const validEnv = ["development", "test", "production"]
|
18
|
-
const currentEnv = api.env()
|
19
|
-
const isDevelopmentEnv = api.env("development")
|
20
|
-
const isProductionEnv = api.env("production")
|
21
|
-
const isTestEnv = api.env("test")
|
22
|
-
|
23
|
-
if (!validEnv.includes(currentEnv)) {
|
24
|
-
throw new Error(
|
25
|
-
`Please specify a valid NODE_ENV or BABEL_ENV environment variable. Valid values are "development", "test", and "production". Instead, received: "${currentEnv}".`
|
26
|
-
)
|
27
|
-
}
|
28
|
-
|
29
|
-
return {
|
30
|
-
presets: [
|
31
|
-
isTestEnv && ["@babel/preset-env", { targets: { node: "current" } }],
|
32
|
-
(isProductionEnv || isDevelopmentEnv) && [
|
33
|
-
"@babel/preset-env",
|
34
|
-
{
|
35
|
-
useBuiltIns: "entry",
|
36
|
-
corejs: coreJsVersion(),
|
37
|
-
modules: "auto",
|
38
|
-
bugfixes: true,
|
39
|
-
exclude: ["transform-typeof-symbol"]
|
40
|
-
}
|
41
|
-
],
|
42
|
-
moduleExists("@babel/preset-typescript") && "@babel/preset-typescript"
|
43
|
-
].filter(Boolean),
|
44
|
-
plugins: [["@babel/plugin-transform-runtime", { helpers: false }]].filter(
|
45
|
-
Boolean
|
46
|
-
)
|
47
|
-
}
|
48
|
-
}
|
@@ -1,103 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
/* eslint global-require: 0 */
|
3
|
-
/* eslint import/no-dynamic-require: 0 */
|
4
|
-
const { basename, dirname, join, relative, resolve } = require("path");
|
5
|
-
const { existsSync, readdirSync } = require("fs");
|
6
|
-
const extname = require("path-complete-extname");
|
7
|
-
const config = require("../config");
|
8
|
-
const { isProduction } = require("../env");
|
9
|
-
const pluginsPath = resolve(__dirname, "..", "plugins", `${config.assets_bundler}.js`);
|
10
|
-
const { getPlugins } = require(pluginsPath);
|
11
|
-
const rulesPath = resolve(__dirname, "..", "rules", `${config.assets_bundler}.js`);
|
12
|
-
const rules = require(rulesPath);
|
13
|
-
// Don't use contentHash except for production for performance
|
14
|
-
// https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
|
15
|
-
const hash = isProduction || config.useContentHash ? "-[contenthash]" : "";
|
16
|
-
const getFilesInDirectory = (dir, includeNested) => {
|
17
|
-
if (!existsSync(dir)) {
|
18
|
-
return [];
|
19
|
-
}
|
20
|
-
return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => {
|
21
|
-
const filePath = join(dir, dirent.name);
|
22
|
-
if (dirent.isDirectory() && includeNested) {
|
23
|
-
return getFilesInDirectory(filePath, includeNested);
|
24
|
-
}
|
25
|
-
if (dirent.isFile()) {
|
26
|
-
return filePath;
|
27
|
-
}
|
28
|
-
return [];
|
29
|
-
});
|
30
|
-
};
|
31
|
-
const getEntryObject = () => {
|
32
|
-
const entries = {};
|
33
|
-
const rootPath = join(config.source_path, config.source_entry_path);
|
34
|
-
if (config.source_entry_path === "/" && config.nested_entries) {
|
35
|
-
throw new Error(`Invalid Shakapacker configuration detected!\n\n` +
|
36
|
-
`You have set source_entry_path to '/' with nested_entries enabled.\n` +
|
37
|
-
`This would create webpack entry points for EVERY file in your source directory,\n` +
|
38
|
-
`which would severely impact build performance.\n\n` +
|
39
|
-
`To fix this issue, either:\n` +
|
40
|
-
`1. Set 'nested_entries: false' in your shakapacker.yml\n` +
|
41
|
-
`2. Change 'source_entry_path' to a specific subdirectory (e.g., 'packs')\n` +
|
42
|
-
`3. Or use both options for better organization of your entry points`);
|
43
|
-
}
|
44
|
-
getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => {
|
45
|
-
const namespace = relative(join(rootPath), dirname(path));
|
46
|
-
const name = join(namespace, basename(path, extname(path)));
|
47
|
-
const assetPath = resolve(path);
|
48
|
-
// Allows for multiple filetypes per entry (https://webpack.js.org/guides/entry-advanced/)
|
49
|
-
// Transforms the config object value to an array with all values under the same name
|
50
|
-
const previousPaths = entries[name];
|
51
|
-
if (previousPaths) {
|
52
|
-
const pathArray = Array.isArray(previousPaths)
|
53
|
-
? previousPaths
|
54
|
-
: [previousPaths];
|
55
|
-
pathArray.push(assetPath);
|
56
|
-
entries[name] = pathArray;
|
57
|
-
}
|
58
|
-
else {
|
59
|
-
entries[name] = assetPath;
|
60
|
-
}
|
61
|
-
});
|
62
|
-
return entries;
|
63
|
-
};
|
64
|
-
const getModulePaths = () => {
|
65
|
-
const result = [resolve(config.source_path)];
|
66
|
-
if (config.additional_paths) {
|
67
|
-
config.additional_paths.forEach((path) => result.push(resolve(path)));
|
68
|
-
}
|
69
|
-
result.push("node_modules");
|
70
|
-
return result;
|
71
|
-
};
|
72
|
-
const baseConfig = {
|
73
|
-
mode: "production",
|
74
|
-
output: {
|
75
|
-
filename: `js/[name]${hash}.js`,
|
76
|
-
chunkFilename: `js/[name]${hash}.chunk.js`,
|
77
|
-
// https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
|
78
|
-
hotUpdateChunkFilename: "js/[id].[fullhash].hot-update.js",
|
79
|
-
path: config.outputPath,
|
80
|
-
publicPath: config.publicPath,
|
81
|
-
// This is required for SRI to work.
|
82
|
-
crossOriginLoading: config.integrity && config.integrity.enabled
|
83
|
-
? config.integrity.cross_origin
|
84
|
-
: false
|
85
|
-
},
|
86
|
-
entry: getEntryObject(),
|
87
|
-
resolve: {
|
88
|
-
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".coffee"],
|
89
|
-
modules: getModulePaths()
|
90
|
-
},
|
91
|
-
plugins: getPlugins(),
|
92
|
-
resolveLoader: {
|
93
|
-
modules: ["node_modules"]
|
94
|
-
},
|
95
|
-
optimization: {
|
96
|
-
splitChunks: { chunks: "all" },
|
97
|
-
runtimeChunk: "single"
|
98
|
-
},
|
99
|
-
module: {
|
100
|
-
rules
|
101
|
-
}
|
102
|
-
};
|
103
|
-
module.exports = baseConfig;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
const { merge } = require("webpack-merge")
|
2
|
-
const config = require("../config")
|
3
|
-
const baseConfig = require("./base")
|
4
|
-
|
5
|
-
const rspackTestConfig = () => ({
|
6
|
-
mode: "development",
|
7
|
-
devtool: "cheap-module-source-map",
|
8
|
-
// Disable file watching in test mode
|
9
|
-
watchOptions: {
|
10
|
-
ignored: /node_modules/
|
11
|
-
}
|
12
|
-
})
|
13
|
-
|
14
|
-
const webpackTestConfig = () => ({})
|
15
|
-
|
16
|
-
const bundlerConfig =
|
17
|
-
config.assets_bundler === "rspack" ? rspackTestConfig() : webpackTestConfig()
|
18
|
-
|
19
|
-
module.exports = merge(baseConfig, bundlerConfig)
|
data/package/esbuild/index.js
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
/* eslint global-require: 0 */
|
2
|
-
/* eslint import/no-dynamic-require: 0 */
|
3
|
-
|
4
|
-
const { resolve } = require("path")
|
5
|
-
const { existsSync } = require("fs")
|
6
|
-
const { merge } = require("webpack-merge")
|
7
|
-
|
8
|
-
const getLoaderExtension = (filename) => {
|
9
|
-
const matchData = filename.match(/\.([jt]sx?)?(\.erb)?$/)
|
10
|
-
|
11
|
-
if (!matchData) {
|
12
|
-
return "js"
|
13
|
-
}
|
14
|
-
|
15
|
-
return matchData[1]
|
16
|
-
}
|
17
|
-
|
18
|
-
const getCustomConfig = () => {
|
19
|
-
const path = resolve("config", "esbuild.config.js")
|
20
|
-
if (existsSync(path)) {
|
21
|
-
return require(path)
|
22
|
-
}
|
23
|
-
return {}
|
24
|
-
}
|
25
|
-
|
26
|
-
const getEsbuildLoaderConfig = (filenameToProcess) => {
|
27
|
-
const customConfig = getCustomConfig()
|
28
|
-
const defaultConfig = {
|
29
|
-
loader: require.resolve("esbuild-loader"),
|
30
|
-
options: {
|
31
|
-
loader: getLoaderExtension(filenameToProcess)
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
return merge(defaultConfig, customConfig)
|
36
|
-
}
|
37
|
-
|
38
|
-
module.exports = {
|
39
|
-
getEsbuildLoaderConfig
|
40
|
-
}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
const { requireOrError } = require("../utils/requireOrError")
|
2
|
-
const { error: logError } = require("../utils/debug")
|
3
|
-
|
4
|
-
const rspack = requireOrError("@rspack/core")
|
5
|
-
|
6
|
-
const getOptimization = () => {
|
7
|
-
// Use Rspack's built-in minification instead of terser-webpack-plugin
|
8
|
-
const result = { minimize: true }
|
9
|
-
try {
|
10
|
-
result.minimizer = [
|
11
|
-
new rspack.SwcJsMinimizerRspackPlugin(),
|
12
|
-
new rspack.LightningCssMinimizerRspackPlugin()
|
13
|
-
]
|
14
|
-
} catch (error) {
|
15
|
-
// Log full error with stack trace
|
16
|
-
logError(
|
17
|
-
`Failed to configure Rspack minimizers: ${error.message}\n${error.stack}`
|
18
|
-
)
|
19
|
-
// Re-throw the error to properly propagate it
|
20
|
-
throw new Error(
|
21
|
-
`Could not configure Rspack minimizers: ${error.message}. Please check that @rspack/core is properly installed.`
|
22
|
-
)
|
23
|
-
}
|
24
|
-
return result
|
25
|
-
}
|
26
|
-
|
27
|
-
module.exports = {
|
28
|
-
getOptimization
|
29
|
-
}
|
data/package/rules/raw.js
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
const config = require("../config")
|
2
|
-
|
3
|
-
const rspackRawConfig = () => ({
|
4
|
-
resourceQuery: /raw/,
|
5
|
-
type: "asset/source"
|
6
|
-
})
|
7
|
-
|
8
|
-
const webpackRawConfig = () => ({
|
9
|
-
test: /\.html$/,
|
10
|
-
exclude: /\.(js|mjs|jsx|ts|tsx)$/,
|
11
|
-
type: "asset/source"
|
12
|
-
})
|
13
|
-
|
14
|
-
module.exports =
|
15
|
-
config.assets_bundler === "rspack" ? rspackRawConfig() : webpackRawConfig()
|
data/package/swc/index.js
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
/* eslint global-require: 0 */
|
2
|
-
/* eslint import/no-dynamic-require: 0 */
|
3
|
-
|
4
|
-
const { resolve } = require("path")
|
5
|
-
const { existsSync } = require("fs")
|
6
|
-
const { merge } = require("webpack-merge")
|
7
|
-
|
8
|
-
const isJsxFile = (filename) => !!filename.match(/\.(jsx|tsx)?(\.erb)?$/)
|
9
|
-
|
10
|
-
const isTypescriptFile = (filename) => !!filename.match(/\.(ts|tsx)?(\.erb)?$/)
|
11
|
-
|
12
|
-
const getCustomConfig = () => {
|
13
|
-
const path = resolve("config", "swc.config.js")
|
14
|
-
if (existsSync(path)) {
|
15
|
-
return require(path)
|
16
|
-
}
|
17
|
-
return {}
|
18
|
-
}
|
19
|
-
|
20
|
-
const getSwcLoaderConfig = (filenameToProcess) => {
|
21
|
-
const customConfig = getCustomConfig()
|
22
|
-
const defaultConfig = {
|
23
|
-
loader: require.resolve("swc-loader"),
|
24
|
-
options: {
|
25
|
-
jsc: {
|
26
|
-
parser: {
|
27
|
-
dynamicImport: true,
|
28
|
-
syntax: isTypescriptFile(filenameToProcess)
|
29
|
-
? "typescript"
|
30
|
-
: "ecmascript",
|
31
|
-
[isTypescriptFile(filenameToProcess) ? "tsx" : "jsx"]:
|
32
|
-
isJsxFile(filenameToProcess)
|
33
|
-
},
|
34
|
-
loose: true
|
35
|
-
},
|
36
|
-
sourceMaps: true,
|
37
|
-
env: {
|
38
|
-
coreJs: 3,
|
39
|
-
exclude: ["transform-typeof-symbol"],
|
40
|
-
mode: "entry"
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
return merge(defaultConfig, customConfig)
|
46
|
-
}
|
47
|
-
|
48
|
-
module.exports = {
|
49
|
-
getSwcLoaderConfig
|
50
|
-
}
|