webpacker 5.4.4 → 6.0.0.rc.6

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.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.github/workflows/jest.yml +7 -15
  4. data/.github/workflows/js-lint.yml +7 -15
  5. data/.github/workflows/rubocop.yml +1 -1
  6. data/.github/workflows/ruby.yml +18 -16
  7. data/.gitignore +2 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +5 -7
  10. data/CHANGELOG.md +30 -12
  11. data/CONTRIBUTING.md +20 -1
  12. data/Gemfile.lock +83 -83
  13. data/README.md +389 -179
  14. data/config/README.md +3 -0
  15. data/config/webpacker.yml +1 -0
  16. data/docs/deployment.md +9 -11
  17. data/docs/developing_webpacker.md +29 -0
  18. data/docs/troubleshooting.md +61 -25
  19. data/docs/v6_upgrade.md +113 -0
  20. data/gemfiles/Gemfile-rails.6.1.x +12 -0
  21. data/lib/install/{javascript/packs/application.js → application.js} +2 -5
  22. data/lib/install/bin/webpack +4 -7
  23. data/lib/install/bin/yarn +18 -0
  24. data/lib/install/config/webpack/base.js +3 -0
  25. data/lib/install/config/webpack/development.js +2 -2
  26. data/lib/install/config/webpack/production.js +2 -2
  27. data/lib/install/config/webpack/test.js +2 -2
  28. data/lib/install/config/webpacker.yml +21 -49
  29. data/lib/install/package.json +15 -0
  30. data/lib/install/template.rb +64 -29
  31. data/lib/tasks/webpacker/binstubs.rake +6 -4
  32. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  33. data/lib/tasks/webpacker/check_node.rake +3 -0
  34. data/lib/tasks/webpacker/check_yarn.rake +3 -0
  35. data/lib/tasks/webpacker/clobber.rake +1 -1
  36. data/lib/tasks/webpacker/compile.rake +4 -2
  37. data/lib/tasks/webpacker/info.rake +12 -10
  38. data/lib/tasks/webpacker/install.rake +6 -4
  39. data/lib/tasks/webpacker/verify_config.rake +14 -0
  40. data/lib/tasks/webpacker/verify_install.rake +1 -10
  41. data/lib/tasks/webpacker/yarn_install.rake +9 -7
  42. data/lib/tasks/webpacker.rake +2 -11
  43. data/lib/tasks/yarn.rake +38 -0
  44. data/lib/webpacker/commands.rb +21 -16
  45. data/lib/webpacker/compiler.rb +16 -9
  46. data/lib/webpacker/configuration.rb +8 -32
  47. data/lib/webpacker/dev_server.rb +6 -0
  48. data/lib/webpacker/dev_server_runner.rb +28 -4
  49. data/lib/webpacker/helper.rb +47 -81
  50. data/lib/webpacker/instance.rb +4 -0
  51. data/lib/webpacker/manifest.rb +2 -3
  52. data/lib/webpacker/railtie.rb +8 -2
  53. data/lib/webpacker/runner.rb +1 -1
  54. data/lib/webpacker/version.rb +1 -1
  55. data/lib/webpacker/webpack_runner.rb +29 -3
  56. data/lib/webpacker.rb +1 -1
  57. data/package/__tests__/config.js +5 -37
  58. data/package/__tests__/development.js +13 -21
  59. data/package/__tests__/env.js +16 -4
  60. data/package/__tests__/index.js +9 -0
  61. data/package/__tests__/production.js +6 -6
  62. data/package/__tests__/staging.js +7 -6
  63. data/package/__tests__/test.js +4 -5
  64. data/package/babel/preset.js +54 -0
  65. data/package/config.js +6 -14
  66. data/package/env.js +13 -4
  67. data/package/environments/__tests__/base.js +20 -52
  68. data/package/environments/base.js +68 -128
  69. data/package/environments/development.js +49 -47
  70. data/package/environments/production.js +66 -64
  71. data/package/environments/test.js +2 -2
  72. data/package/index.js +15 -8
  73. data/package/inliningCss.js +7 -0
  74. data/package/rules/babel.js +10 -8
  75. data/package/rules/coffee.js +6 -0
  76. data/package/rules/erb.js +15 -0
  77. data/package/rules/file.js +21 -19
  78. data/package/rules/index.js +16 -18
  79. data/package/rules/less.js +22 -0
  80. data/package/rules/raw.js +5 -0
  81. data/package/rules/sass.js +9 -10
  82. data/package/rules/stylus.js +26 -0
  83. data/package/utils/get_style_rule.js +28 -36
  84. data/package/utils/helpers.js +28 -35
  85. data/package.json +18 -38
  86. data/test/command_test.rb +76 -0
  87. data/test/compiler_test.rb +0 -12
  88. data/test/configuration_test.rb +4 -35
  89. data/test/dev_server_runner_test.rb +36 -6
  90. data/test/engine_rake_tasks_test.rb +39 -0
  91. data/test/helper_test.rb +79 -77
  92. data/test/manifest_test.rb +16 -0
  93. data/test/mounted_app/Rakefile +4 -0
  94. data/test/mounted_app/test/dummy/Rakefile +3 -0
  95. data/test/mounted_app/test/dummy/bin/rails +3 -0
  96. data/test/mounted_app/test/dummy/bin/rake +3 -0
  97. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  98. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  99. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  100. data/test/mounted_app/test/dummy/config.ru +5 -0
  101. data/test/mounted_app/test/dummy/package.json +7 -0
  102. data/test/rake_tasks_test.rb +1 -10
  103. data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
  104. data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
  105. data/test/test_app/config/webpacker.yml +5 -31
  106. data/test/test_app/config/webpacker_other_location.yml +79 -0
  107. data/test/test_app/config/webpacker_public_root.yml +0 -1
  108. data/test/test_app/public/packs/manifest.json +36 -18
  109. data/test/test_app/some.config.js +0 -0
  110. data/test/webpack_runner_test.rb +9 -3
  111. data/test/webpacker_test.rb +21 -0
  112. data/webpacker.gemspec +2 -2
  113. data/yarn.lock +1277 -4620
  114. metadata +63 -92
  115. data/docs/assets.md +0 -119
  116. data/docs/cloud9.md +0 -310
  117. data/docs/css.md +0 -308
  118. data/docs/docker.md +0 -68
  119. data/docs/engines.md +0 -213
  120. data/docs/env.md +0 -63
  121. data/docs/es6.md +0 -72
  122. data/docs/folder-structure.md +0 -66
  123. data/docs/integrations.md +0 -220
  124. data/docs/misc.md +0 -23
  125. data/docs/props.md +0 -223
  126. data/docs/target.md +0 -22
  127. data/docs/testing.md +0 -136
  128. data/docs/typescript.md +0 -190
  129. data/docs/v4-upgrade.md +0 -142
  130. data/docs/webpack-dev-server.md +0 -92
  131. data/docs/webpack.md +0 -364
  132. data/docs/yarn.md +0 -23
  133. data/lib/install/angular.rb +0 -23
  134. data/lib/install/coffee.rb +0 -25
  135. data/lib/install/config/.browserslistrc +0 -1
  136. data/lib/install/config/babel.config.js +0 -82
  137. data/lib/install/config/postcss.config.js +0 -12
  138. data/lib/install/config/webpack/environment.js +0 -3
  139. data/lib/install/elm.rb +0 -39
  140. data/lib/install/erb.rb +0 -25
  141. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  142. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  143. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  144. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  145. data/lib/install/examples/angular/hello_angular.js +0 -7
  146. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  147. data/lib/install/examples/elm/Main.elm +0 -55
  148. data/lib/install/examples/elm/hello_elm.js +0 -16
  149. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  150. data/lib/install/examples/react/babel.config.js +0 -99
  151. data/lib/install/examples/react/hello_react.jsx +0 -26
  152. data/lib/install/examples/react/tsconfig.json +0 -21
  153. data/lib/install/examples/stimulus/application.js +0 -1
  154. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  155. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  156. data/lib/install/examples/svelte/app.svelte +0 -11
  157. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  158. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  159. data/lib/install/examples/typescript/tsconfig.json +0 -24
  160. data/lib/install/examples/vue/app.vue +0 -22
  161. data/lib/install/examples/vue/hello_vue.js +0 -72
  162. data/lib/install/loaders/coffee.js +0 -6
  163. data/lib/install/loaders/elm.js +0 -25
  164. data/lib/install/loaders/erb.js +0 -11
  165. data/lib/install/loaders/svelte.js +0 -9
  166. data/lib/install/loaders/vue.js +0 -6
  167. data/lib/install/react.rb +0 -18
  168. data/lib/install/stimulus.rb +0 -12
  169. data/lib/install/svelte.rb +0 -29
  170. data/lib/install/typescript.rb +0 -39
  171. data/lib/install/vue.rb +0 -49
  172. data/lib/tasks/installers.rake +0 -42
  173. data/package/config_types/__tests__/config_list.js +0 -118
  174. data/package/config_types/__tests__/config_object.js +0 -43
  175. data/package/config_types/config_list.js +0 -75
  176. data/package/config_types/config_object.js +0 -55
  177. data/package/config_types/index.js +0 -7
  178. data/package/rules/module.css.js +0 -3
  179. data/package/rules/module.sass.js +0 -8
  180. data/package/rules/node_modules.js +0 -22
  181. data/package/utils/__tests__/deep_assign.js +0 -32
  182. data/package/utils/__tests__/deep_merge.js +0 -10
  183. data/package/utils/__tests__/get_style_rule.js +0 -65
  184. data/package/utils/__tests__/objectify.js +0 -9
  185. data/package/utils/deep_assign.js +0 -22
  186. data/package/utils/deep_merge.js +0 -22
  187. data/package/utils/objectify.js +0 -3
  188. /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
  189. /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
