webpacker 6.0.0.pre.2 → 6.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/jest.yml +5 -2
- data/.github/workflows/js-lint.yml +5 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +17 -14
- data/.node-version +1 -1
- data/.rubocop.yml +106 -0
- data/CHANGELOG.md +36 -9
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +93 -90
- data/README.md +363 -107
- 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 +57 -25
- data/docs/v6_upgrade.md +75 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/config/webpacker.yml +5 -7
- data/lib/install/{javascript/packs → packs/entrypoints}/application.js +4 -3
- data/lib/install/template.rb +17 -10
- 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/webpacker.rb +1 -1
- data/lib/webpacker/commands.rb +2 -1
- 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 +1 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +1 -0
- data/package.json +25 -29
- data/package/__tests__/development.js +3 -2
- data/package/__tests__/env.js +8 -4
- data/package/__tests__/index.js +9 -0
- data/package/babel/preset.js +24 -14
- data/package/env.js +7 -1
- data/package/environments/__tests__/base.js +7 -7
- data/package/environments/base.js +25 -25
- data/package/environments/development.js +7 -8
- 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/test/configuration_test.rb +3 -3
- data/test/dev_server_runner_test.rb +13 -2
- data/test/helper_test.rb +59 -60
- 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/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/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 +17 -0
- data/yarn.lock +1567 -1039
- metadata +24 -36
- 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/package/index.js
CHANGED
@@ -1,13 +1,16 @@
|
|
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
7
|
const baseConfig = require('./environments/base')
|
7
|
-
const
|
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
15
|
const webpackConfig = () => {
|
13
16
|
const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
|
@@ -20,5 +23,9 @@ module.exports = {
|
|
20
23
|
devServer,
|
21
24
|
webpackConfig: webpackConfig(),
|
22
25
|
baseConfig,
|
23
|
-
|
26
|
+
rules,
|
27
|
+
moduleExists,
|
28
|
+
canProcess,
|
29
|
+
inliningCss,
|
30
|
+
...webpackMerge
|
24
31
|
}
|
data/package/rules/babel.js
CHANGED
@@ -8,7 +8,7 @@ const {
|
|
8
8
|
const { isProduction } = require('../env')
|
9
9
|
|
10
10
|
module.exports = {
|
11
|
-
test: /\.(js|jsx|mjs|ts|tsx)?(\.erb)?$/,
|
11
|
+
test: /\.(js|jsx|mjs|ts|tsx|coffee)?(\.erb)?$/,
|
12
12
|
include: [sourcePath, ...additionalPaths].map((p) => {
|
13
13
|
try {
|
14
14
|
return realpathSync(p)
|
data/package/rules/coffee.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
const { canProcess } = require('../utils/helpers')
|
2
|
+
|
3
|
+
module.exports = canProcess('coffee-loader', (resolvedPath) => ({
|
2
4
|
test: /\.coffee(\.erb)?$/,
|
3
|
-
use: [
|
4
|
-
|
5
|
-
]
|
6
|
-
}
|
5
|
+
use: [{ loader: resolvedPath }]
|
6
|
+
}))
|
data/package/rules/erb.js
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
const { canProcess } = require('../utils/helpers')
|
2
|
+
|
1
3
|
const runner = /^win/.test(process.platform) ? 'ruby ' : ''
|
2
4
|
|
3
|
-
module.exports = {
|
5
|
+
module.exports = canProcess('rails-erb-loader', (resolvedPath) => ({
|
4
6
|
test: /\.erb$/,
|
5
7
|
enforce: 'pre',
|
6
8
|
exclude: /node_modules/,
|
7
9
|
use: [
|
8
10
|
{
|
9
|
-
loader:
|
11
|
+
loader: resolvedPath,
|
10
12
|
options: { runner: `${runner}bin/rails runner` }
|
11
13
|
}
|
12
14
|
]
|
13
|
-
}
|
15
|
+
}))
|
data/package/rules/file.js
CHANGED
@@ -13,9 +13,11 @@ module.exports = {
|
|
13
13
|
/\.ttf$/,
|
14
14
|
/\.woff$/,
|
15
15
|
/\.woff2$/,
|
16
|
-
/\.
|
17
|
-
/\.json$/
|
16
|
+
/\.svg$/
|
18
17
|
],
|
19
18
|
exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
|
20
|
-
type: 'asset/resource'
|
19
|
+
type: 'asset/resource',
|
20
|
+
generator: {
|
21
|
+
filename: 'static/[hash][ext][query]'
|
22
|
+
}
|
21
23
|
}
|
data/package/rules/index.js
CHANGED
@@ -1,24 +1,16 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const load = (name) => {
|
5
|
-
try {
|
6
|
-
return require(`./${name}`)
|
7
|
-
} catch (e) {
|
8
|
-
return null
|
9
|
-
}
|
10
|
-
}
|
11
|
-
|
12
4
|
const rules = {
|
13
|
-
|
14
|
-
|
15
|
-
css:
|
16
|
-
sass:
|
17
|
-
babel:
|
18
|
-
erb:
|
19
|
-
coffee:
|
20
|
-
|
21
|
-
|
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')
|
22
14
|
}
|
23
15
|
|
24
16
|
module.exports = Object.keys(rules)
|
data/package/rules/less.js
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
const path = require('path')
|
2
|
+
const { canProcess } = require('../utils/helpers')
|
2
3
|
const getStyleRule = require('../utils/get_style_rule')
|
4
|
+
|
3
5
|
const {
|
4
6
|
additional_paths: paths,
|
5
7
|
source_path: sourcePath
|
6
8
|
} = require('../config')
|
7
9
|
|
8
|
-
module.exports =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
+
}
|
16
20
|
}
|
17
|
-
|
18
|
-
|
21
|
+
])
|
22
|
+
)
|
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/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_DEV_SERVER"] = "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,86 +66,85 @@ 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("
|
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")
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
def test_preload_pack_asset
|
83
|
+
if self.class.method_defined?(:preload_link_tag)
|
84
|
+
assert_equal \
|
85
|
+
%(<link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">),
|
86
|
+
preload_pack_asset("fonts/fa-regular-400.woff2")
|
87
|
+
else
|
88
|
+
error = assert_raises do
|
89
|
+
preload_pack_asset("fonts/fa-regular-400.woff2")
|
90
|
+
end
|
91
|
+
|
92
|
+
assert_equal \
|
93
|
+
"You need Rails >= 5.2 to use this tag.",
|
94
|
+
error.message
|
95
|
+
end
|
86
96
|
end
|
87
97
|
|
88
|
-
def
|
98
|
+
def test_javascript_pack_tag
|
89
99
|
assert_equal \
|
90
|
-
%(<script src="/packs/bootstrap-
|
91
|
-
|
100
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
101
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
102
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>\n) +
|
103
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
104
|
+
javascript_pack_tag("application", "bootstrap")
|
92
105
|
end
|
93
106
|
|
94
107
|
def test_javascript_pack_tag_splat
|
95
108
|
assert_equal \
|
96
|
-
%(<script src="/packs/bootstrap-
|
109
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
110
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
97
111
|
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
98
|
-
javascript_pack_tag("
|
112
|
+
javascript_pack_tag("application", defer: true)
|
99
113
|
end
|
100
114
|
|
101
|
-
def
|
115
|
+
def test_javascript_pack_tag_symbol
|
102
116
|
assert_equal \
|
103
117
|
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
104
118
|
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
105
119
|
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
|
106
|
-
|
120
|
+
javascript_pack_tag(:application)
|
107
121
|
end
|
108
122
|
|
109
|
-
def
|
110
|
-
|
111
|
-
assert_equal \
|
112
|
-
%(<link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">),
|
113
|
-
preload_pack_asset("fonts/fa-regular-400.woff2")
|
114
|
-
else
|
115
|
-
error = assert_raises do
|
116
|
-
preload_pack_asset("fonts/fa-regular-400.woff2")
|
117
|
-
end
|
118
|
-
|
119
|
-
assert_equal \
|
120
|
-
"You need Rails >= 5.2 to use this tag.",
|
121
|
-
error.message
|
122
|
-
end
|
123
|
+
def application_stylesheet_chunks
|
124
|
+
%w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css]
|
123
125
|
end
|
124
126
|
|
125
|
-
def
|
126
|
-
|
127
|
-
%(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
|
128
|
-
%(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
|
129
|
-
%(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
|
130
|
-
stylesheet_packs_with_chunks_tag("application", "hello_stimulus")
|
127
|
+
def hello_stimulus_stylesheet_chunks
|
128
|
+
%w[/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css]
|
131
129
|
end
|
132
130
|
|
133
131
|
def test_stylesheet_pack_tag
|
134
132
|
assert_equal \
|
135
|
-
|
136
|
-
|
133
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
134
|
+
.map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
|
135
|
+
stylesheet_pack_tag("application", "hello_stimulus")
|
137
136
|
end
|
138
137
|
|
139
138
|
def test_stylesheet_pack_tag_symbol
|
140
139
|
assert_equal \
|
141
|
-
|
142
|
-
|
140
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
141
|
+
.map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
|
142
|
+
stylesheet_pack_tag(:application, :hello_stimulus)
|
143
143
|
end
|
144
144
|
|
145
145
|
def test_stylesheet_pack_tag_splat
|
146
146
|
assert_equal \
|
147
|
-
|
148
|
-
|
149
|
-
stylesheet_pack_tag("bootstrap.css", "application.css", media: "all")
|
147
|
+
(application_stylesheet_chunks).map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n"),
|
148
|
+
stylesheet_pack_tag("application", media: "all")
|
150
149
|
end
|
151
150
|
end
|