shakapacker 7.2.3 → 8.0.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintignore +1 -1
- data/.eslintrc.js +29 -8
- data/.github/PULL_REQUEST_TEMPLATE.md +10 -3
- data/.github/workflows/dummy.yml +5 -1
- data/.github/workflows/generator.yml +13 -18
- data/.github/workflows/node.yml +56 -0
- data/.github/workflows/ruby.yml +28 -17
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +52 -1
- data/README.md +88 -50
- data/Rakefile +1 -7
- data/docs/customizing_babel_config.md +2 -2
- data/docs/deployment.md +13 -6
- data/docs/react.md +6 -12
- data/docs/troubleshooting.md +4 -4
- data/docs/using_esbuild_loader.md +1 -1
- data/docs/using_swc_loader.md +1 -1
- data/docs/v8_upgrade.md +148 -0
- data/gemfiles/Gemfile-rails.7.1.x +12 -0
- data/jest.config.js +4 -0
- data/lib/install/config/shakapacker.yml +2 -2
- data/lib/install/template.rb +36 -30
- data/lib/shakapacker/base_strategy.rb +2 -1
- data/lib/shakapacker/compiler.rb +5 -20
- data/lib/shakapacker/configuration.rb +2 -46
- data/lib/shakapacker/deprecation_helper.rb +0 -78
- data/lib/shakapacker/dev_server.rb +1 -16
- data/lib/shakapacker/dev_server_runner.rb +2 -21
- data/lib/shakapacker/env.rb +1 -1
- data/lib/shakapacker/instance.rb +1 -3
- data/lib/shakapacker/manifest.rb +1 -1
- data/lib/shakapacker/railtie.rb +7 -0
- data/lib/shakapacker/runner.rb +4 -18
- data/lib/shakapacker/utils/manager.rb +58 -0
- data/lib/shakapacker/utils/misc.rb +0 -12
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +9 -30
- data/lib/shakapacker/webpack_runner.rb +2 -21
- data/lib/shakapacker.rb +0 -2
- data/lib/tasks/shakapacker/check_binstubs.rake +12 -26
- data/lib/tasks/shakapacker/check_manager.rake +3 -8
- data/lib/tasks/shakapacker/info.rake +6 -15
- data/package/babel/preset.js +15 -15
- data/package/config.js +15 -17
- data/package/dev_server.js +4 -4
- data/package/env.js +19 -17
- data/package/environments/base.js +41 -24
- data/package/environments/development.js +6 -6
- data/package/environments/production.js +16 -16
- data/package/environments/test.js +1 -1
- data/package/esbuild/index.js +6 -6
- data/package/index.d.ts +0 -1
- data/package/index.js +17 -46
- data/package/rules/babel.js +6 -8
- data/package/rules/coffee.js +2 -2
- data/package/rules/css.js +1 -1
- data/package/rules/erb.js +4 -4
- data/package/rules/esbuild.js +5 -7
- data/package/rules/file.js +17 -7
- data/package/rules/index.js +11 -11
- data/package/rules/jscommon.js +5 -5
- data/package/rules/less.js +6 -6
- data/package/rules/raw.js +1 -1
- data/package/rules/sass.js +4 -4
- data/package/rules/stylus.js +6 -6
- data/package/rules/swc.js +5 -7
- data/package/swc/index.js +10 -10
- data/package/utils/configPath.js +3 -18
- data/package/utils/defaultConfigPath.js +1 -1
- data/package/utils/{get_style_rule.js → getStyleRule.js} +6 -6
- data/package/utils/helpers.js +2 -43
- data/package/utils/inliningCss.js +4 -3
- data/package/utils/snakeToCamelCase.js +5 -0
- data/package/webpackDevServerConfig.js +28 -25
- data/package.json +11 -17
- data/prettier.config.js +4 -0
- data/shakapacker.gemspec +1 -1
- data/spec/dummy/app/javascript/packs/application.js +1 -1
- data/spec/dummy/config/application.rb +3 -0
- data/spec/dummy/config/initializers/react_on_rails.rb +2 -2
- data/spec/dummy/config/shakapacker.yml +3 -4
- data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -1
- data/spec/dummy/config/webpack/webpack.config.js +1 -1
- data/spec/dummy/package.json +2 -1
- data/spec/dummy/yarn.lock +2 -3
- data/spec/generator_specs/e2e_template/template.rb +15 -28
- data/spec/generator_specs/generator_spec.rb +6 -136
- data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -1
- data/spec/shakapacker/compiler_spec.rb +1 -3
- data/spec/shakapacker/configuration_spec.rb +4 -56
- data/spec/shakapacker/dev_server_runner_spec.rb +19 -102
- data/spec/shakapacker/dev_server_spec.rb +1 -16
- data/spec/shakapacker/engine_rake_tasks_spec.rb +1 -16
- data/spec/shakapacker/instance_spec.rb +1 -3
- data/spec/shakapacker/rake_tasks_spec.rb +2 -14
- data/spec/shakapacker/shakapacker_spec.rb +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -1
- data/spec/shakapacker/test_app/package.json +2 -1
- data/spec/shakapacker/utils_manager_spec.rb +125 -0
- data/spec/shakapacker/version_checker_spec.rb +4 -4
- data/spec/shakapacker/webpack_runner_spec.rb +19 -28
- data/spec/support/package_json_helpers.rb +7 -4
- data/test/helpers.js +67 -0
- data/test/package/config.test.js +50 -0
- data/test/package/dev_server.test.js +44 -0
- data/test/package/development.test.js +43 -0
- data/test/package/env.test.js +57 -0
- data/test/package/environments/base.test.js +105 -0
- data/test/package/environments/development.test.js +50 -0
- data/test/package/environments/production.test.js +106 -0
- data/test/package/index.test.js +45 -0
- data/test/package/production.test.js +32 -0
- data/test/package/rules/babel.test.js +58 -0
- data/test/package/rules/esbuild.test.js +59 -0
- data/test/package/rules/file.test.js +81 -0
- data/test/package/rules/index.test.js +7 -0
- data/test/package/rules/raw.test.js +12 -0
- data/test/package/rules/swc.test.js +59 -0
- data/test/package/staging.test.js +31 -0
- data/test/package/test.test.js +28 -0
- data/yarn.lock +1278 -421
- metadata +52 -102
- data/.github/workflows/jest.yml +0 -34
- data/.github/workflows/js-lint.yml +0 -34
- data/.github/workflows/rubocop.yml +0 -29
- data/.github/workflows/ruby-backward-compatibility.yml +0 -52
- data/lib/install/package.json +0 -15
- data/lib/tasks/shakapacker/check_yarn.rake +0 -34
- data/lib/tasks/shakapacker/yarn_install.rake +0 -24
- data/lib/tasks/webpacker/binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_node.rake +0 -9
- data/lib/tasks/webpacker/check_yarn.rake +0 -9
- data/lib/tasks/webpacker/clean.rake +0 -9
- data/lib/tasks/webpacker/clobber.rake +0 -11
- data/lib/tasks/webpacker/compile.rake +0 -9
- data/lib/tasks/webpacker/info.rake +0 -9
- data/lib/tasks/webpacker/install.rake +0 -9
- data/lib/tasks/webpacker/verify_config.rake +0 -9
- data/lib/tasks/webpacker/verify_install.rake +0 -9
- data/lib/tasks/webpacker/yarn_install.rake +0 -9
- data/lib/tasks/webpacker.rake +0 -20
- data/lib/webpacker/dev_server_runner.rb +0 -9
- data/lib/webpacker/webpack_runner.rb +0 -9
- data/lib/webpacker.rb +0 -4
- data/package/__tests__/config-bc.js +0 -27
- data/package/__tests__/config.js +0 -46
- data/package/__tests__/dev_server-bc.js +0 -46
- data/package/__tests__/dev_server.js +0 -46
- data/package/__tests__/development-bc.js +0 -66
- data/package/__tests__/development.js +0 -66
- data/package/__tests__/env-bc.js +0 -59
- data/package/__tests__/env.js +0 -59
- data/package/__tests__/index-bc.js +0 -22
- data/package/__tests__/index.js +0 -46
- data/package/__tests__/production-bc.js +0 -51
- data/package/__tests__/production.js +0 -51
- data/package/__tests__/staging-bc.js +0 -53
- data/package/__tests__/staging.js +0 -53
- data/package/__tests__/test-bc.js +0 -43
- data/package/__tests__/test.js +0 -43
- data/package/environments/__tests__/base-bc.js +0 -107
- data/package/environments/__tests__/base.js +0 -107
- data/package/environments/__tests__/development.js +0 -53
- data/package/environments/__tests__/production.js +0 -92
- data/package/rules/__tests__/__utils__/webpack.js +0 -50
- data/package/rules/__tests__/babel.js +0 -63
- data/package/rules/__tests__/esbuild.js +0 -64
- data/package/rules/__tests__/file.js +0 -62
- data/package/rules/__tests__/index.js +0 -7
- data/package/rules/__tests__/raw.js +0 -18
- data/package/rules/__tests__/swc.js +0 -63
- data/package/utils/snakeToCamelCase +0 -7
- data/spec/backward_compatibility_specs/command_spec.rb +0 -116
- data/spec/backward_compatibility_specs/compiler_spec.rb +0 -59
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +0 -24
- data/spec/backward_compatibility_specs/configuration_spec.rb +0 -294
- data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +0 -206
- data/spec/backward_compatibility_specs/dev_server_spec.rb +0 -47
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +0 -38
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +0 -67
- data/spec/backward_compatibility_specs/env_spec.rb +0 -23
- data/spec/backward_compatibility_specs/helper_spec.rb +0 -243
- data/spec/backward_compatibility_specs/instance_spec.rb +0 -31
- data/spec/backward_compatibility_specs/manifest_spec.rb +0 -100
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +0 -55
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +0 -41
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +0 -24
- data/spec/backward_compatibility_specs/webpack_runner_spec.rb +0 -86
- data/spec/backward_compatibility_specs/webpacker_spec.rb +0 -41
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +0 -3
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js +0 -10
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/generated/something.js +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.css +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.js +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker-dev-server +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -84
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_defaults_fallback.yml +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_manifest_path.yml +0 -80
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_nested_entries.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +0 -7
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +0 -85
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_public_root.yml +0 -18
- data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +0 -5
- data/spec/backward_compatibility_specs/webpacker_test_app/package.json +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +0 -58
- data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +0 -11
data/package/dev_server.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
// These are the raw
|
2
|
-
const { isBoolean } = require(
|
3
|
-
const config = require(
|
1
|
+
// These are the raw shakapacker dev server config settings from the YML file with ENV overrides applied.
|
2
|
+
const { isBoolean } = require("./utils/helpers")
|
3
|
+
const config = require("./config")
|
4
4
|
|
5
5
|
const envFetch = (key) => {
|
6
6
|
const value = process.env[key]
|
@@ -10,7 +10,7 @@ const envFetch = (key) => {
|
|
10
10
|
const devServerConfig = config.dev_server
|
11
11
|
|
12
12
|
if (devServerConfig) {
|
13
|
-
const envPrefix = config.dev_server.env_prefix ||
|
13
|
+
const envPrefix = config.dev_server.env_prefix || "SHAKAPACKER_DEV_SERVER"
|
14
14
|
|
15
15
|
Object.keys(devServerConfig).forEach((key) => {
|
16
16
|
const envValue = envFetch(`${envPrefix}_${key.toUpperCase()}`)
|
data/package/env.js
CHANGED
@@ -1,40 +1,42 @@
|
|
1
|
-
const { load } = require(
|
2
|
-
const { readFileSync } = require(
|
3
|
-
const defaultConfigPath = require(
|
1
|
+
const { load } = require("js-yaml")
|
2
|
+
const { readFileSync } = require("fs")
|
3
|
+
const defaultConfigPath = require("./utils/defaultConfigPath")
|
4
4
|
|
5
|
-
const NODE_ENVIRONMENTS = [
|
6
|
-
const DEFAULT =
|
7
|
-
const configPath = require(
|
5
|
+
const NODE_ENVIRONMENTS = ["development", "production", "test"]
|
6
|
+
const DEFAULT = "production"
|
7
|
+
const configPath = require("./utils/configPath")
|
8
8
|
|
9
9
|
const railsEnv = process.env.RAILS_ENV
|
10
10
|
const rawNodeEnv = process.env.NODE_ENV
|
11
|
-
const nodeEnv
|
12
|
-
|
13
|
-
const isProduction = nodeEnv ===
|
14
|
-
const isDevelopment = nodeEnv ===
|
11
|
+
const nodeEnv =
|
12
|
+
rawNodeEnv && NODE_ENVIRONMENTS.includes(rawNodeEnv) ? rawNodeEnv : DEFAULT
|
13
|
+
const isProduction = nodeEnv === "production"
|
14
|
+
const isDevelopment = nodeEnv === "development"
|
15
15
|
|
16
16
|
let config
|
17
17
|
try {
|
18
|
-
config = load(readFileSync(configPath),
|
18
|
+
config = load(readFileSync(configPath), "utf8")
|
19
19
|
} catch (error) {
|
20
|
-
if (error.code ===
|
20
|
+
if (error.code === "ENOENT") {
|
21
21
|
// File not found, use default configuration
|
22
|
-
config = load(readFileSync(defaultConfigPath),
|
22
|
+
config = load(readFileSync(defaultConfigPath), "utf8")
|
23
23
|
} else {
|
24
24
|
throw error
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
28
|
-
const availableEnvironments = Object.keys(config).join(
|
29
|
-
const regex = new RegExp(`^(${availableEnvironments})$`,
|
28
|
+
const availableEnvironments = Object.keys(config).join("|")
|
29
|
+
const regex = new RegExp(`^(${availableEnvironments})$`, "g")
|
30
30
|
|
31
|
-
const runningWebpackDevServer = process.env.WEBPACK_SERVE ===
|
31
|
+
const runningWebpackDevServer = process.env.WEBPACK_SERVE === "true"
|
32
32
|
|
33
33
|
const validatedRailsEnv = railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT
|
34
34
|
|
35
35
|
if (railsEnv && validatedRailsEnv !== railsEnv) {
|
36
36
|
/* eslint no-console:0 */
|
37
|
-
console.warn(
|
37
|
+
console.warn(
|
38
|
+
`Warning: '${railsEnv}' environment not found in the configuration. Using '${DEFAULT}' configuration as a fallback.`
|
39
|
+
)
|
38
40
|
}
|
39
41
|
|
40
42
|
module.exports = {
|
@@ -1,28 +1,45 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const {
|
5
|
-
const
|
6
|
-
const
|
7
|
-
const WebpackAssetsManifest = require(
|
8
|
-
const webpack = require(
|
9
|
-
const rules = require(
|
10
|
-
const config = require(
|
11
|
-
const { isProduction } = require(
|
12
|
-
const { moduleExists } = require(
|
4
|
+
const { existsSync, readdirSync } = require("fs")
|
5
|
+
const { basename, dirname, join, relative, resolve } = require("path")
|
6
|
+
const extname = require("path-complete-extname")
|
7
|
+
const WebpackAssetsManifest = require("webpack-assets-manifest")
|
8
|
+
const webpack = require("webpack")
|
9
|
+
const rules = require("../rules")
|
10
|
+
const config = require("../config")
|
11
|
+
const { isProduction } = require("../env")
|
12
|
+
const { moduleExists } = require("../utils/helpers")
|
13
|
+
|
14
|
+
const getFilesInDirectory = (dir, includeNested) => {
|
15
|
+
if (!existsSync(dir)) {
|
16
|
+
return []
|
17
|
+
}
|
18
|
+
|
19
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => {
|
20
|
+
const filePath = join(dir, dirent.name)
|
21
|
+
|
22
|
+
if (dirent.isDirectory() && includeNested) {
|
23
|
+
return getFilesInDirectory(filePath, includeNested)
|
24
|
+
}
|
25
|
+
if (dirent.isFile()) {
|
26
|
+
return filePath
|
27
|
+
}
|
28
|
+
return []
|
29
|
+
})
|
30
|
+
}
|
13
31
|
|
14
32
|
const getEntryObject = () => {
|
15
33
|
const entries = {}
|
16
34
|
const rootPath = join(config.source_path, config.source_entry_path)
|
17
|
-
if (config.source_entry_path ===
|
35
|
+
if (config.source_entry_path === "/" && config.nested_entries) {
|
18
36
|
throw new Error(
|
19
37
|
"Your shakapacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
|
20
|
-
|
38
|
+
"'true'. Doing this would result in packs for every one of your source files"
|
21
39
|
)
|
22
40
|
}
|
23
|
-
const nesting = config.nested_entries ? '**/' : ''
|
24
41
|
|
25
|
-
|
42
|
+
getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => {
|
26
43
|
const namespace = relative(join(rootPath), dirname(path))
|
27
44
|
const name = join(namespace, basename(path, extname(path)))
|
28
45
|
let assetPaths = resolve(path)
|
@@ -50,7 +67,7 @@ const getModulePaths = () => {
|
|
50
67
|
if (config.additional_paths) {
|
51
68
|
config.additional_paths.forEach((path) => result.push(resolve(path)))
|
52
69
|
}
|
53
|
-
result.push(
|
70
|
+
result.push("node_modules")
|
54
71
|
|
55
72
|
return result
|
56
73
|
}
|
@@ -67,9 +84,9 @@ const getPlugins = () => {
|
|
67
84
|
})
|
68
85
|
]
|
69
86
|
|
70
|
-
if (moduleExists(
|
71
|
-
const hash = isProduction || config.useContentHash ?
|
72
|
-
const MiniCssExtractPlugin = require(
|
87
|
+
if (moduleExists("css-loader") && moduleExists("mini-css-extract-plugin")) {
|
88
|
+
const hash = isProduction || config.useContentHash ? "-[contenthash:8]" : ""
|
89
|
+
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
73
90
|
plugins.push(
|
74
91
|
new MiniCssExtractPlugin({
|
75
92
|
filename: `css/[name]${hash}.css`,
|
@@ -87,35 +104,35 @@ const getPlugins = () => {
|
|
87
104
|
|
88
105
|
// Don't use contentHash except for production for performance
|
89
106
|
// https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
|
90
|
-
const hash = isProduction || config.useContentHash ?
|
107
|
+
const hash = isProduction || config.useContentHash ? "-[contenthash]" : ""
|
91
108
|
|
92
109
|
module.exports = {
|
93
|
-
mode:
|
110
|
+
mode: "production",
|
94
111
|
output: {
|
95
112
|
filename: `js/[name]${hash}.js`,
|
96
113
|
chunkFilename: `js/[name]${hash}.chunk.js`,
|
97
114
|
|
98
115
|
// https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
|
99
|
-
hotUpdateChunkFilename:
|
116
|
+
hotUpdateChunkFilename: "js/[id].[fullhash].hot-update.js",
|
100
117
|
path: config.outputPath,
|
101
118
|
publicPath: config.publicPath
|
102
119
|
},
|
103
120
|
entry: getEntryObject(),
|
104
121
|
resolve: {
|
105
|
-
extensions: [
|
122
|
+
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".coffee"],
|
106
123
|
modules: getModulePaths()
|
107
124
|
},
|
108
125
|
|
109
126
|
plugins: getPlugins(),
|
110
127
|
|
111
128
|
resolveLoader: {
|
112
|
-
modules: [
|
129
|
+
modules: ["node_modules"]
|
113
130
|
},
|
114
131
|
|
115
132
|
optimization: {
|
116
|
-
splitChunks: { chunks:
|
133
|
+
splitChunks: { chunks: "all" },
|
117
134
|
|
118
|
-
runtimeChunk:
|
135
|
+
runtimeChunk: "single"
|
119
136
|
},
|
120
137
|
|
121
138
|
module: {
|
@@ -1,12 +1,12 @@
|
|
1
|
-
const { merge } = require(
|
1
|
+
const { merge } = require("webpack-merge")
|
2
2
|
|
3
|
-
const baseConfig = require(
|
4
|
-
const webpackDevServerConfig
|
5
|
-
const { runningWebpackDevServer } = require(
|
3
|
+
const baseConfig = require("./base")
|
4
|
+
const webpackDevServerConfig = require("../webpackDevServerConfig")
|
5
|
+
const { runningWebpackDevServer } = require("../env")
|
6
6
|
|
7
7
|
const devConfig = {
|
8
|
-
mode:
|
9
|
-
devtool:
|
8
|
+
mode: "development",
|
9
|
+
devtool: "cheap-module-source-map",
|
10
10
|
...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
|
11
11
|
}
|
12
12
|
|
@@ -1,29 +1,29 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const { merge } = require(
|
5
|
-
const CompressionPlugin = require(
|
6
|
-
const TerserPlugin = require(
|
7
|
-
const baseConfig = require(
|
8
|
-
const { moduleExists } = require(
|
9
|
-
const config = require(
|
4
|
+
const { merge } = require("webpack-merge")
|
5
|
+
const CompressionPlugin = require("compression-webpack-plugin")
|
6
|
+
const TerserPlugin = require("terser-webpack-plugin")
|
7
|
+
const baseConfig = require("./base")
|
8
|
+
const { moduleExists } = require("../utils/helpers")
|
9
|
+
const config = require("../config")
|
10
10
|
|
11
11
|
const getPlugins = () => {
|
12
12
|
const plugins = []
|
13
13
|
|
14
14
|
plugins.push(
|
15
15
|
new CompressionPlugin({
|
16
|
-
filename:
|
17
|
-
algorithm:
|
16
|
+
filename: "[path][base].gz[query]",
|
17
|
+
algorithm: "gzip",
|
18
18
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
19
19
|
})
|
20
20
|
)
|
21
21
|
|
22
|
-
if (
|
22
|
+
if ("brotli" in process.versions) {
|
23
23
|
plugins.push(
|
24
24
|
new CompressionPlugin({
|
25
|
-
filename:
|
26
|
-
algorithm:
|
25
|
+
filename: "[path][base].br[query]",
|
26
|
+
algorithm: "brotliCompress",
|
27
27
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
28
28
|
})
|
29
29
|
)
|
@@ -34,10 +34,10 @@ const getPlugins = () => {
|
|
34
34
|
|
35
35
|
const tryCssMinimizer = () => {
|
36
36
|
if (
|
37
|
-
moduleExists(
|
38
|
-
moduleExists(
|
37
|
+
moduleExists("css-loader") &&
|
38
|
+
moduleExists("css-minimizer-webpack-plugin")
|
39
39
|
) {
|
40
|
-
const CssMinimizerPlugin = require(
|
40
|
+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
|
41
41
|
return new CssMinimizerPlugin()
|
42
42
|
}
|
43
43
|
|
@@ -45,8 +45,8 @@ const tryCssMinimizer = () => {
|
|
45
45
|
}
|
46
46
|
|
47
47
|
const productionConfig = {
|
48
|
-
devtool:
|
49
|
-
stats:
|
48
|
+
devtool: "source-map",
|
49
|
+
stats: "normal",
|
50
50
|
bail: true,
|
51
51
|
plugins: getPlugins(),
|
52
52
|
optimization: {
|
data/package/esbuild/index.js
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const { resolve } = require(
|
5
|
-
const { existsSync } = require(
|
6
|
-
const { merge } = require(
|
4
|
+
const { resolve } = require("path")
|
5
|
+
const { existsSync } = require("fs")
|
6
|
+
const { merge } = require("webpack-merge")
|
7
7
|
|
8
8
|
const getLoaderExtension = (filename) => {
|
9
9
|
const matchData = filename.match(/\.([jt]sx?)?(\.erb)?$/)
|
10
10
|
|
11
11
|
if (!matchData) {
|
12
|
-
return
|
12
|
+
return "js"
|
13
13
|
}
|
14
14
|
|
15
15
|
return matchData[1]
|
16
16
|
}
|
17
17
|
|
18
18
|
const getCustomConfig = () => {
|
19
|
-
const path = resolve(
|
19
|
+
const path = resolve("config", "esbuild.config.js")
|
20
20
|
if (existsSync(path)) {
|
21
21
|
return require(path)
|
22
22
|
}
|
@@ -26,7 +26,7 @@ const getCustomConfig = () => {
|
|
26
26
|
const getEsbuildLoaderConfig = (filenameToProcess) => {
|
27
27
|
const customConfig = getCustomConfig()
|
28
28
|
const defaultConfig = {
|
29
|
-
loader: require.resolve(
|
29
|
+
loader: require.resolve("esbuild-loader"),
|
30
30
|
options: {
|
31
31
|
loader: getLoaderExtension(filenameToProcess)
|
32
32
|
}
|
data/package/index.d.ts
CHANGED
@@ -35,7 +35,6 @@ declare module 'shakapacker' {
|
|
35
35
|
export const config: Config
|
36
36
|
export const devServer: Record<string, unknown>
|
37
37
|
export function generateWebpackConfig(extraConfig?: Configuration): Configuration
|
38
|
-
export const globalMutableWebpackConfig: Configuration
|
39
38
|
export const baseConfig: Configuration
|
40
39
|
export const env: Env
|
41
40
|
export const rules: Record<string, unknown>
|
data/package/index.js
CHANGED
@@ -1,41 +1,35 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const webpackMerge = require(
|
5
|
-
const { resolve } = require(
|
6
|
-
const { existsSync } = require(
|
7
|
-
const baseConfig = require(
|
8
|
-
const rules = require(
|
9
|
-
const config = require(
|
10
|
-
const devServer = require(
|
11
|
-
const env = require(
|
12
|
-
const { moduleExists, canProcess } = require(
|
13
|
-
const inliningCss = require(
|
14
|
-
|
15
|
-
const globalMutableWebpackConfig = () => {
|
16
|
-
const { nodeEnv } = env
|
17
|
-
const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
|
18
|
-
const environmentConfig = existsSync(path) ? require(path) : baseConfig
|
19
|
-
return environmentConfig
|
20
|
-
}
|
4
|
+
const webpackMerge = require("webpack-merge")
|
5
|
+
const { resolve } = require("path")
|
6
|
+
const { existsSync } = require("fs")
|
7
|
+
const baseConfig = require("./environments/base")
|
8
|
+
const rules = require("./rules")
|
9
|
+
const config = require("./config")
|
10
|
+
const devServer = require("./dev_server")
|
11
|
+
const env = require("./env")
|
12
|
+
const { moduleExists, canProcess } = require("./utils/helpers")
|
13
|
+
const inliningCss = require("./utils/inliningCss")
|
21
14
|
|
22
15
|
const generateWebpackConfig = (extraConfig = {}, ...extraArgs) => {
|
23
16
|
if (extraArgs.length > 0) {
|
24
17
|
throw new Error(
|
25
|
-
|
18
|
+
"Only one extra config may be passed here - use webpack-merge to merge configs before passing them to Shakapacker"
|
26
19
|
)
|
27
20
|
}
|
28
21
|
|
29
|
-
const
|
30
|
-
const
|
31
|
-
|
22
|
+
const { nodeEnv } = env
|
23
|
+
const path = resolve(__dirname, "environments", `${nodeEnv}.js`)
|
24
|
+
const environmentConfig = existsSync(path) ? require(path) : baseConfig
|
25
|
+
|
26
|
+
return webpackMerge.merge({}, environmentConfig, extraConfig)
|
32
27
|
}
|
33
28
|
|
34
|
-
|
29
|
+
module.exports = {
|
35
30
|
config, // shakapacker.yml
|
36
31
|
devServer,
|
37
32
|
generateWebpackConfig,
|
38
|
-
globalMutableWebpackConfig: globalMutableWebpackConfig(),
|
39
33
|
baseConfig,
|
40
34
|
env,
|
41
35
|
rules,
|
@@ -44,26 +38,3 @@ const shakapackerObject = {
|
|
44
38
|
inliningCss,
|
45
39
|
...webpackMerge
|
46
40
|
}
|
47
|
-
|
48
|
-
// For backward compatibility
|
49
|
-
const shakapackerProxyHandler = {
|
50
|
-
get(target, prop) {
|
51
|
-
if (prop === 'webpackConfig') {
|
52
|
-
// eslint-disable-next-line no-console
|
53
|
-
console.warn(`⚠️
|
54
|
-
DEPRECATION NOTICE:
|
55
|
-
The 'webpackConfig' is deprecated and will be removed in a future version.
|
56
|
-
Please use 'globalMutableWebpackConfig' instead, or use
|
57
|
-
'generateWebpackConfig()' to avoid unwanted config mutation across the app.
|
58
|
-
|
59
|
-
For more information, see version 7 upgrade documentation at:
|
60
|
-
https://github.com/shakacode/shakapacker/blob/main/docs/v7_upgrade.md
|
61
|
-
`)
|
62
|
-
return globalMutableWebpackConfig()
|
63
|
-
}
|
64
|
-
|
65
|
-
return target[prop]
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
module.exports = new Proxy(shakapackerObject, shakapackerProxyHandler)
|
data/package/rules/babel.js
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
const { loaderMatches } = require(
|
2
|
-
const {
|
3
|
-
|
4
|
-
|
5
|
-
const { isProduction } = require('../env')
|
6
|
-
const jscommon = require('./jscommon')
|
1
|
+
const { loaderMatches } = require("../utils/helpers")
|
2
|
+
const { webpack_loader: webpackLoader } = require("../config")
|
3
|
+
const { isProduction } = require("../env")
|
4
|
+
const jscommon = require("./jscommon")
|
7
5
|
|
8
|
-
module.exports = loaderMatches(webpackLoader,
|
6
|
+
module.exports = loaderMatches(webpackLoader, "babel", () => ({
|
9
7
|
test: /\.(js|jsx|mjs|ts|tsx|coffee)?(\.erb)?$/,
|
10
8
|
...jscommon,
|
11
9
|
use: [
|
12
10
|
{
|
13
|
-
loader: require.resolve(
|
11
|
+
loader: require.resolve("babel-loader"),
|
14
12
|
options: {
|
15
13
|
cacheDirectory: true,
|
16
14
|
cacheCompression: isProduction,
|
data/package/rules/coffee.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
const { canProcess } = require(
|
1
|
+
const { canProcess } = require("../utils/helpers")
|
2
2
|
|
3
|
-
module.exports = canProcess(
|
3
|
+
module.exports = canProcess("coffee-loader", (resolvedPath) => ({
|
4
4
|
test: /\.coffee(\.erb)?$/,
|
5
5
|
use: [{ loader: resolvedPath }]
|
6
6
|
}))
|
data/package/rules/css.js
CHANGED
data/package/rules/erb.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
const { canProcess } = require(
|
1
|
+
const { canProcess } = require("../utils/helpers")
|
2
2
|
|
3
|
-
const runner = /^win/.test(process.platform) ?
|
3
|
+
const runner = /^win/.test(process.platform) ? "ruby " : ""
|
4
4
|
|
5
|
-
module.exports = canProcess(
|
5
|
+
module.exports = canProcess("rails-erb-loader", (resolvedPath) => ({
|
6
6
|
test: /\.erb$/,
|
7
|
-
enforce:
|
7
|
+
enforce: "pre",
|
8
8
|
exclude: /node_modules/,
|
9
9
|
use: [
|
10
10
|
{
|
data/package/rules/esbuild.js
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
const { loaderMatches } = require(
|
2
|
-
const { getEsbuildLoaderConfig } = require(
|
3
|
-
const {
|
4
|
-
|
5
|
-
} = require('../config')
|
6
|
-
const jscommon = require('./jscommon')
|
1
|
+
const { loaderMatches } = require("../utils/helpers")
|
2
|
+
const { getEsbuildLoaderConfig } = require("../esbuild")
|
3
|
+
const { webpack_loader: webpackLoader } = require("../config")
|
4
|
+
const jscommon = require("./jscommon")
|
7
5
|
|
8
|
-
module.exports = loaderMatches(webpackLoader,
|
6
|
+
module.exports = loaderMatches(webpackLoader, "esbuild", () => ({
|
9
7
|
test: /\.(ts|tsx|js|jsx|mjs|coffee)?(\.erb)?$/,
|
10
8
|
...jscommon,
|
11
9
|
use: ({ resource }) => getEsbuildLoaderConfig(resource)
|
data/package/rules/file.js
CHANGED
@@ -1,18 +1,28 @@
|
|
1
|
-
const { dirname } = require(
|
2
|
-
const {
|
1
|
+
const { dirname } = require("path")
|
2
|
+
const {
|
3
|
+
additional_paths: additionalPaths,
|
4
|
+
source_path: sourcePath
|
5
|
+
} = require("../config")
|
3
6
|
|
4
7
|
module.exports = {
|
5
8
|
test: /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2|svg)$/,
|
6
9
|
exclude: /\.(js|mjs|jsx|ts|tsx)$/,
|
7
|
-
type:
|
10
|
+
type: "asset/resource",
|
8
11
|
generator: {
|
9
12
|
filename: (pathData) => {
|
10
|
-
const
|
11
|
-
|
12
|
-
|
13
|
+
const path = dirname(pathData.filename)
|
14
|
+
const stripPaths = [...additionalPaths, sourcePath]
|
15
|
+
|
16
|
+
const selectedStripPath = stripPaths.find((includePath) =>
|
17
|
+
path.startsWith(includePath)
|
18
|
+
)
|
19
|
+
|
20
|
+
const folders = path
|
21
|
+
.replace(`${selectedStripPath}`, "")
|
22
|
+
.split("/")
|
13
23
|
.filter(Boolean)
|
14
24
|
|
15
|
-
const foldersWithStatic = [
|
25
|
+
const foldersWithStatic = ["static", ...folders].join("/")
|
16
26
|
return `${foldersWithStatic}/[name]-[hash][ext][query]`
|
17
27
|
}
|
18
28
|
}
|
data/package/rules/index.js
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
4
|
const rules = {
|
5
|
-
raw: require(
|
6
|
-
file: require(
|
7
|
-
css: require(
|
8
|
-
sass: require(
|
9
|
-
babel: require(
|
10
|
-
swc: require(
|
11
|
-
esbuild: require(
|
12
|
-
erb: require(
|
13
|
-
coffee: require(
|
14
|
-
less: require(
|
15
|
-
stylus: require(
|
5
|
+
raw: require("./raw"),
|
6
|
+
file: require("./file"),
|
7
|
+
css: require("./css"),
|
8
|
+
sass: require("./sass"),
|
9
|
+
babel: require("./babel"),
|
10
|
+
swc: require("./swc"),
|
11
|
+
esbuild: require("./esbuild"),
|
12
|
+
erb: require("./erb"),
|
13
|
+
coffee: require("./coffee"),
|
14
|
+
less: require("./less"),
|
15
|
+
stylus: require("./stylus")
|
16
16
|
}
|
17
17
|
|
18
18
|
module.exports = Object.keys(rules)
|
data/package/rules/jscommon.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
const { resolve } = require(
|
2
|
-
const { realpathSync } = require(
|
1
|
+
const { resolve } = require("path")
|
2
|
+
const { realpathSync } = require("fs")
|
3
3
|
const {
|
4
4
|
source_path: sourcePath,
|
5
5
|
additional_paths: additionalPaths
|
6
|
-
} = require(
|
6
|
+
} = require("../config")
|
7
7
|
|
8
|
-
const inclusions = [sourcePath, ...additionalPaths].map(p => {
|
8
|
+
const inclusions = [sourcePath, ...additionalPaths].map((p) => {
|
9
9
|
try {
|
10
10
|
return realpathSync(p)
|
11
11
|
} catch (e) {
|
@@ -18,7 +18,7 @@ module.exports = {
|
|
18
18
|
exclude: [
|
19
19
|
{
|
20
20
|
// exclude all node_modules from running through babel-loader
|
21
|
-
and: [resolve(
|
21
|
+
and: [resolve("node_modules")],
|
22
22
|
// Do not exclude inclusions, as otherwise these won't be transpiled
|
23
23
|
not: [...inclusions]
|
24
24
|
}
|
data/package/rules/less.js
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
const path = require(
|
2
|
-
const { canProcess } = require(
|
3
|
-
const getStyleRule = require(
|
1
|
+
const path = require("path")
|
2
|
+
const { canProcess } = require("../utils/helpers")
|
3
|
+
const getStyleRule = require("../utils/getStyleRule")
|
4
4
|
|
5
5
|
const {
|
6
6
|
additional_paths: paths,
|
7
7
|
source_path: sourcePath
|
8
|
-
} = require(
|
8
|
+
} = require("../config")
|
9
9
|
|
10
|
-
module.exports = canProcess(
|
10
|
+
module.exports = canProcess("less-loader", (resolvedPath) =>
|
11
11
|
getStyleRule(/\.(less)(\.erb)?$/i, [
|
12
12
|
{
|
13
13
|
loader: resolvedPath,
|
14
14
|
options: {
|
15
15
|
lessOptions: {
|
16
|
-
paths: [path.resolve(__dirname,
|
16
|
+
paths: [path.resolve(__dirname, "node_modules"), sourcePath, ...paths]
|
17
17
|
},
|
18
18
|
sourceMap: true
|
19
19
|
}
|
data/package/rules/raw.js
CHANGED
data/package/rules/sass.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
|
3
|
-
const getStyleRule = require(
|
4
|
-
const { canProcess } = require(
|
5
|
-
const { additional_paths: includePaths } = require(
|
3
|
+
const getStyleRule = require("../utils/getStyleRule")
|
4
|
+
const { canProcess } = require("../utils/helpers")
|
5
|
+
const { additional_paths: includePaths } = require("../config")
|
6
6
|
|
7
|
-
module.exports = canProcess(
|
7
|
+
module.exports = canProcess("sass-loader", (resolvedPath) =>
|
8
8
|
getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
|
9
9
|
{
|
10
10
|
loader: resolvedPath,
|