webpacker 6.0.0.pre.2 → 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.
- checksums.yaml +4 -4
- data/.github/workflows/jest.yml +7 -15
- data/.github/workflows/js-lint.yml +7 -15
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +18 -40
- data/.node-version +1 -1
- data/.rubocop.yml +107 -1
- data/CHANGELOG.md +48 -9
- data/CONTRIBUTING.md +20 -1
- data/Gemfile.lock +107 -104
- data/README.md +387 -177
- data/config/README.md +3 -0
- data/config/webpacker.yml +1 -0
- data/docs/deployment.md +9 -29
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +61 -25
- data/docs/v6_upgrade.md +113 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/{javascript/packs/application.js → application.js} +2 -5
- data/lib/install/bin/webpack +4 -7
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpacker.yml +18 -17
- data/lib/install/package.json +15 -0
- data/lib/install/template.rb +50 -21
- data/lib/tasks/webpacker/binstubs.rake +2 -2
- data/lib/tasks/webpacker/check_node.rake +3 -0
- data/lib/tasks/webpacker/check_yarn.rake +4 -1
- data/lib/tasks/webpacker/clobber.rake +1 -1
- data/lib/tasks/webpacker/install.rake +2 -2
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -11
- data/lib/tasks/yarn.rake +38 -0
- data/lib/webpacker/commands.rb +21 -16
- data/lib/webpacker/compiler.rb +9 -3
- data/lib/webpacker/configuration.rb +19 -8
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +7 -2
- data/lib/webpacker/env.rb +5 -1
- data/lib/webpacker/helper.rb +26 -50
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +1 -2
- data/lib/webpacker/railtie.rb +8 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +27 -6
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/development.js +4 -10
- data/package/__tests__/env.js +8 -4
- data/package/__tests__/index.js +9 -0
- data/package/babel/preset.js +24 -14
- data/package/config.js +3 -3
- data/package/env.js +6 -3
- data/package/environments/__tests__/base.js +7 -7
- data/package/environments/base.js +25 -25
- data/package/environments/development.js +36 -35
- data/package/environments/production.js +28 -30
- data/package/index.js +9 -2
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +1 -1
- data/package/rules/coffee.js +5 -5
- data/package/rules/erb.js +5 -3
- data/package/rules/file.js +5 -3
- data/package/rules/index.js +9 -17
- data/package/rules/less.js +14 -10
- data/package/rules/raw.js +5 -0
- data/package/rules/sass.js +12 -9
- data/package/rules/stylus.js +26 -0
- data/package/utils/get_style_rule.js +28 -30
- data/package/utils/helpers.js +25 -0
- data/package.json +25 -29
- data/test/command_test.rb +76 -0
- data/test/configuration_test.rb +3 -3
- data/test/dev_server_runner_test.rb +13 -2
- data/test/helper_test.rb +69 -61
- data/test/manifest_test.rb +16 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +4 -4
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
- data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/test/test_app/config/webpacker.yml +4 -6
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/public/packs/manifest.json +19 -5
- data/test/webpacker_test.rb +21 -0
- data/webpacker.gemspec +2 -2
- data/yarn.lock +2357 -3262
- metadata +34 -41
- data/docs/assets.md +0 -135
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -303
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -68
- data/docs/es6.md +0 -72
- data/docs/folder-structure.md +0 -66
- data/docs/integrations.md +0 -220
- data/docs/misc.md +0 -23
- data/docs/props.md +0 -187
- data/docs/react.md +0 -183
- data/docs/target.md +0 -22
- data/docs/testing.md +0 -147
- data/docs/typescript.md +0 -190
- data/docs/v4-upgrade.md +0 -142
- data/docs/webpack-dev-server.md +0 -94
- data/docs/webpack.md +0 -315
- data/docs/yarn.md +0 -23
- data/lib/install/examples/vue3/app.vue +0 -27
- data/lib/install/examples/vue3/hello_vue.js +0 -15
- data/lib/install/javascript/packs/application.css +0 -9
- data/package/babel/preset-react.js +0 -62
- data/package/rules/svg.js +0 -23
- /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
- /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
data/package/rules/sass.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint global-require: 0 */
|
|
2
|
+
|
|
2
3
|
const getStyleRule = require('../utils/get_style_rule')
|
|
4
|
+
const { canProcess } = require('../utils/helpers')
|
|
3
5
|
const { additional_paths: includePaths } = require('../config')
|
|
4
6
|
|
|
5
|
-
module.exports =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
module.exports = canProcess('sass-loader', (resolvedPath) =>
|
|
8
|
+
getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
|
|
9
|
+
{
|
|
10
|
+
loader: resolvedPath,
|
|
11
|
+
options: {
|
|
12
|
+
sassOptions: { includePaths }
|
|
13
|
+
}
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
|
|
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,39 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint global-require: 0 */
|
|
2
|
+
const { canProcess, moduleExists } = require('./helpers')
|
|
3
|
+
const inliningCss = require('../inliningCss')
|
|
2
4
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
loader: require.resolve('postcss-loader'),
|
|
5
|
+
const getStyleRule = (test, preprocessors = []) => {
|
|
6
|
+
if (moduleExists('css-loader')) {
|
|
7
|
+
const tryPostcss = () =>
|
|
8
|
+
canProcess('postcss-loader', (loaderPath) => ({
|
|
9
|
+
loader: loaderPath,
|
|
9
10
|
options: { sourceMap: true }
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
} catch (e) {
|
|
13
|
-
/* Work out what to print here */
|
|
14
|
-
}
|
|
11
|
+
}))
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
}
|
|
13
|
+
// style-loader is required when using css modules with HMR on the webpack-dev-server
|
|
18
14
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
].filter(Boolean)
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
return {
|
|
29
|
+
test,
|
|
30
|
+
use
|
|
31
|
+
}
|
|
36
32
|
}
|
|
33
|
+
|
|
34
|
+
return null
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
module.exports = getStyleRule
|
data/package/utils/helpers.js
CHANGED
|
@@ -16,11 +16,36 @@ const resetEnv = () => {
|
|
|
16
16
|
|
|
17
17
|
const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
|
|
18
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
|
+
|
|
19
42
|
module.exports = {
|
|
20
43
|
chdirTestApp,
|
|
21
44
|
chdirCwd,
|
|
22
45
|
isArray,
|
|
23
46
|
isBoolean,
|
|
24
47
|
ensureTrailingSlash,
|
|
48
|
+
canProcess,
|
|
49
|
+
moduleExists,
|
|
25
50
|
resetEnv
|
|
26
51
|
}
|
data/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rails/webpacker",
|
|
3
|
-
"version": "6.0.0-
|
|
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,40 +8,36 @@
|
|
|
8
8
|
"lib/install/config/webpacker.yml"
|
|
9
9
|
],
|
|
10
10
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
12
|
-
"yarn": ">=1 <
|
|
11
|
+
"node": ">= 12.13.0 || >=14",
|
|
12
|
+
"yarn": ">=1 <4"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@babel/core": "^7.
|
|
16
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
17
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
18
|
-
"@babel/preset-env": "^7.
|
|
19
|
-
"@babel/runtime": "^7.
|
|
15
|
+
"@babel/core": "^7.15.5",
|
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
|
17
|
+
"@babel/plugin-transform-runtime": "^7.15.0",
|
|
18
|
+
"@babel/preset-env": "^7.15.6",
|
|
19
|
+
"@babel/runtime": "^7.15.4",
|
|
20
20
|
"babel-loader": "^8.2.2",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"core-js": "^3.8.0",
|
|
25
|
-
"glob": "^7.1.6",
|
|
26
|
-
"js-yaml": "^3.14.0",
|
|
21
|
+
"compression-webpack-plugin": "^9.0.0",
|
|
22
|
+
"glob": "^7.2.0",
|
|
23
|
+
"js-yaml": "^4.1.0",
|
|
27
24
|
"path-complete-extname": "^1.0.0",
|
|
28
|
-
"pnp-webpack-plugin": "^1.
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"webpack": "^5.
|
|
32
|
-
"webpack-
|
|
33
|
-
"webpack-
|
|
34
|
-
"webpack-
|
|
35
|
-
"webpack-sources": "^2.2.0"
|
|
25
|
+
"pnp-webpack-plugin": "^1.7.0",
|
|
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"
|
|
36
32
|
},
|
|
37
33
|
"devDependencies": {
|
|
38
|
-
"eslint": "^7.
|
|
39
|
-
"eslint-config-airbnb": "^18.2.
|
|
40
|
-
"eslint-config-prettier": "^
|
|
41
|
-
"eslint-plugin-import": "^2.
|
|
42
|
-
"eslint-plugin-jsx-a11y": "^6.
|
|
43
|
-
"eslint-plugin-react": "^7.
|
|
44
|
-
"jest": "^
|
|
34
|
+
"eslint": "^7.32.0",
|
|
35
|
+
"eslint-config-airbnb": "^18.2.1",
|
|
36
|
+
"eslint-config-prettier": "^8.3.0",
|
|
37
|
+
"eslint-plugin-import": "^2.24.2",
|
|
38
|
+
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
39
|
+
"eslint-plugin-react": "^7.26.0",
|
|
40
|
+
"jest": "^27.2.1"
|
|
45
41
|
},
|
|
46
42
|
"jest": {
|
|
47
43
|
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|
data/test/command_test.rb
CHANGED
|
@@ -31,3 +31,79 @@ class CommandTest < Minitest::Test
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
class ClearCommandVersioningTest < Minitest::Test
|
|
36
|
+
def setup
|
|
37
|
+
@now = Time.parse("2021-01-01 12:34:56 UTC")
|
|
38
|
+
# Test assets to be kept and deleted, path and mtime
|
|
39
|
+
@prev_files = {
|
|
40
|
+
# recent versions to be kept with Webpacker.commands.clean(count = 2)
|
|
41
|
+
"js/application-deadbeef.js" => @now - 4000,
|
|
42
|
+
"js/common-deadbeee.js" => @now - 4002,
|
|
43
|
+
"css/common-deadbeed.css" => @now - 4004,
|
|
44
|
+
"media/images/logo-deadbeeb.css" => @now - 4006,
|
|
45
|
+
"js/application-1eadbeef.js" => @now - 8000,
|
|
46
|
+
"js/common-1eadbeee.js" => @now - 8002,
|
|
47
|
+
"css/common-1eadbeed.css" => @now - 8004,
|
|
48
|
+
"media/images/logo-1eadbeeb.css" => @now - 8006,
|
|
49
|
+
# new files to be kept with Webpacker.commands.clean(age = 3600)
|
|
50
|
+
"js/brandnew-0001.js" => @now,
|
|
51
|
+
"js/brandnew-0002.js" => @now - 10,
|
|
52
|
+
"js/brandnew-0003.js" => @now - 20,
|
|
53
|
+
"js/brandnew-0004.js" => @now - 40,
|
|
54
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
|
55
|
+
@expired_files = {
|
|
56
|
+
# old files that are outside count = 2 or age = 3600 and to be deleted
|
|
57
|
+
"js/application-0eadbeef.js" => @now - 9000,
|
|
58
|
+
"js/common-0eadbeee.js" => @now - 9002,
|
|
59
|
+
"css/common-0eadbeed.css" => @now - 9004,
|
|
60
|
+
"js/brandnew-0005.js" => @now - 3640,
|
|
61
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
|
62
|
+
@all_files = @prev_files.merge(@expired_files)
|
|
63
|
+
@dir_glob_stub = Proc.new { |arg|
|
|
64
|
+
case arg
|
|
65
|
+
when "#{Webpacker.config.public_output_path}/**/*"
|
|
66
|
+
@all_files.keys
|
|
67
|
+
else
|
|
68
|
+
[]
|
|
69
|
+
end
|
|
70
|
+
}
|
|
71
|
+
@file_mtime_stub = Proc.new { |longpath|
|
|
72
|
+
@all_files[longpath]
|
|
73
|
+
}
|
|
74
|
+
@file_delete_mock = Minitest::Mock.new
|
|
75
|
+
@expired_files.keys.each do |longpath|
|
|
76
|
+
@file_delete_mock.expect(:delete, 1, [longpath])
|
|
77
|
+
end
|
|
78
|
+
@file_delete_stub = Proc.new { |longpath|
|
|
79
|
+
if @prev_files.has_key?(longpath)
|
|
80
|
+
flunk "#{longpath} should not be deleted"
|
|
81
|
+
else
|
|
82
|
+
@file_delete_mock.delete(longpath)
|
|
83
|
+
end
|
|
84
|
+
}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def time_and_files_stub(&proc)
|
|
88
|
+
Time.stub :now, @now do
|
|
89
|
+
Dir.stub :glob, @dir_glob_stub do
|
|
90
|
+
File.stub :directory?, false do
|
|
91
|
+
File.stub :file?, true do
|
|
92
|
+
File.stub :mtime, @file_mtime_stub do
|
|
93
|
+
File.stub :delete, @file_delete_stub do
|
|
94
|
+
yield proc
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
@file_delete_mock.verify
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_clean_command_with_versioned_files
|
|
105
|
+
time_and_files_stub do
|
|
106
|
+
assert Webpacker.commands.clean
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
data/test/configuration_test.rb
CHANGED
|
@@ -10,12 +10,12 @@ class ConfigurationTest < Webpacker::Test
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def test_source_path
|
|
13
|
-
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/
|
|
13
|
+
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs").to_s
|
|
14
14
|
assert_equal source_path, @config.source_path.to_s
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def test_source_entry_path
|
|
18
|
-
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/
|
|
18
|
+
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs", "entrypoints").to_s
|
|
19
19
|
assert_equal @config.source_entry_path.to_s, source_entry_path
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -44,7 +44,7 @@ class ConfigurationTest < Webpacker::Test
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def test_cache_path
|
|
47
|
-
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/
|
|
47
|
+
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/webpacker").to_s
|
|
48
48
|
assert_equal @config.cache_path.to_s, cache_path
|
|
49
49
|
end
|
|
50
50
|
|
|
@@ -5,11 +5,13 @@ class DevServerRunnerTest < Webpacker::Test
|
|
|
5
5
|
def setup
|
|
6
6
|
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
|
7
7
|
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
|
8
|
+
@original_webpacker_config = ENV["WEBPACKER_CONFIG"]
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def teardown
|
|
11
12
|
ENV["NODE_ENV"] = @original_node_env
|
|
12
13
|
ENV["RAILS_ENV"] = @original_rails_env
|
|
14
|
+
ENV["WEBPACKER_CONFIG"] = @original_webpacker_config
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def test_run_cmd_via_node_modules
|
|
@@ -38,24 +40,33 @@ class DevServerRunnerTest < Webpacker::Test
|
|
|
38
40
|
def dev_server.port; "3035"; end
|
|
39
41
|
def dev_server.pretty?; false; end
|
|
40
42
|
def dev_server.https?; true; end
|
|
43
|
+
def dev_server.hmr?; false; end
|
|
41
44
|
Webpacker::DevServer.stub(:new, dev_server) do
|
|
42
45
|
verify_command(cmd, argv: ["--https"])
|
|
43
46
|
end
|
|
44
47
|
end
|
|
45
48
|
|
|
49
|
+
def test_environment_variables
|
|
50
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
|
|
51
|
+
env = Webpacker::Compiler.env.dup
|
|
52
|
+
ENV["WEBPACKER_CONFIG"] = env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
|
|
53
|
+
env["WEBPACK_SERVE"] = "true"
|
|
54
|
+
verify_command(cmd, env: env)
|
|
55
|
+
end
|
|
56
|
+
|
|
46
57
|
private
|
|
47
58
|
def test_app_path
|
|
48
59
|
File.expand_path("test_app", __dir__)
|
|
49
60
|
end
|
|
50
61
|
|
|
51
|
-
def verify_command(cmd, use_node_modules: true, argv: [])
|
|
62
|
+
def verify_command(cmd, use_node_modules: true, argv: [], env: Webpacker::Compiler.env)
|
|
52
63
|
cwd = Dir.pwd
|
|
53
64
|
Dir.chdir(test_app_path)
|
|
54
65
|
|
|
55
66
|
klass = Webpacker::DevServerRunner
|
|
56
67
|
instance = klass.new(argv)
|
|
57
68
|
mock = Minitest::Mock.new
|
|
58
|
-
mock.expect(:call, nil, [
|
|
69
|
+
mock.expect(:call, nil, [env, *cmd])
|
|
59
70
|
|
|
60
71
|
klass.stub(:new, instance) do
|
|
61
72
|
instance.stub(:node_modules_bin_exist?, use_node_modules) do
|
data/test/helper_test.rb
CHANGED
|
@@ -26,18 +26,18 @@ class HelperTest < ActionView::TestCase
|
|
|
26
26
|
|
|
27
27
|
def test_image_pack_path
|
|
28
28
|
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", image_pack_path("application.png")
|
|
29
|
-
assert_equal "/packs/
|
|
30
|
-
assert_equal "/packs/
|
|
31
|
-
assert_equal "/packs/
|
|
32
|
-
assert_equal "/packs/
|
|
29
|
+
assert_equal "/packs/static/image-c38deda30895059837cf.jpg", image_pack_path("image.jpg")
|
|
30
|
+
assert_equal "/packs/static/image-c38deda30895059837cf.jpg", image_pack_path("static/image.jpg")
|
|
31
|
+
assert_equal "/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_path("nested/image.jpg")
|
|
32
|
+
assert_equal "/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_path("static/nested/image.jpg")
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def test_image_pack_url
|
|
36
36
|
assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", image_pack_url("application.png")
|
|
37
|
-
assert_equal "https://example.com/packs/
|
|
38
|
-
assert_equal "https://example.com/packs/
|
|
39
|
-
assert_equal "https://example.com/packs/
|
|
40
|
-
assert_equal "https://example.com/packs/
|
|
37
|
+
assert_equal "https://example.com/packs/static/image-c38deda30895059837cf.jpg", image_pack_url("image.jpg")
|
|
38
|
+
assert_equal "https://example.com/packs/static/image-c38deda30895059837cf.jpg", image_pack_url("static/image.jpg")
|
|
39
|
+
assert_equal "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_url("nested/image.jpg")
|
|
40
|
+
assert_equal "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_url("static/nested/image.jpg")
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def test_image_pack_tag
|
|
@@ -45,20 +45,20 @@ class HelperTest < ActionView::TestCase
|
|
|
45
45
|
"<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />",
|
|
46
46
|
image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")
|
|
47
47
|
assert_equal \
|
|
48
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
|
48
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
49
49
|
image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")
|
|
50
50
|
assert_equal \
|
|
51
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
|
52
|
-
image_pack_tag("
|
|
51
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
52
|
+
image_pack_tag("static/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
53
53
|
assert_equal \
|
|
54
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
|
54
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
55
55
|
image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
56
56
|
assert_equal \
|
|
57
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
|
58
|
-
image_pack_tag("
|
|
57
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
58
|
+
image_pack_tag("static/nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
59
59
|
assert_equal \
|
|
60
|
-
"<img srcset=\"/packs/
|
|
61
|
-
image_pack_tag("
|
|
60
|
+
"<img srcset=\"/packs/static/image-2x-7cca48e6cae66ec07b8e.jpg 2x\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" />",
|
|
61
|
+
image_pack_tag("static/image.jpg", srcset: { "static/image-2x.jpg" => "2x" })
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def test_favicon_pack_tag
|
|
@@ -66,44 +66,17 @@ class HelperTest < ActionView::TestCase
|
|
|
66
66
|
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />",
|
|
67
67
|
favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
|
|
68
68
|
assert_equal \
|
|
69
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
|
69
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />",
|
|
70
70
|
favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
71
71
|
assert_equal \
|
|
72
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
|
73
|
-
favicon_pack_tag("
|
|
72
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />",
|
|
73
|
+
favicon_pack_tag("static/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
74
74
|
assert_equal \
|
|
75
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
|
75
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />",
|
|
76
76
|
favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
77
77
|
assert_equal \
|
|
78
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
|
79
|
-
favicon_pack_tag("
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_javascript_pack_tag
|
|
83
|
-
assert_equal \
|
|
84
|
-
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
|
85
|
-
javascript_pack_tag("bootstrap.js")
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def test_javascript_pack_tag_symbol
|
|
89
|
-
assert_equal \
|
|
90
|
-
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
|
91
|
-
javascript_pack_tag(:bootstrap)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def test_javascript_pack_tag_splat
|
|
95
|
-
assert_equal \
|
|
96
|
-
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>\n) +
|
|
97
|
-
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
|
98
|
-
javascript_pack_tag("bootstrap.js", "application.js", defer: true)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def test_javascript_pack_tag_split_chunks
|
|
102
|
-
assert_equal \
|
|
103
|
-
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
|
104
|
-
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
|
105
|
-
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
|
|
106
|
-
javascript_packs_with_chunks_tag("application")
|
|
78
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />",
|
|
79
|
+
favicon_pack_tag("static/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
107
80
|
end
|
|
108
81
|
|
|
109
82
|
def test_preload_pack_asset
|
|
@@ -122,30 +95,65 @@ class HelperTest < ActionView::TestCase
|
|
|
122
95
|
end
|
|
123
96
|
end
|
|
124
97
|
|
|
125
|
-
def
|
|
98
|
+
def test_javascript_pack_tag
|
|
99
|
+
assert_equal \
|
|
100
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
|
101
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
|
102
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>\n) +
|
|
103
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>),
|
|
104
|
+
javascript_pack_tag("application", "bootstrap")
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_javascript_pack_with_no_defer_tag
|
|
108
|
+
assert_equal \
|
|
109
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
|
110
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
|
111
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>\n) +
|
|
112
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
|
113
|
+
javascript_pack_tag("application", "bootstrap", defer: false)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_javascript_pack_tag_splat
|
|
126
117
|
assert_equal \
|
|
127
|
-
%(<
|
|
128
|
-
%(<
|
|
129
|
-
%(<
|
|
130
|
-
|
|
118
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
|
119
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
|
120
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
|
121
|
+
javascript_pack_tag("application", defer: true)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_javascript_pack_tag_symbol
|
|
125
|
+
assert_equal \
|
|
126
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
|
127
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
|
128
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
|
129
|
+
javascript_pack_tag(:application)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def application_stylesheet_chunks
|
|
133
|
+
%w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css]
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def hello_stimulus_stylesheet_chunks
|
|
137
|
+
%w[/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css]
|
|
131
138
|
end
|
|
132
139
|
|
|
133
140
|
def test_stylesheet_pack_tag
|
|
134
141
|
assert_equal \
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
|
143
|
+
.map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
|
|
144
|
+
stylesheet_pack_tag("application", "hello_stimulus")
|
|
137
145
|
end
|
|
138
146
|
|
|
139
147
|
def test_stylesheet_pack_tag_symbol
|
|
140
148
|
assert_equal \
|
|
141
|
-
|
|
142
|
-
|
|
149
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
|
150
|
+
.map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
|
|
151
|
+
stylesheet_pack_tag(:application, :hello_stimulus)
|
|
143
152
|
end
|
|
144
153
|
|
|
145
154
|
def test_stylesheet_pack_tag_splat
|
|
146
155
|
assert_equal \
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
stylesheet_pack_tag("bootstrap.css", "application.css", media: "all")
|
|
156
|
+
(application_stylesheet_chunks).map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n"),
|
|
157
|
+
stylesheet_pack_tag("application", media: "all")
|
|
150
158
|
end
|
|
151
159
|
end
|
data/test/manifest_test.rb
CHANGED
|
@@ -25,6 +25,22 @@ class ManifestTest < Minitest::Test
|
|
|
25
25
|
assert_equal Webpacker.manifest.lookup!("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def test_lookup_with_chunks_without_extension_success!
|
|
29
|
+
assert_equal ["/packs/bootstrap-300631c4f0e0f9c865bc.js"], Webpacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_lookup_with_chunks_with_extension_success!
|
|
33
|
+
assert_equal ["/packs/bootstrap-300631c4f0e0f9c865bc.js"], Webpacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_lookup_with_chunks_without_extension_subdir_success!
|
|
37
|
+
assert_equal ["/packs/print/application-983b6c164a47f7ed49cd.css"], Webpacker.manifest.lookup_pack_with_chunks!("print/application", type: :css)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_lookup_with_chunks_with_extension_subdir_success!
|
|
41
|
+
assert_equal ["/packs/print/application-983b6c164a47f7ed49cd.css"], Webpacker.manifest.lookup_pack_with_chunks!("print/application.css", type: :css)
|
|
42
|
+
end
|
|
43
|
+
|
|
28
44
|
def test_lookup_nil
|
|
29
45
|
assert_nil Webpacker.manifest.lookup("foo.js")
|
|
30
46
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
|
2
2
|
|
|
3
3
|
default: &default
|
|
4
|
-
source_path: app/
|
|
5
|
-
source_entry_path:
|
|
4
|
+
source_path: app/packs
|
|
5
|
+
source_entry_path: entrypoints
|
|
6
6
|
public_output_path: packs
|
|
7
|
-
cache_path: tmp/
|
|
7
|
+
cache_path: tmp/webpacker
|
|
8
8
|
|
|
9
|
-
# Additional paths webpack should
|
|
9
|
+
# Additional paths webpack should look up modules
|
|
10
10
|
# ['app/assets', 'engine/foo/app/assets']
|
|
11
11
|
additional_paths:
|
|
12
12
|
- app/assets
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint no-console:0 */
|
|
2
2
|
// This file is automatically compiled by Webpack, along with any other files
|
|
3
3
|
// present in this directory. You're encouraged to place your actual application logic in
|
|
4
|
-
// a relevant structure within app/
|
|
4
|
+
// a relevant structure within app/packs and only use these pack files to reference
|
|
5
5
|
// that code so it'll be compiled.
|
|
6
6
|
//
|
|
7
7
|
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$test_app_autoload_paths_in_initializer = ActiveSupport::Dependencies.autoload_paths
|