webpacker 5.0.1 → 6.0.0.beta

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 (172) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +38 -0
  4. data/.github/workflows/js-lint.yml +39 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +70 -0
  7. data/.gitignore +2 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +11 -16
  10. data/6_0_upgrade.md +43 -0
  11. data/CHANGELOG.md +49 -3
  12. data/CONTRIBUTING.md +1 -1
  13. data/Gemfile.lock +91 -85
  14. data/README.md +233 -133
  15. data/lib/install/config/webpack/base.js +3 -0
  16. data/lib/install/config/webpack/development.js +2 -2
  17. data/lib/install/config/webpack/production.js +2 -2
  18. data/lib/install/config/webpack/test.js +2 -2
  19. data/lib/install/config/webpacker.yml +9 -42
  20. data/lib/install/javascript/packs/application.css +9 -0
  21. data/lib/install/javascript/packs/application.js +3 -1
  22. data/lib/install/template.rb +33 -19
  23. data/lib/tasks/webpacker.rake +2 -11
  24. data/lib/tasks/webpacker/binstubs.rake +6 -4
  25. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  26. data/lib/tasks/webpacker/check_node.rake +1 -1
  27. data/lib/tasks/webpacker/check_yarn.rake +2 -3
  28. data/lib/tasks/webpacker/compile.rake +4 -2
  29. data/lib/tasks/webpacker/info.rake +12 -10
  30. data/lib/tasks/webpacker/install.rake +6 -4
  31. data/lib/tasks/webpacker/verify_install.rake +2 -1
  32. data/lib/tasks/webpacker/yarn_install.rake +9 -1
  33. data/lib/webpacker/commands.rb +1 -1
  34. data/lib/webpacker/compiler.rb +22 -11
  35. data/lib/webpacker/configuration.rb +7 -27
  36. data/lib/webpacker/dev_server_proxy.rb +3 -1
  37. data/lib/webpacker/dev_server_runner.rb +23 -4
  38. data/lib/webpacker/helper.rb +55 -46
  39. data/lib/webpacker/manifest.rb +1 -1
  40. data/lib/webpacker/railtie.rb +0 -43
  41. data/lib/webpacker/runner.rb +1 -0
  42. data/lib/webpacker/version.rb +1 -1
  43. data/lib/webpacker/webpack_runner.rb +7 -2
  44. data/package.json +27 -43
  45. data/package/__tests__/config.js +6 -27
  46. data/package/__tests__/dev_server.js +2 -0
  47. data/package/__tests__/development.js +18 -7
  48. data/package/__tests__/env.js +12 -4
  49. data/package/__tests__/production.js +6 -6
  50. data/package/__tests__/staging.js +7 -6
  51. data/package/__tests__/test.js +4 -5
  52. data/package/babel/preset.js +55 -0
  53. data/package/config.js +4 -9
  54. data/package/configPath.js +3 -0
  55. data/package/dev_server.js +1 -1
  56. data/package/env.js +9 -4
  57. data/package/environments/__tests__/base.js +21 -36
  58. data/package/environments/base.js +63 -127
  59. data/package/environments/development.js +46 -39
  60. data/package/environments/production.js +63 -70
  61. data/package/environments/test.js +2 -2
  62. data/package/index.js +13 -8
  63. data/package/rules/babel.js +20 -11
  64. data/package/rules/coffee.js +6 -0
  65. data/package/rules/erb.js +15 -0
  66. data/package/rules/file.js +19 -18
  67. data/package/rules/index.js +15 -18
  68. data/package/rules/less.js +22 -0
  69. data/package/rules/sass.js +13 -10
  70. data/package/rules/svg.js +20 -0
  71. data/package/utils/get_style_rule.js +26 -36
  72. data/package/utils/helpers.js +26 -35
  73. data/test/compiler_test.rb +4 -11
  74. data/test/configuration_test.rb +2 -32
  75. data/test/dev_server_runner_test.rb +25 -6
  76. data/test/engine_rake_tasks_test.rb +39 -0
  77. data/test/helper_test.rb +18 -9
  78. data/test/mounted_app/Rakefile +4 -0
  79. data/test/mounted_app/test/dummy/Rakefile +3 -0
  80. data/test/mounted_app/test/dummy/bin/rails +3 -0
  81. data/test/mounted_app/test/dummy/bin/rake +3 -0
  82. data/test/mounted_app/test/dummy/config.ru +5 -0
  83. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  84. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  85. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  86. data/test/mounted_app/test/dummy/package.json +7 -0
  87. data/test/rake_tasks_test.rb +1 -10
  88. data/test/test_app/config/application.rb +0 -1
  89. data/test/test_app/config/webpacker.yml +3 -21
  90. data/test/test_app/config/webpacker_public_root.yml +0 -1
  91. data/test/test_app/public/packs/manifest.json +18 -13
  92. data/test/test_app/some.config.js +0 -0
  93. data/test/webpack_runner_test.rb +10 -4
  94. data/webpacker.gemspec +1 -1
  95. data/yarn.lock +2657 -6224
  96. metadata +49 -90
  97. data/.travis.yml +0 -43
  98. data/docs/assets.md +0 -119
  99. data/docs/cloud9.md +0 -310
  100. data/docs/css.md +0 -253
  101. data/docs/deployment.md +0 -130
  102. data/docs/docker.md +0 -68
  103. data/docs/engines.md +0 -213
  104. data/docs/env.md +0 -65
  105. data/docs/es6.md +0 -72
  106. data/docs/folder-structure.md +0 -66
  107. data/docs/integrations.md +0 -220
  108. data/docs/misc.md +0 -23
  109. data/docs/props.md +0 -223
  110. data/docs/testing.md +0 -137
  111. data/docs/troubleshooting.md +0 -156
  112. data/docs/typescript.md +0 -125
  113. data/docs/v4-upgrade.md +0 -142
  114. data/docs/webpack-dev-server.md +0 -92
  115. data/docs/webpack.md +0 -364
  116. data/docs/yarn.md +0 -23
  117. data/lib/install/angular.rb +0 -23
  118. data/lib/install/coffee.rb +0 -25
  119. data/lib/install/config/.browserslistrc +0 -1
  120. data/lib/install/config/babel.config.js +0 -72
  121. data/lib/install/config/postcss.config.js +0 -12
  122. data/lib/install/config/webpack/environment.js +0 -3
  123. data/lib/install/elm.rb +0 -39
  124. data/lib/install/erb.rb +0 -25
  125. data/lib/install/examples/angular/hello_angular.js +0 -7
  126. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  127. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  128. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  129. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  130. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  131. data/lib/install/examples/elm/Main.elm +0 -55
  132. data/lib/install/examples/elm/hello_elm.js +0 -16
  133. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  134. data/lib/install/examples/react/babel.config.js +0 -87
  135. data/lib/install/examples/react/hello_react.jsx +0 -26
  136. data/lib/install/examples/react/tsconfig.json +0 -20
  137. data/lib/install/examples/stimulus/application.js +0 -1
  138. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  139. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  140. data/lib/install/examples/svelte/app.svelte +0 -11
  141. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  142. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  143. data/lib/install/examples/typescript/tsconfig.json +0 -23
  144. data/lib/install/examples/vue/app.vue +0 -22
  145. data/lib/install/examples/vue/hello_vue.js +0 -72
  146. data/lib/install/loaders/coffee.js +0 -6
  147. data/lib/install/loaders/elm.js +0 -25
  148. data/lib/install/loaders/erb.js +0 -11
  149. data/lib/install/loaders/svelte.js +0 -9
  150. data/lib/install/loaders/typescript.js +0 -11
  151. data/lib/install/loaders/vue.js +0 -6
  152. data/lib/install/react.rb +0 -18
  153. data/lib/install/stimulus.rb +0 -12
  154. data/lib/install/svelte.rb +0 -29
  155. data/lib/install/typescript.rb +0 -46
  156. data/lib/install/vue.rb +0 -49
  157. data/lib/tasks/installers.rake +0 -42
  158. data/package/config_types/__tests__/config_list.js +0 -118
  159. data/package/config_types/__tests__/config_object.js +0 -43
  160. data/package/config_types/config_list.js +0 -75
  161. data/package/config_types/config_object.js +0 -55
  162. data/package/config_types/index.js +0 -7
  163. data/package/rules/module.css.js +0 -3
  164. data/package/rules/module.sass.js +0 -8
  165. data/package/rules/node_modules.js +0 -24
  166. data/package/utils/__tests__/deep_assign.js +0 -32
  167. data/package/utils/__tests__/deep_merge.js +0 -10
  168. data/package/utils/__tests__/get_style_rule.js +0 -65
  169. data/package/utils/__tests__/objectify.js +0 -9
  170. data/package/utils/deep_assign.js +0 -22
  171. data/package/utils/deep_merge.js +0 -22
  172. data/package/utils/objectify.js +0 -3