@@ -1,77 +1,79 @@
1
- const TerserPlugin = require('terser-webpack-plugin')
1
+ /* eslint global-require: 0 */
2
+ /* eslint import/no-dynamic-require: 0 */
3
+
4
+ const { merge } = require('webpack-merge')
2
5
  const CompressionPlugin = require('compression-webpack-plugin')
3
- const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
4
- const safePostCssParser = require('postcss-safe-parser')
5
- const Base = require('./base')
6
+ const TerserPlugin = require('terser-webpack-plugin')
7
+ const baseConfig = require('./base')
8
+ const { moduleExists } = require('../utils/helpers')
9
+
10
+ const getPlugins = () => {
11
+ const plugins = []
6
12
 
7
- module.exports = class extends Base {
8
- constructor() {
9
- super()
13
+ plugins.push(
14
+ new CompressionPlugin({
15
+ filename: '[path][base].gz[query]',
16
+ algorithm: 'gzip',
17
+ test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
18
+ })
19
+ )
10
20
 
11
- this.plugins.append(
12
- 'Compression',
21
+ if ('brotli' in process.versions) {
22
+ plugins.push(
13
23
  new CompressionPlugin({
14
- filename: '[path].gz[query]',
15
- algorithm: 'gzip',
24
+ filename: '[path][base].br[query]',
25
+ algorithm: 'brotliCompress',
16
26
  test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
17
27
  })
18
28
  )
29
+ }
19
30
 
20
- if ('brotli' in process.versions) {
21
- this.plugins.append(
22
- 'Compression Brotli',
23
- new CompressionPlugin({
24
- filename: '[path].br[query]',
25
- algorithm: 'brotliCompress',
26
- test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
27
- })
28
- )
29
- }
31
+ return plugins
32
+ }
30
33
 
31
- this.plugins.append(
32
- 'OptimizeCSSAssets',
33
- new OptimizeCSSAssetsPlugin({
34
- parser: safePostCssParser,
35
- map: {
36
- inline: false,
37
- annotation: true
34
+ const tryCssMinimizer = () => {
35
+ if (
36
+ moduleExists('css-loader') &&
37
+ moduleExists('css-minimizer-webpack-plugin')
38
+ ) {
39
+ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
40
+ return new CssMinimizerPlugin()
41
+ }
42
+
43
+ return null
44
+ }
45
+
46
+ const productionConfig = {
47
+ devtool: 'source-map',
48
+ stats: 'normal',
49
+ bail: true,
50
+ plugins: getPlugins(),
51
+ optimization: {
52
+ minimizer: [
53
+ tryCssMinimizer(),
54
+ new TerserPlugin({
55
+ parallel: Number.parseInt(process.env.WEBPACKER_PARALLEL, 10) || true,
56
+ terserOptions: {
57
+ parse: {
58
+ // Let terser parse ecma 8 code but always output
59
+ // ES5 compliant code for older browsers
60
+ ecma: 8
61
+ },
62
+ compress: {
63
+ ecma: 5,
64
+ warnings: false,
65
+ comparisons: false
66
+ },
67
+ mangle: { safari10: true },
68
+ output: {
69
+ ecma: 5,
70
+ comments: false,
71
+ ascii_only: true
72
+ }
38
73
  }
39
74
  })
40
- )
41
-
42
- this.config.merge({
43
- devtool: 'source-map',
44
- stats: 'normal',
45
- bail: true,
46
- optimization: {
47
- minimizer: [
48
- new TerserPlugin({
49
- parallel: Number.parseInt(process.env.WEBPACKER_PARALLEL, 10) || true,
50
- cache: true,
51
- sourceMap: true,
52
- terserOptions: {
53
- parse: {
54
- // Let terser parse ecma 8 code but always output
55
- // ES5 compliant code for older browsers
56
- ecma: 8
57
- },
58
- compress: {
59
- ecma: 5,
60
- warnings: false,
61
- comparisons: false
62
- },
63
- mangle: {
64
- safari10: true
65
- },
66
- output: {
67
- ecma: 5,
68
- comments: false,
69
- ascii_only: true
70
- }
71
- }
72
- })
73
- ]
74
- }
75
- })
75
+ ].filter(Boolean)
76
76
  }
77
77
  }
78
+
79
+ module.exports = merge(baseConfig, productionConfig)
@@ -1,3 +1,3 @@
1
- const Base = require('./base')
1
+ const baseConfig = require('./base')
2
2
 
3
- module.exports = class extends Base {}
3
+ module.exports = baseConfig
data/package/index.js CHANGED
@@ -1,24 +1,31 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
+ const webpackMerge = require('webpack-merge')
4
5
  const { resolve } = require('path')
5
6
  const { existsSync } = require('fs')
6
- const Environment = require('./environments/base')
7
- const loaders = require('./rules')
7
+ const baseConfig = require('./environments/base')
8
+ const rules = require('./rules')
8
9
  const config = require('./config')
9
10
  const devServer = require('./dev_server')
10
11
  const { nodeEnv } = require('./env')
12
+ const { moduleExists, canProcess } = require('./utils/helpers')
13
+ const inliningCss = require('./inliningCss')
11
14
 
12
- const createEnvironment = () => {
15
+ const webpackConfig = () => {
13
16
  const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
14
- const constructor = existsSync(path) ? require(path) : Environment
15
- return new constructor()
17
+ const environmentConfig = existsSync(path) ? require(path) : baseConfig
18
+ return environmentConfig
16
19
  }
17
20
 
18
21
  module.exports = {
19
22
  config,
20
23
  devServer,
21
- environment: createEnvironment(),
22
- Environment,
23
- loaders
24
+ webpackConfig: webpackConfig(),
25
+ baseConfig,
26
+ rules,
27
+ moduleExists,
28
+ canProcess,
29
+ inliningCss,
30
+ ...webpackMerge
24
31
  }
@@ -0,0 +1,7 @@
1
+ const { runningWebpackDevServer } = require('./env')
2
+ const devServer = require('./dev_server')
3
+
4
+ // This logic is tied to lib/webpacker/instance.rb
5
+ const inliningCss = runningWebpackDevServer && devServer.hmr
6
+
7
+ module.exports = inliningCss
@@ -1,12 +1,14 @@
1
1
  const { resolve } = require('path')
2
2
  const { realpathSync } = require('fs')
3
- const { source_path: sourcePath, additional_paths: additionalPaths } = require('../config')
4
- const { nodeEnv } = require('../env')
5
3
 
6
- // Process application Javascript code with Babel.
7
- // Uses application .babelrc to apply any transformations
4
+ const {
5
+ source_path: sourcePath,
6
+ additional_paths: additionalPaths
7
+ } = require('../config')
8
+ const { isProduction } = require('../env')
9
+
8
10
  module.exports = {
9
- test: /\.(js|jsx|mjs|ts|tsx)?(\.erb)?$/,
11
+ test: /\.(js|jsx|mjs|ts|tsx|coffee)?(\.erb)?$/,
10
12
  include: [sourcePath, ...additionalPaths].map((p) => {
11
13
  try {
12
14
  return realpathSync(p)
@@ -17,11 +19,11 @@ module.exports = {
17
19
  exclude: /node_modules/,
18
20
  use: [
19
21
  {
20
- loader: 'babel-loader',
22
+ loader: require.resolve('babel-loader'),
21
23
  options: {
22
24
  cacheDirectory: true,
23
- cacheCompression: nodeEnv === 'production',
24
- compact: nodeEnv === 'production'
25
+ cacheCompression: isProduction,
26
+ compact: isProduction
25
27
  }
26
28
  }
27
29
  ]
@@ -0,0 +1,6 @@
1
+ const { canProcess } = require('../utils/helpers')
2
+
3
+ module.exports = canProcess('coffee-loader', (resolvedPath) => ({
4
+ test: /\.coffee(\.erb)?$/,
5
+ use: [{ loader: resolvedPath }]
6
+ }))
@@ -0,0 +1,15 @@
1
+ const { canProcess } = require('../utils/helpers')
2
+
3
+ const runner = /^win/.test(process.platform) ? 'ruby ' : ''
4
+
5
+ module.exports = canProcess('rails-erb-loader', (resolvedPath) => ({
6
+ test: /\.erb$/,
7
+ enforce: 'pre',
8
+ exclude: /node_modules/,
9
+ use: [
10
+ {
11
+ loader: resolvedPath,
12
+ options: { runner: `${runner}bin/rails runner` }
13
+ }
14
+ ]
15
+ }))
@@ -1,21 +1,23 @@
1
- const { join, normalize } = require('path')
2
- const { source_path: sourcePath, static_assets_extensions: fileExtensions } = require('../config')
3
-
4
1
  module.exports = {
5
- test: new RegExp(`(${fileExtensions.join('|')})$`, 'i'),
6
- use: [
7
- {
8
- loader: 'file-loader',
9
- options: {
10
- name(file) {
11
- if (file.includes(normalize(sourcePath))) {
12
- return 'media/[path][name]-[hash].[ext]'
13
- }
14
- return 'media/[folder]/[name]-[hash:8].[ext]'
15
- },
16
- esModule: false,
17
- context: join(sourcePath)
18
- }
19
- }
20
- ]
2
+ test: [
3
+ /\.bmp$/,
4
+ /\.gif$/,
5
+ /\.jpe?g$/,
6
+ /\.png$/,
7
+ /\.tiff$/,
8
+ /\.ico$/,
9
+ /\.avif$/,
10
+ /\.webp$/,
11
+ /\.eot$/,
12
+ /\.otf$/,
13
+ /\.ttf$/,
14
+ /\.woff$/,
15
+ /\.woff2$/,
16
+ /\.svg$/
17
+ ],
18
+ exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
19
+ type: 'asset/resource',
20
+ generator: {
21
+ filename: 'static/[name]-[hash][ext][query]'
22
+ }
21
23
  }
@@ -1,20 +1,18 @@
1
- const babel = require('./babel')
2
- const file = require('./file')
3
- const css = require('./css')
4
- const sass = require('./sass')
5
- const moduleCss = require('./module.css')
6
- const moduleSass = require('./module.sass')
7
- const nodeModules = require('./node_modules')
1
+ /* eslint global-require: 0 */
2
+ /* eslint import/no-dynamic-require: 0 */
8
3
 
9
- // Webpack loaders are processed in reverse order
10
- // https://webpack.js.org/concepts/loaders/#loader-features
11
- // Lastly, process static files using file loader
12
- module.exports = {
13
- file,
14
- css,
15
- sass,
16
- moduleCss,
17
- moduleSass,
18
- nodeModules,
19
- babel
4
+ const rules = {
5
+ raw: require('./raw'),
6
+ file: require('./file'),
7
+ css: require('./css'),
8
+ sass: require('./sass'),
9
+ babel: require('./babel'),
10
+ erb: require('./erb'),
11
+ coffee: require('./coffee'),
12
+ less: require('./less'),
13
+ stylus: require('./stylus')
20
14
  }
15
+
16
+ module.exports = Object.keys(rules)
17
+ .filter((key) => !!rules[key])
18
+ .map((key) => rules[key])
@@ -0,0 +1,22 @@
1
+ const path = require('path')
2
+ const { canProcess } = require('../utils/helpers')
3
+ const getStyleRule = require('../utils/get_style_rule')
4
+
5
+ const {
6
+ additional_paths: paths,
7
+ source_path: sourcePath
8
+ } = require('../config')
9
+
10
+ module.exports = canProcess('less-loader', (resolvedPath) =>
11
+ getStyleRule(/\.(less)(\.erb)?$/i, [
12
+ {
13
+ loader: resolvedPath,
14
+ options: {
15
+ lessOptions: {
16
+ paths: [path.resolve(__dirname, 'node_modules'), sourcePath, ...paths]
17
+ },
18
+ sourceMap: true
19
+ }
20
+ }
21
+ ])
22
+ )
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ test: [/\.html$/],
3
+ exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
4
+ type: 'asset/source'
5
+ }
@@ -1,17 +1,16 @@
1
1
  /* eslint global-require: 0 */
2
2
 
3
3
  const getStyleRule = require('../utils/get_style_rule')
4
+ const { canProcess } = require('../utils/helpers')
4
5
  const { additional_paths: includePaths } = require('../config')
5
6
 
6
- module.exports = getStyleRule(/\.(scss|sass)(\.erb)?$/i, false, [
7
- {
8
- loader: 'sass-loader',
9
- options: {
10
- sourceMap: true,
11
- implementation: require('sass'),
12
- sassOptions: {
13
- includePaths
7
+ module.exports = canProcess('sass-loader', (resolvedPath) =>
8
+ getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
9
+ {
10
+ loader: resolvedPath,
11
+ options: {
12
+ sassOptions: { includePaths }
14
13
  }
15
14
  }
16
- }
17
- ])
15
+ ])
16
+ )
@@ -0,0 +1,26 @@
1
+ const path = require('path')
2
+ const { canProcess } = require('../utils/helpers')
3
+ const getStyleRule = require('../utils/get_style_rule')
4
+
5
+ const {
6
+ additional_paths: paths,
7
+ source_path: sourcePath
8
+ } = require('../config')
9
+
10
+ module.exports = canProcess('stylus-loader', (resolvedPath) =>
11
+ getStyleRule(/\.(styl(us)?)(\.erb)?$/i, [
12
+ {
13
+ loader: resolvedPath,
14
+ options: {
15
+ stylusOptions: {
16
+ include: [
17
+ path.resolve(__dirname, 'node_modules'),
18
+ sourcePath,
19
+ ...paths
20
+ ]
21
+ },
22
+ sourceMap: true
23
+ }
24
+ }
25
+ ])
26
+ )
@@ -1,45 +1,37 @@
1
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2
- const { resolve } = require('path')
3
- const config = require('../config')
1
+ /* eslint global-require: 0 */
2
+ const { canProcess, moduleExists } = require('./helpers')
3
+ const inliningCss = require('../inliningCss')
4
4
 
5
- const styleLoader = {
6
- loader: 'style-loader'
7
- }
5
+ const getStyleRule = (test, preprocessors = []) => {
6
+ if (moduleExists('css-loader')) {
7
+ const tryPostcss = () =>
8
+ canProcess('postcss-loader', (loaderPath) => ({
9
+ loader: loaderPath,
10
+ options: { sourceMap: true }
11
+ }))
8
12
 
9
- const getStyleRule = (test, modules = false, preprocessors = []) => {
10
- const use = [
11
- {
12
- loader: 'css-loader',
13
- options: {
14
- sourceMap: true,
15
- importLoaders: 2,
16
- modules: modules ? {
17
- localIdentName: '[name]__[local]___[hash:base64:5]'
18
- } : false
19
- }
20
- },
21
- {
22
- loader: 'postcss-loader',
23
- options: {
24
- config: { path: resolve() },
25
- sourceMap: true
26
- }
27
- },
28
- ...preprocessors
29
- ]
13
+ // style-loader is required when using css modules with HMR on the webpack-dev-server
30
14
 
31
- const options = modules ? { include: /\.module\.[a-z]+$/ } : { exclude: /\.module\.[a-z]+$/ }
15
+ const use = [
16
+ inliningCss ? 'style-loader' : require('mini-css-extract-plugin').loader,
17
+ {
18
+ loader: require.resolve('css-loader'),
19
+ options: {
20
+ sourceMap: true,
21
+ importLoaders: 2
22
+ }
23
+ },
24
+ tryPostcss(),
25
+ ...preprocessors
26
+ ].filter(Boolean)
32
27
 
33
- if (config.extract_css) {
34
- use.unshift(MiniCssExtractPlugin.loader)
35
- } else {
36
- use.unshift(styleLoader)
28
+ return {
29
+ test,
30
+ use
31
+ }
37
32
  }
38
33
 
39
- // sideEffects - See https://github.com/webpack/webpack/issues/6571
40
- return {
41
- test, use, sideEffects: !modules, ...options
42
- }
34
+ return null
43
35
  }
44
36
 
45
37
  module.exports = getStyleRule
@@ -1,30 +1,5 @@
1
- const { stringify } = require('flatted')
2
-
3
- const isObject = (value) => typeof value === 'object'
4
- && value !== null
5
- && (value.length === undefined || value.length === null)
6
-
7
- const isNotObject = (value) => !isObject(value)
8
-
9
- const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
10
-
11
- const isEmpty = (value) => value === null || value === undefined
12
-
13
- const isString = (key) => key && typeof key === 'string'
14
-
15
- const isStrPath = (key) => {
16
- if (!isString(key)) throw new Error(`Key ${key} should be string`)
17
- return isString(key) && key.includes('.')
18
- }
19
-
20
1
  const isArray = (value) => Array.isArray(value)
21
-
22
- const isEqual = (target, source) => stringify(target) === stringify(source)
23
-
24
- const canMerge = (value) => isObject(value) || isArray(value)
25
-
26
- const prettyPrint = (obj) => JSON.stringify(obj, null, 2)
27
-
2
+ const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
28
3
  const chdirTestApp = () => {
29
4
  try {
30
5
  return process.chdir('test/test_app')
@@ -41,18 +16,36 @@ const resetEnv = () => {
41
16
 
42
17
  const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
43
18
 
19
+ const resolvedPath = (packageName) => {
20
+ try {
21
+ return require.resolve(packageName)
22
+ } catch (e) {
23
+ if (e.code !== 'MODULE_NOT_FOUND') {
24
+ throw e
25
+ }
26
+ return null
27
+ }
28
+ }
29
+
30
+ const moduleExists = (packageName) => (!!resolvedPath(packageName))
31
+
32
+ const canProcess = (rule, fn) => {
33
+ const modulePath = resolvedPath(rule)
34
+
35
+ if (modulePath) {
36
+ return fn(modulePath)
37
+ }
38
+
39
+ return null
40
+ }
41
+
44
42
  module.exports = {
45
43
  chdirTestApp,
46
44
  chdirCwd,
47
- ensureTrailingSlash,
48
- isObject,
49
- isNotObject,
50
- isBoolean,
51
45
  isArray,
52
- isEqual,
53
- isEmpty,
54
- isStrPath,
55
- canMerge,
56
- prettyPrint,
46
+ isBoolean,
47
+ ensureTrailingSlash,
48
+ canProcess,
49
+ moduleExists,
57
50
  resetEnv
58
51
  }
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rails/webpacker",
3
- "version": "5.4.3",
3
+ "version": "6.0.0-rc.6",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
6
  "files": [
@@ -8,56 +8,36 @@
8
8
  "lib/install/config/webpacker.yml"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=10.17.0",
11
+ "node": ">= 12.13.0 || >=14",
12
12
  "yarn": ">=1 <4"
13
13
  },
14
14
  "dependencies": {
15
- "@babel/core": "^7.15.0",
15
+ "@babel/core": "^7.15.5",
16
16
  "@babel/plugin-proposal-class-properties": "^7.14.5",
17
- "@babel/plugin-proposal-object-rest-spread": "^7.14.7",
18
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
19
- "@babel/plugin-transform-destructuring": "^7.14.7",
20
- "@babel/plugin-transform-regenerator": "^7.14.5",
21
17
  "@babel/plugin-transform-runtime": "^7.15.0",
22
- "@babel/preset-env": "^7.15.0",
23
- "@babel/runtime": "^7.15.3",
18
+ "@babel/preset-env": "^7.15.6",
19
+ "@babel/runtime": "^7.15.4",
24
20
  "babel-loader": "^8.2.2",
25
- "babel-plugin-dynamic-import-node": "^2.3.3",
26
- "babel-plugin-macros": "^2.8.0",
27
- "case-sensitive-paths-webpack-plugin": "^2.4.0",
28
- "compression-webpack-plugin": "^4.0.1",
29
- "core-js": "^3.16.2",
30
- "css-loader": "^3.6.0",
31
- "file-loader": "^6.2.0",
32
- "flatted": "^3.2.2",
33
- "glob": "^7.1.7",
34
- "js-yaml": "^3.14.1",
35
- "mini-css-extract-plugin": "^0.9.0",
36
- "optimize-css-assets-webpack-plugin": "^5.0.8",
21
+ "compression-webpack-plugin": "^9.0.0",
22
+ "glob": "^7.2.0",
23
+ "js-yaml": "^4.1.0",
37
24
  "path-complete-extname": "^1.0.0",
38
25
  "pnp-webpack-plugin": "^1.7.0",
39
- "postcss-flexbugs-fixes": "^4.2.1",
40
- "postcss-import": "^12.0.1",
41
- "postcss-loader": "^3.0.0",
42
- "postcss-preset-env": "^6.7.0",
43
- "postcss-safe-parser": "^4.0.2",
44
- "regenerator-runtime": "^0.13.9",
45
- "sass": "^1.38.0",
46
- "sass-loader": "10.1.1",
47
- "style-loader": "^1.3.0",
48
- "terser-webpack-plugin": "^4.2.3",
49
- "webpack": "^4.46.0",
50
- "webpack-assets-manifest": "^3.1.1",
51
- "webpack-cli": "^3.3.12",
52
- "webpack-sources": "^1.4.3"
26
+ "terser-webpack-plugin": "^5.2.4",
27
+ "webpack": "^5.53.0",
28
+ "webpack-assets-manifest": "^5.0.6",
29
+ "webpack-cli": "^4.8.0",
30
+ "webpack-merge": "^5.8.0",
31
+ "webpack-sources": "^3.2.1"
53
32
  },
54
33
  "devDependencies": {
55
34
  "eslint": "^7.32.0",
56
35
  "eslint-config-airbnb": "^18.2.1",
57
- "eslint-plugin-import": "^2.24.0",
36
+ "eslint-config-prettier": "^8.3.0",
37
+ "eslint-plugin-import": "^2.24.2",
58
38
  "eslint-plugin-jsx-a11y": "^6.4.1",
59
- "eslint-plugin-react": "^7.24.0",
60
- "jest": "^27.0.6"
39
+ "eslint-plugin-react": "^7.26.0",
40
+ "jest": "^27.2.1"
61
41
  },
62
42
  "jest": {
63
43
  "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",