webpacker 3.6.0 → 4.0.2
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/.node-version +1 -0
- data/.travis.yml +12 -4
- data/CHANGELOG.md +240 -28
- data/CONTRIBUTING.md +33 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +78 -71
- data/MIT-LICENSE +1 -1
- data/README.md +75 -16
- data/docs/assets.md +7 -4
- data/docs/css.md +47 -14
- data/docs/deployment.md +11 -0
- data/docs/engines.md +155 -0
- data/docs/es6.md +5 -5
- data/docs/testing.md +1 -1
- data/docs/troubleshooting.md +4 -4
- data/docs/v4-upgrade.md +132 -0
- data/docs/webpack.md +56 -3
- data/docs/yarn.md +12 -1
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.4.2.x +2 -2
- data/gemfiles/Gemfile-rails.5.0.x +2 -2
- data/gemfiles/Gemfile-rails.5.1.x +2 -2
- data/gemfiles/Gemfile-rails.5.2.x +10 -0
- data/lib/install/bin/webpack +5 -1
- data/lib/install/bin/webpack-dev-server +5 -1
- data/lib/install/coffee.rb +2 -2
- data/lib/install/config/.browserslistrc +1 -0
- data/lib/install/config/babel.config.js +70 -0
- data/lib/install/config/postcss.config.js +12 -0
- data/lib/install/config/webpacker.yml +26 -0
- data/lib/install/elm.rb +2 -2
- data/lib/install/erb.rb +2 -2
- data/lib/install/examples/react/babel.config.js +83 -0
- data/lib/install/examples/stimulus/application.js +1 -6
- data/lib/install/examples/stimulus/controllers/index.js +9 -0
- data/lib/install/examples/typescript/tsconfig.json +4 -0
- data/lib/install/examples/vue/hello_vue.js +6 -4
- data/lib/install/javascript/packs/application.js +8 -0
- data/lib/install/loaders/typescript.js +8 -3
- data/lib/install/loaders/vue.js +1 -8
- data/lib/install/react.rb +6 -19
- data/lib/install/template.rb +29 -30
- data/lib/install/typescript.rb +4 -4
- data/lib/install/vue.rb +14 -5
- data/lib/tasks/installers.rake +4 -2
- data/lib/tasks/webpacker/binstubs.rake +3 -2
- data/lib/tasks/webpacker/compile.rake +10 -5
- data/lib/tasks/webpacker/install.rake +3 -2
- data/lib/tasks/webpacker/verify_install.rake +1 -4
- data/lib/tasks/webpacker/yarn_install.rake +1 -1
- data/lib/webpacker/commands.rb +0 -1
- data/lib/webpacker/compiler.rb +17 -13
- data/lib/webpacker/configuration.rb +13 -5
- data/lib/webpacker/dev_server.rb +7 -10
- data/lib/webpacker/dev_server_proxy.rb +13 -6
- data/lib/webpacker/dev_server_runner.rb +13 -6
- data/lib/webpacker/helper.rb +78 -20
- data/lib/webpacker/manifest.rb +64 -21
- data/lib/webpacker/railtie.rb +16 -7
- data/lib/webpacker/runner.rb +3 -3
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +14 -3
- data/package.json +46 -34
- data/package/__tests__/config.js +37 -3
- data/package/__tests__/dev_server.js +15 -0
- data/package/__tests__/production.js +2 -2
- data/package/__tests__/staging.js +3 -3
- data/package/__tests__/test.js +2 -1
- data/package/config.js +21 -9
- data/package/config_types/config_list.js +5 -6
- data/package/dev_server.js +3 -1
- data/package/environments/__tests__/base.js +7 -5
- data/package/environments/base.js +84 -31
- data/package/environments/development.js +6 -2
- data/package/environments/production.js +46 -36
- data/package/rules/babel.js +10 -4
- data/package/rules/file.js +8 -3
- data/package/rules/index.js +7 -2
- data/package/rules/node_modules.js +23 -0
- data/package/utils/__tests__/get_style_rule.js +20 -0
- data/package/utils/deep_merge.js +5 -6
- data/package/utils/get_style_rule.js +29 -42
- data/package/utils/helpers.js +18 -6
- data/package/utils/objectify.js +1 -2
- data/test/compiler_test.rb +15 -3
- data/test/configuration_test.rb +9 -0
- data/test/dev_server_runner_test.rb +51 -0
- data/test/helper_test.rb +48 -5
- data/test/manifest_test.rb +14 -0
- data/test/rake_tasks_test.rb +34 -0
- data/test/test_app/config.ru +5 -0
- data/test/test_app/config/application.rb +1 -0
- data/test/test_app/config/webpack/development.js +0 -0
- data/test/test_app/config/webpacker.yml +20 -0
- data/test/test_app/config/webpacker_public_root.yml +19 -0
- data/test/test_app/package.json +13 -0
- data/test/test_app/public/packs/manifest.json +22 -1
- data/test/test_app/yarn.lock +11 -0
- data/test/test_helper.rb +1 -3
- data/test/webpack_runner_test.rb +51 -0
- data/yarn.lock +4077 -2816
- metadata +28 -6
- data/lib/install/config/.babelrc +0 -18
- data/lib/install/config/.postcssrc.yml +0 -3
- data/lib/install/examples/react/.babelrc +0 -6
data/package/rules/index.js
CHANGED
|
@@ -4,12 +4,17 @@ const css = require('./css')
|
|
|
4
4
|
const sass = require('./sass')
|
|
5
5
|
const moduleCss = require('./module.css')
|
|
6
6
|
const moduleSass = require('./module.sass')
|
|
7
|
+
const nodeModules = require('./node_modules')
|
|
7
8
|
|
|
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
|
|
8
12
|
module.exports = {
|
|
9
|
-
|
|
13
|
+
file,
|
|
10
14
|
css,
|
|
11
15
|
sass,
|
|
12
16
|
moduleCss,
|
|
13
17
|
moduleSass,
|
|
14
|
-
|
|
18
|
+
nodeModules,
|
|
19
|
+
babel
|
|
15
20
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
module.exports = {
|
|
7
|
+
test: /\.(js|mjs)$/,
|
|
8
|
+
include: /node_modules/,
|
|
9
|
+
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
|
10
|
+
use: [
|
|
11
|
+
{
|
|
12
|
+
loader: 'babel-loader',
|
|
13
|
+
options: {
|
|
14
|
+
babelrc: false,
|
|
15
|
+
presets: [['@babel/preset-env', { modules: false }]],
|
|
16
|
+
cacheDirectory: join(cachePath, 'babel-loader-node-modules'),
|
|
17
|
+
cacheCompression: nodeEnv === 'production',
|
|
18
|
+
compact: false,
|
|
19
|
+
sourceMaps: false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -33,4 +33,24 @@ describe('getStyleRule', () => {
|
|
|
33
33
|
|
|
34
34
|
expect(cssRule.use).toMatchObject(expect.arrayContaining(expectation))
|
|
35
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(`doesn't add mini-css-extract-plugin when extract_css is false`, () => {
|
|
48
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
49
|
+
const expectation = [MiniCssExtractPlugin.loader]
|
|
50
|
+
|
|
51
|
+
require('../../config').extract_css = false
|
|
52
|
+
const cssRule = getStyleRule(/\.(css)$/i)
|
|
53
|
+
|
|
54
|
+
expect(cssRule.use).toMatchObject(expect.not.arrayContaining(expectation))
|
|
55
|
+
})
|
|
36
56
|
})
|
data/package/utils/deep_merge.js
CHANGED
|
@@ -10,12 +10,11 @@ const deepMerge = (target, source) => {
|
|
|
10
10
|
if (!(isObject(target) && isObject(source))) return source
|
|
11
11
|
|
|
12
12
|
return [...Object.keys(target), ...Object.keys(source)].reduce(
|
|
13
|
-
(result, key) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)),
|
|
13
|
+
(result, key) => (Object.assign(
|
|
14
|
+
{},
|
|
15
|
+
result,
|
|
16
|
+
{ [key]: deepMerge(target[key], source[key]) }
|
|
17
|
+
)),
|
|
19
18
|
{}
|
|
20
19
|
)
|
|
21
20
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
2
|
+
const { resolve } = require('path')
|
|
3
3
|
const devServer = require('../dev_server')
|
|
4
|
-
const
|
|
4
|
+
const config = require('../config')
|
|
5
5
|
|
|
6
|
-
const postcssConfigPath = path.resolve(process.cwd(), '.postcssrc.yml')
|
|
7
|
-
const isProduction = nodeEnv === 'production'
|
|
8
6
|
const inDevServer = process.argv.find(v => v.includes('webpack-dev-server'))
|
|
9
7
|
const isHMR = inDevServer && (devServer && devServer.hmr)
|
|
10
|
-
const extractCSS = !isHMR || isProduction
|
|
11
8
|
|
|
12
9
|
const styleLoader = {
|
|
13
10
|
loader: 'style-loader',
|
|
@@ -18,46 +15,36 @@ const styleLoader = {
|
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
const getStyleRule = (test, modules = false, preprocessors = []) => {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
...preprocessors
|
|
41
|
-
]
|
|
42
|
-
}
|
|
18
|
+
const use = [
|
|
19
|
+
{
|
|
20
|
+
loader: 'css-loader',
|
|
21
|
+
options: {
|
|
22
|
+
sourceMap: true,
|
|
23
|
+
importLoaders: 2,
|
|
24
|
+
localIdentName: '[name]__[local]___[hash:base64:5]',
|
|
25
|
+
modules
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
loader: 'postcss-loader',
|
|
30
|
+
options: {
|
|
31
|
+
config: { path: resolve() },
|
|
32
|
+
sourceMap: true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
...preprocessors
|
|
36
|
+
]
|
|
43
37
|
|
|
44
38
|
const options = modules ? { include: /\.module\.[a-z]+$/ } : { exclude: /\.module\.[a-z]+$/ }
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
// For hot-reloading use regular loaders
|
|
54
|
-
const inlineCSSLoader = Object.assign(
|
|
55
|
-
{},
|
|
56
|
-
{ test, use: [styleLoader].concat(extractOptions.use) },
|
|
57
|
-
options
|
|
58
|
-
)
|
|
40
|
+
if (config.extract_css) {
|
|
41
|
+
use.unshift(MiniCssExtractPlugin.loader)
|
|
42
|
+
} else {
|
|
43
|
+
use.unshift(styleLoader)
|
|
44
|
+
}
|
|
59
45
|
|
|
60
|
-
|
|
46
|
+
// sideEffects - See https://github.com/webpack/webpack/issues/6571
|
|
47
|
+
return Object.assign({}, { test, use, sideEffects: !modules }, options)
|
|
61
48
|
}
|
|
62
49
|
|
|
63
50
|
module.exports = getStyleRule
|
data/package/utils/helpers.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const { stringify } = require('flatted/cjs')
|
|
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)
|
|
5
8
|
|
|
6
9
|
const isBoolean = str => /^true/.test(str) || /^false/.test(str)
|
|
7
10
|
|
|
@@ -16,7 +19,7 @@ const isStrPath = (key) => {
|
|
|
16
19
|
|
|
17
20
|
const isArray = value => Array.isArray(value)
|
|
18
21
|
|
|
19
|
-
const isEqual = (target, source) =>
|
|
22
|
+
const isEqual = (target, source) => stringify(target) === stringify(source)
|
|
20
23
|
|
|
21
24
|
const canMerge = value => isObject(value) || isArray(value)
|
|
22
25
|
|
|
@@ -32,15 +35,24 @@ const chdirTestApp = () => {
|
|
|
32
35
|
|
|
33
36
|
const chdirCwd = () => process.chdir(process.cwd())
|
|
34
37
|
|
|
38
|
+
const resetEnv = () => {
|
|
39
|
+
process.env = {}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ensureTrailingSlash = path => (path.endsWith('/') ? path : `${path}/`)
|
|
43
|
+
|
|
35
44
|
module.exports = {
|
|
36
45
|
chdirTestApp,
|
|
37
46
|
chdirCwd,
|
|
47
|
+
ensureTrailingSlash,
|
|
38
48
|
isObject,
|
|
49
|
+
isNotObject,
|
|
39
50
|
isBoolean,
|
|
40
51
|
isArray,
|
|
41
52
|
isEqual,
|
|
42
53
|
isEmpty,
|
|
43
54
|
isStrPath,
|
|
44
55
|
canMerge,
|
|
45
|
-
prettyPrint
|
|
56
|
+
prettyPrint,
|
|
57
|
+
resetEnv
|
|
46
58
|
}
|
data/package/utils/objectify.js
CHANGED
data/test/compiler_test.rb
CHANGED
|
@@ -16,16 +16,18 @@ class CompilerTest < Minitest::Test
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def test_custom_environment_variables
|
|
19
|
-
|
|
19
|
+
assert_nil Webpacker.compiler.send(:webpack_env)["FOO"]
|
|
20
20
|
Webpacker.compiler.env["FOO"] = "BAR"
|
|
21
21
|
assert Webpacker.compiler.send(:webpack_env)["FOO"] == "BAR"
|
|
22
|
+
ensure
|
|
23
|
+
Webpacker.compiler.env = {}
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
def test_default_watched_paths
|
|
25
27
|
assert_equal Webpacker.compiler.send(:default_watched_paths), [
|
|
26
28
|
"app/assets/**/*",
|
|
27
29
|
"/etc/yarn/**/*",
|
|
28
|
-
"
|
|
30
|
+
"app/javascript/**/*",
|
|
29
31
|
"yarn.lock",
|
|
30
32
|
"package.json",
|
|
31
33
|
"config/webpack/**/*"
|
|
@@ -59,6 +61,16 @@ class CompilerTest < Minitest::Test
|
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
def test_compilation_digest_path
|
|
62
|
-
|
|
64
|
+
assert_equal Webpacker.compiler.send(:compilation_digest_path).basename.to_s, "last-compilation-digest-#{Webpacker.env}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_external_env_variables
|
|
68
|
+
assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"]
|
|
69
|
+
assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"]
|
|
70
|
+
|
|
71
|
+
ENV["WEBPACKER_ASSET_HOST"] = "foo.bar"
|
|
72
|
+
ENV["WEBPACKER_RELATIVE_URL_ROOT"] = "/baz"
|
|
73
|
+
assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"], "foo.bar"
|
|
74
|
+
assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"], "/baz"
|
|
63
75
|
end
|
|
64
76
|
end
|
data/test/configuration_test.rb
CHANGED
|
@@ -22,6 +22,15 @@ class ConfigurationTest < Webpacker::Test
|
|
|
22
22
|
def test_public_output_path
|
|
23
23
|
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
|
|
24
24
|
assert_equal @config.public_output_path.to_s, public_output_path
|
|
25
|
+
|
|
26
|
+
@config = Webpacker::Configuration.new(
|
|
27
|
+
root_path: @config.root_path,
|
|
28
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_public_root.yml", __dir__)),
|
|
29
|
+
env: "production"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
|
|
33
|
+
assert_equal @config.public_output_path.to_s, public_output_path
|
|
25
34
|
end
|
|
26
35
|
|
|
27
36
|
def test_public_manifest_path
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "webpacker/dev_server_runner"
|
|
3
|
+
|
|
4
|
+
class DevServerRunnerTest < Webpacker::Test
|
|
5
|
+
def setup
|
|
6
|
+
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
|
7
|
+
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def teardown
|
|
11
|
+
ENV["NODE_ENV"] = @original_node_env
|
|
12
|
+
ENV["RAILS_ENV"] = @original_rails_env
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_run_cmd_via_node_modules
|
|
16
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
|
|
17
|
+
|
|
18
|
+
verify_command(cmd, use_node_modules: true)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_run_cmd_via_yarn
|
|
22
|
+
cmd = ["yarn", "webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
|
|
23
|
+
|
|
24
|
+
verify_command(cmd, use_node_modules: false)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
def test_app_path
|
|
29
|
+
File.expand_path("test_app", __dir__)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def verify_command(cmd, use_node_modules: true)
|
|
33
|
+
cwd = Dir.pwd
|
|
34
|
+
Dir.chdir(test_app_path)
|
|
35
|
+
|
|
36
|
+
klass = Webpacker::DevServerRunner
|
|
37
|
+
instance = klass.new([])
|
|
38
|
+
mock = Minitest::Mock.new
|
|
39
|
+
mock.expect(:call, nil, [{}, *cmd])
|
|
40
|
+
|
|
41
|
+
klass.stub(:new, instance) do
|
|
42
|
+
instance.stub(:node_modules_bin_exist?, use_node_modules) do
|
|
43
|
+
Kernel.stub(:exec, mock) { klass.run([]) }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
mock.verify
|
|
48
|
+
ensure
|
|
49
|
+
Dir.chdir(cwd)
|
|
50
|
+
end
|
|
51
|
+
end
|
data/test/helper_test.rb
CHANGED
|
@@ -18,23 +18,38 @@ class HelperTest < ActionView::TestCase
|
|
|
18
18
|
assert_equal "/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_path("bootstrap.js")
|
|
19
19
|
assert_equal "/packs/bootstrap-c38deda30895059837cf.css", asset_pack_path("bootstrap.css")
|
|
20
20
|
|
|
21
|
-
Webpacker.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", asset_pack_path("application.png")
|
|
25
|
-
end
|
|
21
|
+
Webpacker.config.stub :extract_css?, false do
|
|
22
|
+
assert_nil asset_pack_path("bootstrap.css")
|
|
23
|
+
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", asset_pack_path("application.png")
|
|
26
24
|
end
|
|
27
25
|
end
|
|
28
26
|
|
|
29
27
|
def test_asset_pack_url
|
|
30
28
|
assert_equal "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_url("bootstrap.js")
|
|
31
29
|
assert_equal "https://example.com/packs/bootstrap-c38deda30895059837cf.css", asset_pack_url("bootstrap.css")
|
|
30
|
+
|
|
31
|
+
Webpacker.config.stub :extract_css?, false do
|
|
32
|
+
assert_nil asset_pack_path("bootstrap.css")
|
|
33
|
+
assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", asset_pack_url("application.png")
|
|
34
|
+
end
|
|
32
35
|
end
|
|
33
36
|
|
|
34
37
|
def test_image_pack_tag
|
|
35
38
|
assert_equal \
|
|
36
39
|
"<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />",
|
|
37
40
|
image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")
|
|
41
|
+
assert_equal \
|
|
42
|
+
"<img alt=\"Edit Entry\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
43
|
+
image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")
|
|
44
|
+
assert_equal \
|
|
45
|
+
"<img alt=\"Edit Entry\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
46
|
+
image_pack_tag("media/images/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
47
|
+
assert_equal \
|
|
48
|
+
"<img alt=\"Edit Entry\" src=\"/packs/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
49
|
+
image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
50
|
+
assert_equal \
|
|
51
|
+
"<img alt=\"Edit Entry\" src=\"/packs/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
52
|
+
image_pack_tag("media/images/nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
38
53
|
end
|
|
39
54
|
|
|
40
55
|
def test_javascript_pack_tag
|
|
@@ -43,6 +58,12 @@ class HelperTest < ActionView::TestCase
|
|
|
43
58
|
javascript_pack_tag("bootstrap.js")
|
|
44
59
|
end
|
|
45
60
|
|
|
61
|
+
def test_javascript_pack_tag_symbol
|
|
62
|
+
assert_equal \
|
|
63
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
|
64
|
+
javascript_pack_tag(:bootstrap)
|
|
65
|
+
end
|
|
66
|
+
|
|
46
67
|
def test_javascript_pack_tag_splat
|
|
47
68
|
assert_equal \
|
|
48
69
|
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>\n) +
|
|
@@ -50,12 +71,34 @@ class HelperTest < ActionView::TestCase
|
|
|
50
71
|
javascript_pack_tag("bootstrap.js", "application.js", defer: true)
|
|
51
72
|
end
|
|
52
73
|
|
|
74
|
+
def test_javascript_pack_tag_split_chunks
|
|
75
|
+
assert_equal \
|
|
76
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
|
77
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
|
78
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
|
|
79
|
+
javascript_packs_with_chunks_tag("application")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_stylesheet_pack_tag_split_chunks
|
|
83
|
+
assert_equal \
|
|
84
|
+
%(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
|
|
85
|
+
%(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
|
|
86
|
+
%(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
|
|
87
|
+
stylesheet_packs_with_chunks_tag("application", "hello_stimulus")
|
|
88
|
+
end
|
|
89
|
+
|
|
53
90
|
def test_stylesheet_pack_tag
|
|
54
91
|
assert_equal \
|
|
55
92
|
%(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
|
|
56
93
|
stylesheet_pack_tag("bootstrap.css")
|
|
57
94
|
end
|
|
58
95
|
|
|
96
|
+
def test_stylesheet_pack_tag_symbol
|
|
97
|
+
assert_equal \
|
|
98
|
+
%(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
|
|
99
|
+
stylesheet_pack_tag(:bootstrap)
|
|
100
|
+
end
|
|
101
|
+
|
|
59
102
|
def test_stylesheet_pack_tag_splat
|
|
60
103
|
assert_equal \
|
|
61
104
|
%(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
|
data/test/manifest_test.rb
CHANGED
|
@@ -22,7 +22,21 @@ class ManifestTest < Minitest::Test
|
|
|
22
22
|
assert_nil Webpacker.manifest.lookup("foo.js")
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
def test_lookup_chunks_nil
|
|
26
|
+
assert_nil Webpacker.manifest.lookup_pack_with_chunks("foo.js")
|
|
27
|
+
end
|
|
28
|
+
|
|
25
29
|
def test_lookup_success
|
|
26
30
|
assert_equal Webpacker.manifest.lookup("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
|
27
31
|
end
|
|
32
|
+
|
|
33
|
+
def test_lookup_entrypoint
|
|
34
|
+
application_entrypoints = [
|
|
35
|
+
"/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
|
|
36
|
+
"/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
|
|
37
|
+
"/packs/application-k344a6d59eef8632c9d1.js"
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
assert_equal Webpacker.manifest.lookup_pack_with_chunks!("application", type: :javascript), application_entrypoints
|
|
41
|
+
end
|
|
28
42
|
end
|