@@ -1,8 +0,0 @@
1
- const getStyleRule = require('../utils/get_style_rule')
2
-
3
- module.exports = getStyleRule(/\.(scss|sass)$/i, true, [
4
- {
5
- loader: 'sass-loader',
6
- options: { sourceMap: true }
7
- }
8
- ])
@@ -1,24 +0,0 @@
1
- const { join } = require('path')
2
- const { cache_path: cachePath } = require('../config')
3
- const { nodeEnv } = require('../env')
4
-
5
- // Compile standard ES features for JS in node_modules with Babel.
6
- // Regex details for exclude: https://regex101.com/r/SKPnnv/1
7
- module.exports = {
8
- test: /\.(js|mjs)$/,
9
- include: /node_modules/,
10
- exclude: /(?:@?babel(?:\/|\\{1,2}|-).+)|regenerator-runtime|core-js|^webpack$|^webpack-assets-manifest$|^webpack-cli$|^webpack-sources$|^@rails\/webpacker$/,
11
- use: [
12
- {
13
- loader: 'babel-loader',
14
- options: {
15
- babelrc: false,
16
- presets: [['@babel/preset-env', { modules: false }]],
17
- cacheDirectory: join(cachePath, 'babel-loader-node-modules'),
18
- cacheCompression: nodeEnv === 'production',
19
- compact: false,
20
- sourceMaps: false
21
- }
22
- }
23
- ]
24
- }
@@ -1,32 +0,0 @@
1
- /* global test expect */
2
-
3
- const deepAssign = require('../deep_assign')
4
-
5
- describe('deepAssign()', () => {
6
- test('deeply assigns nested properties', () => {
7
- const object = { foo: { bar: { } } }
8
- const path = 'foo.bar'
9
- const value = { x: 1, y: 2 }
10
- const expectation = { foo: { bar: { x: 1, y: 2 } } }
11
- expect(deepAssign(object, path, value)).toEqual(expectation)
12
- })
13
-
14
- test('allows assignment of a literal false', () => {
15
- const object = { foo: { bar: { } } }
16
- const path = 'foo.bar'
17
- const value = false
18
- const expectation = { foo: { bar: false } }
19
- expect(deepAssign(object, path, value)).toEqual(expectation)
20
- })
21
-
22
- test('does not allow assignment of other falsy values', () => {
23
- const object = { foo: { bar: { } } }
24
- const path = 'foo.bar'
25
- const values = [undefined, null, 0, '']
26
-
27
- values.forEach(value => {
28
- const expectation = new Error(`Value can't be ${value}`)
29
- expect(() => deepAssign(object, path, value)).toThrow(expectation)
30
- })
31
- })
32
- })
@@ -1,10 +0,0 @@
1
- /* global test expect */
2
-
3
- const deepMerge = require('../deep_merge')
4
-
5
- test('deep merge objects together', () => {
6
- const object1 = { foo: { bar: [1, 2, 3], z: 1 }, x: 0 }
7
- const object2 = { foo: { bar: ['x', 'y'] }, x: 1, y: 2 }
8
- const expectation = { foo: { bar: [1, 2, 3, 'x', 'y'], z: 1 }, x: 1, y: 2 }
9
- expect(deepMerge(object1, object2)).toEqual(expectation)
10
- })
@@ -1,65 +0,0 @@
1
- const { chdirTestApp, chdirCwd } = require('../helpers')
2
-
3
- chdirTestApp()
4
-
5
- const getStyleRule = require('../get_style_rule')
6
-
7
- describe('getStyleRule', () => {
8
- afterAll(chdirCwd)
9
-
10
- test('excludes modules by default', () => {
11
- const cssRule = getStyleRule(/\.(css)$/i)
12
- const expectation = {
13
- test: /\.(css)$/i,
14
- exclude: /\.module\.[a-z]+$/
15
- }
16
-
17
- expect(cssRule).toMatchObject(expectation)
18
- })
19
-
20
- test('includes modules if set to true', () => {
21
- const cssRule = getStyleRule(/\.(scss)$/i, true)
22
- const expectation = {
23
- test: /\.(scss)$/i,
24
- include: /\.module\.[a-z]+$/
25
- }
26
-
27
- expect(cssRule).toMatchObject(expectation)
28
- })
29
-
30
- test('adds extra preprocessors if supplied', () => {
31
- const expectation = [{ foo: 'bar' }]
32
- const cssRule = getStyleRule(/\.(css)$/i, true, expectation)
33
-
34
- expect(cssRule.use).toMatchObject(expect.arrayContaining(expectation))
35
- })
36
-
37
- test('adds mini-css-extract-plugin when extract_css is true', () => {
38
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
39
- const expectation = [MiniCssExtractPlugin.loader]
40
-
41
- require('../../config').extract_css = true
42
- const cssRule = getStyleRule(/\.(css)$/i)
43
-
44
- expect(cssRule.use).toMatchObject(expect.arrayContaining(expectation))
45
- })
46
-
47
- test('adds style-loader when extract_css is true', () => {
48
- const expectation = [{loader: 'style-loader'}]
49
-
50
- require('../../config').extract_css = false
51
- const cssRule = getStyleRule(/\.(css)$/i)
52
-
53
- expect(cssRule.use).toMatchObject(expect.objectContaining(expectation))
54
- })
55
-
56
- test(`doesn't add mini-css-extract-plugin when extract_css is false`, () => {
57
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
58
- const expectation = [MiniCssExtractPlugin.loader]
59
-
60
- require('../../config').extract_css = false
61
- const cssRule = getStyleRule(/\.(css)$/i)
62
-
63
- expect(cssRule.use).toMatchObject(expect.not.arrayContaining(expectation))
64
- })
65
- })
@@ -1,9 +0,0 @@
1
- /* global test expect */
2
-
3
- const objectify = require('../objectify')
4
-
5
- test('Get object from a string path', () => {
6
- const object = { foo: { bar: { x: 1 } } }
7
- expect(objectify('foo.bar', object)).toEqual({ x: 1 })
8
- expect(objectify('some.bar', object)).toEqual(undefined)
9
- })
@@ -1,22 +0,0 @@
1
- const { canMerge, prettyPrint } = require('./helpers')
2
- const deepMerge = require('./deep_merge')
3
-
4
- const deepAssign = (obj, path, value) => {
5
- if (!value && value !== false) throw new Error(`Value can't be ${value}`)
6
-
7
- const keys = path.split('.')
8
- const key = keys.pop()
9
-
10
- const objRef = keys.reduce((acc, currentValue) => {
11
- /* eslint no-param-reassign: 0 */
12
- if (!acc[currentValue]) acc[currentValue] = {}
13
- return acc[currentValue]
14
- }, obj)
15
-
16
- if (!objRef) throw new Error(`Prop not found: ${path} in ${prettyPrint(obj)}`)
17
-
18
- objRef[key] = canMerge(value) ? deepMerge(objRef[key], value) : value
19
- return obj
20
- }
21
-
22
- module.exports = deepAssign
@@ -1,22 +0,0 @@
1
- const {
2
- isObject, isArray, isEqual, isEmpty
3
- } = require('./helpers')
4
-
5
- const deepMerge = (target, source) => {
6
- if (isEmpty(target)) return source
7
- if (isEmpty(source)) return target
8
- if (isEqual(target, source)) return source
9
- if (isArray(target) && isArray(source)) return [...new Set([...target, ...source])]
10
- if (!(isObject(target) && isObject(source))) return source
11
-
12
- return [...Object.keys(target), ...Object.keys(source)].reduce(
13
- (result, key) => ({
14
-
15
- ...result,
16
- [key]: deepMerge(target[key], source[key])
17
- }),
18
- {}
19
- )
20
- }
21
-
22
- module.exports = deepMerge
@@ -1,3 +0,0 @@
1
- const objectify = (path, obj) => path.split('.').reduce((prev, curr) => (prev ? prev[curr] : undefined), obj)
2
-
3
- module.exports = objectify