webpacker 5.4.0 → 6.0.0.rc.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -1
- 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 -36
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +5 -4
- data/CHANGELOG.md +45 -9
- data/CONTRIBUTING.md +20 -1
- data/Gemfile.lock +83 -83
- data/README.md +394 -180
- data/config/README.md +3 -0
- data/config/webpacker.yml +1 -0
- data/docs/deployment.md +9 -11
- 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/webpack/base.js +3 -0
- data/lib/install/config/webpack/development.js +2 -2
- data/lib/install/config/webpack/production.js +2 -2
- data/lib/install/config/webpack/test.js +2 -2
- data/lib/install/config/webpacker.yml +21 -49
- data/lib/install/package.json +15 -0
- data/lib/install/template.rb +63 -28
- data/lib/tasks/webpacker/binstubs.rake +6 -4
- data/lib/tasks/webpacker/check_binstubs.rake +4 -4
- 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/compile.rake +4 -2
- data/lib/tasks/webpacker/info.rake +12 -10
- data/lib/tasks/webpacker/install.rake +6 -4
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -10
- data/lib/tasks/webpacker/yarn_install.rake +9 -7
- data/lib/tasks/webpacker.rake +2 -11
- data/lib/tasks/yarn.rake +38 -0
- data/lib/webpacker/commands.rb +21 -16
- data/lib/webpacker/compiler.rb +16 -9
- data/lib/webpacker/configuration.rb +8 -32
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +28 -4
- data/lib/webpacker/helper.rb +47 -81
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +2 -3
- 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 +29 -3
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/config.js +5 -37
- data/package/__tests__/development.js +13 -21
- data/package/__tests__/env.js +16 -4
- data/package/__tests__/index.js +9 -0
- data/package/__tests__/production.js +6 -6
- data/package/__tests__/staging.js +7 -6
- data/package/__tests__/test.js +4 -5
- data/package/babel/preset.js +54 -0
- data/package/config.js +6 -14
- data/package/env.js +13 -4
- data/package/environments/__tests__/base.js +20 -52
- data/package/environments/base.js +68 -128
- data/package/environments/development.js +49 -47
- data/package/environments/production.js +66 -64
- data/package/environments/test.js +2 -2
- data/package/index.js +15 -8
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +10 -8
- data/package/rules/coffee.js +6 -0
- data/package/rules/erb.js +15 -0
- data/package/rules/file.js +21 -19
- data/package/rules/index.js +16 -18
- data/package/rules/less.js +22 -0
- data/package/rules/raw.js +5 -0
- data/package/rules/sass.js +9 -10
- data/package/rules/stylus.js +26 -0
- data/package/utils/get_style_rule.js +28 -36
- data/package/utils/helpers.js +28 -35
- data/package.json +23 -43
- data/test/command_test.rb +76 -0
- data/test/compiler_test.rb +0 -12
- data/test/configuration_test.rb +4 -35
- data/test/dev_server_runner_test.rb +36 -6
- data/test/engine_rake_tasks_test.rb +39 -0
- data/test/helper_test.rb +76 -62
- data/test/manifest_test.rb +16 -0
- data/test/mounted_app/Rakefile +4 -0
- data/test/mounted_app/test/dummy/Rakefile +3 -0
- data/test/mounted_app/test/dummy/bin/rails +3 -0
- data/test/mounted_app/test/dummy/bin/rake +3 -0
- data/test/mounted_app/test/dummy/config/application.rb +10 -0
- data/test/mounted_app/test/dummy/config/environment.rb +3 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
- data/test/mounted_app/test/dummy/config.ru +5 -0
- data/test/mounted_app/test/dummy/package.json +7 -0
- data/test/rake_tasks_test.rb +1 -10
- 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 +5 -31
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/config/webpacker_public_root.yml +0 -1
- data/test/test_app/public/packs/manifest.json +36 -18
- data/test/test_app/some.config.js +0 -0
- data/test/webpack_runner_test.rb +9 -3
- data/test/webpacker_test.rb +21 -0
- data/webpacker.gemspec +2 -2
- data/yarn.lock +2183 -6524
- metadata +63 -93
- data/.travis.yml +0 -43
- data/docs/assets.md +0 -119
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -308
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -63
- 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 -223
- data/docs/target.md +0 -22
- data/docs/testing.md +0 -136
- data/docs/typescript.md +0 -190
- data/docs/v4-upgrade.md +0 -142
- data/docs/webpack-dev-server.md +0 -92
- data/docs/webpack.md +0 -364
- data/docs/yarn.md +0 -23
- data/lib/install/angular.rb +0 -23
- data/lib/install/coffee.rb +0 -25
- data/lib/install/config/.browserslistrc +0 -1
- data/lib/install/config/babel.config.js +0 -70
- data/lib/install/config/postcss.config.js +0 -12
- data/lib/install/config/webpack/environment.js +0 -3
- data/lib/install/elm.rb +0 -39
- data/lib/install/erb.rb +0 -25
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
- data/lib/install/examples/angular/hello_angular/index.ts +0 -8
- data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
- data/lib/install/examples/angular/hello_angular.js +0 -7
- data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
- data/lib/install/examples/elm/Main.elm +0 -55
- data/lib/install/examples/elm/hello_elm.js +0 -16
- data/lib/install/examples/erb/hello_erb.js.erb +0 -6
- data/lib/install/examples/react/babel.config.js +0 -87
- data/lib/install/examples/react/hello_react.jsx +0 -26
- data/lib/install/examples/react/tsconfig.json +0 -21
- data/lib/install/examples/stimulus/application.js +0 -1
- data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
- data/lib/install/examples/stimulus/controllers/index.js +0 -9
- data/lib/install/examples/svelte/app.svelte +0 -11
- data/lib/install/examples/svelte/hello_svelte.js +0 -20
- data/lib/install/examples/typescript/hello_typescript.ts +0 -4
- data/lib/install/examples/typescript/tsconfig.json +0 -24
- data/lib/install/examples/vue/app.vue +0 -22
- data/lib/install/examples/vue/hello_vue.js +0 -72
- data/lib/install/loaders/coffee.js +0 -6
- data/lib/install/loaders/elm.js +0 -25
- data/lib/install/loaders/erb.js +0 -11
- data/lib/install/loaders/svelte.js +0 -9
- data/lib/install/loaders/vue.js +0 -6
- data/lib/install/react.rb +0 -18
- data/lib/install/stimulus.rb +0 -12
- data/lib/install/svelte.rb +0 -29
- data/lib/install/typescript.rb +0 -39
- data/lib/install/vue.rb +0 -49
- data/lib/tasks/installers.rake +0 -42
- data/package/config_types/__tests__/config_list.js +0 -118
- data/package/config_types/__tests__/config_object.js +0 -43
- data/package/config_types/config_list.js +0 -75
- data/package/config_types/config_object.js +0 -55
- data/package/config_types/index.js +0 -7
- data/package/rules/module.css.js +0 -3
- data/package/rules/module.sass.js +0 -8
- data/package/rules/node_modules.js +0 -22
- data/package/utils/__tests__/deep_assign.js +0 -32
- data/package/utils/__tests__/deep_merge.js +0 -10
- data/package/utils/__tests__/get_style_rule.js +0 -65
- data/package/utils/__tests__/objectify.js +0 -9
- data/package/utils/deep_assign.js +0 -22
- data/package/utils/deep_merge.js +0 -22
- data/package/utils/objectify.js +0 -3
- /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
@@ -1,77 +1,79 @@
|
|
1
|
-
|
1
|
+
/* eslint global-require: 0 */
|
2
|
+
/* eslint import/no-dynamic-require: 0 */
|
3
|
+
|
4
|
+
const { merge } = require('webpack-merge')
|
2
5
|
const CompressionPlugin = require('compression-webpack-plugin')
|
3
|
-
const
|
4
|
-
const
|
5
|
-
const
|
6
|
+
const TerserPlugin = require('terser-webpack-plugin')
|
7
|
+
const baseConfig = require('./base')
|
8
|
+
const { moduleExists } = require('../utils/helpers')
|
9
|
+
|
10
|
+
const getPlugins = () => {
|
11
|
+
const plugins = []
|
6
12
|
|
7
|
-
|
8
|
-
|
9
|
-
|
13
|
+
plugins.push(
|
14
|
+
new CompressionPlugin({
|
15
|
+
filename: '[path][base].gz[query]',
|
16
|
+
algorithm: 'gzip',
|
17
|
+
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
18
|
+
})
|
19
|
+
)
|
10
20
|
|
11
|
-
|
12
|
-
|
21
|
+
if ('brotli' in process.versions) {
|
22
|
+
plugins.push(
|
13
23
|
new CompressionPlugin({
|
14
|
-
filename: '[path].
|
15
|
-
algorithm: '
|
24
|
+
filename: '[path][base].br[query]',
|
25
|
+
algorithm: 'brotliCompress',
|
16
26
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
17
27
|
})
|
18
28
|
)
|
29
|
+
}
|
19
30
|
|
20
|
-
|
21
|
-
|
22
|
-
'Compression Brotli',
|
23
|
-
new CompressionPlugin({
|
24
|
-
filename: '[path].br[query]',
|
25
|
-
algorithm: 'brotliCompress',
|
26
|
-
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
27
|
-
})
|
28
|
-
)
|
29
|
-
}
|
31
|
+
return plugins
|
32
|
+
}
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
const tryCssMinimizer = () => {
|
35
|
+
if (
|
36
|
+
moduleExists('css-loader') &&
|
37
|
+
moduleExists('css-minimizer-webpack-plugin')
|
38
|
+
) {
|
39
|
+
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
|
40
|
+
return new CssMinimizerPlugin()
|
41
|
+
}
|
42
|
+
|
43
|
+
return null
|
44
|
+
}
|
45
|
+
|
46
|
+
const productionConfig = {
|
47
|
+
devtool: 'source-map',
|
48
|
+
stats: 'normal',
|
49
|
+
bail: true,
|
50
|
+
plugins: getPlugins(),
|
51
|
+
optimization: {
|
52
|
+
minimizer: [
|
53
|
+
tryCssMinimizer(),
|
54
|
+
new TerserPlugin({
|
55
|
+
parallel: Number.parseInt(process.env.WEBPACKER_PARALLEL, 10) || true,
|
56
|
+
terserOptions: {
|
57
|
+
parse: {
|
58
|
+
// Let terser parse ecma 8 code but always output
|
59
|
+
// ES5 compliant code for older browsers
|
60
|
+
ecma: 8
|
61
|
+
},
|
62
|
+
compress: {
|
63
|
+
ecma: 5,
|
64
|
+
warnings: false,
|
65
|
+
comparisons: false
|
66
|
+
},
|
67
|
+
mangle: { safari10: true },
|
68
|
+
output: {
|
69
|
+
ecma: 5,
|
70
|
+
comments: false,
|
71
|
+
ascii_only: true
|
72
|
+
}
|
38
73
|
}
|
39
74
|
})
|
40
|
-
)
|
41
|
-
|
42
|
-
this.config.merge({
|
43
|
-
devtool: 'source-map',
|
44
|
-
stats: 'normal',
|
45
|
-
bail: true,
|
46
|
-
optimization: {
|
47
|
-
minimizer: [
|
48
|
-
new TerserPlugin({
|
49
|
-
parallel: Number.parseInt(process.env.WEBPACKER_PARALLEL, 10) || true,
|
50
|
-
cache: true,
|
51
|
-
sourceMap: true,
|
52
|
-
terserOptions: {
|
53
|
-
parse: {
|
54
|
-
// Let terser parse ecma 8 code but always output
|
55
|
-
// ES5 compliant code for older browsers
|
56
|
-
ecma: 8
|
57
|
-
},
|
58
|
-
compress: {
|
59
|
-
ecma: 5,
|
60
|
-
warnings: false,
|
61
|
-
comparisons: false
|
62
|
-
},
|
63
|
-
mangle: {
|
64
|
-
safari10: true
|
65
|
-
},
|
66
|
-
output: {
|
67
|
-
ecma: 5,
|
68
|
-
comments: false,
|
69
|
-
ascii_only: true
|
70
|
-
}
|
71
|
-
}
|
72
|
-
})
|
73
|
-
]
|
74
|
-
}
|
75
|
-
})
|
75
|
+
].filter(Boolean)
|
76
76
|
}
|
77
77
|
}
|
78
|
+
|
79
|
+
module.exports = merge(baseConfig, productionConfig)
|
@@ -1,3 +1,3 @@
|
|
1
|
-
const
|
1
|
+
const baseConfig = require('./base')
|
2
2
|
|
3
|
-
module.exports =
|
3
|
+
module.exports = baseConfig
|
data/package/index.js
CHANGED
@@ -1,24 +1,31 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
+
const webpackMerge = require('webpack-merge')
|
4
5
|
const { resolve } = require('path')
|
5
6
|
const { existsSync } = require('fs')
|
6
|
-
const
|
7
|
-
const
|
7
|
+
const baseConfig = require('./environments/base')
|
8
|
+
const rules = require('./rules')
|
8
9
|
const config = require('./config')
|
9
10
|
const devServer = require('./dev_server')
|
10
11
|
const { nodeEnv } = require('./env')
|
12
|
+
const { moduleExists, canProcess } = require('./utils/helpers')
|
13
|
+
const inliningCss = require('./inliningCss')
|
11
14
|
|
12
|
-
const
|
15
|
+
const webpackConfig = () => {
|
13
16
|
const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
|
14
|
-
const
|
15
|
-
return
|
17
|
+
const environmentConfig = existsSync(path) ? require(path) : baseConfig
|
18
|
+
return environmentConfig
|
16
19
|
}
|
17
20
|
|
18
21
|
module.exports = {
|
19
22
|
config,
|
20
23
|
devServer,
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
webpackConfig: webpackConfig(),
|
25
|
+
baseConfig,
|
26
|
+
rules,
|
27
|
+
moduleExists,
|
28
|
+
canProcess,
|
29
|
+
inliningCss,
|
30
|
+
...webpackMerge
|
24
31
|
}
|
data/package/rules/babel.js
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
const { resolve } = require('path')
|
2
2
|
const { realpathSync } = require('fs')
|
3
|
-
const { source_path: sourcePath, additional_paths: additionalPaths } = require('../config')
|
4
|
-
const { nodeEnv } = require('../env')
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
const {
|
5
|
+
source_path: sourcePath,
|
6
|
+
additional_paths: additionalPaths
|
7
|
+
} = require('../config')
|
8
|
+
const { isProduction } = require('../env')
|
9
|
+
|
8
10
|
module.exports = {
|
9
|
-
test: /\.(js|jsx|mjs|ts|tsx)?(\.erb)?$/,
|
11
|
+
test: /\.(js|jsx|mjs|ts|tsx|coffee)?(\.erb)?$/,
|
10
12
|
include: [sourcePath, ...additionalPaths].map((p) => {
|
11
13
|
try {
|
12
14
|
return realpathSync(p)
|
@@ -17,11 +19,11 @@ module.exports = {
|
|
17
19
|
exclude: /node_modules/,
|
18
20
|
use: [
|
19
21
|
{
|
20
|
-
loader: 'babel-loader',
|
22
|
+
loader: require.resolve('babel-loader'),
|
21
23
|
options: {
|
22
24
|
cacheDirectory: true,
|
23
|
-
cacheCompression:
|
24
|
-
compact:
|
25
|
+
cacheCompression: isProduction,
|
26
|
+
compact: isProduction
|
25
27
|
}
|
26
28
|
}
|
27
29
|
]
|
@@ -0,0 +1,15 @@
|
|
1
|
+
const { canProcess } = require('../utils/helpers')
|
2
|
+
|
3
|
+
const runner = /^win/.test(process.platform) ? 'ruby ' : ''
|
4
|
+
|
5
|
+
module.exports = canProcess('rails-erb-loader', (resolvedPath) => ({
|
6
|
+
test: /\.erb$/,
|
7
|
+
enforce: 'pre',
|
8
|
+
exclude: /node_modules/,
|
9
|
+
use: [
|
10
|
+
{
|
11
|
+
loader: resolvedPath,
|
12
|
+
options: { runner: `${runner}bin/rails runner` }
|
13
|
+
}
|
14
|
+
]
|
15
|
+
}))
|
data/package/rules/file.js
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
const { join, normalize } = require('path')
|
2
|
-
const { source_path: sourcePath, static_assets_extensions: fileExtensions } = require('../config')
|
3
|
-
|
4
1
|
module.exports = {
|
5
|
-
test:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
]
|
2
|
+
test: [
|
3
|
+
/\.bmp$/,
|
4
|
+
/\.gif$/,
|
5
|
+
/\.jpe?g$/,
|
6
|
+
/\.png$/,
|
7
|
+
/\.tiff$/,
|
8
|
+
/\.ico$/,
|
9
|
+
/\.avif$/,
|
10
|
+
/\.webp$/,
|
11
|
+
/\.eot$/,
|
12
|
+
/\.otf$/,
|
13
|
+
/\.ttf$/,
|
14
|
+
/\.woff$/,
|
15
|
+
/\.woff2$/,
|
16
|
+
/\.svg$/
|
17
|
+
],
|
18
|
+
exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
|
19
|
+
type: 'asset/resource',
|
20
|
+
generator: {
|
21
|
+
filename: 'static/[name]-[hash][ext][query]'
|
22
|
+
}
|
21
23
|
}
|
data/package/rules/index.js
CHANGED
@@ -1,20 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const css = require('./css')
|
4
|
-
const sass = require('./sass')
|
5
|
-
const moduleCss = require('./module.css')
|
6
|
-
const moduleSass = require('./module.sass')
|
7
|
-
const nodeModules = require('./node_modules')
|
1
|
+
/* eslint global-require: 0 */
|
2
|
+
/* eslint import/no-dynamic-require: 0 */
|
8
3
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
babel
|
4
|
+
const rules = {
|
5
|
+
raw: require('./raw'),
|
6
|
+
file: require('./file'),
|
7
|
+
css: require('./css'),
|
8
|
+
sass: require('./sass'),
|
9
|
+
babel: require('./babel'),
|
10
|
+
erb: require('./erb'),
|
11
|
+
coffee: require('./coffee'),
|
12
|
+
less: require('./less'),
|
13
|
+
stylus: require('./stylus')
|
20
14
|
}
|
15
|
+
|
16
|
+
module.exports = Object.keys(rules)
|
17
|
+
.filter((key) => !!rules[key])
|
18
|
+
.map((key) => rules[key])
|
@@ -0,0 +1,22 @@
|
|
1
|
+
const path = require('path')
|
2
|
+
const { canProcess } = require('../utils/helpers')
|
3
|
+
const getStyleRule = require('../utils/get_style_rule')
|
4
|
+
|
5
|
+
const {
|
6
|
+
additional_paths: paths,
|
7
|
+
source_path: sourcePath
|
8
|
+
} = require('../config')
|
9
|
+
|
10
|
+
module.exports = canProcess('less-loader', (resolvedPath) =>
|
11
|
+
getStyleRule(/\.(less)(\.erb)?$/i, [
|
12
|
+
{
|
13
|
+
loader: resolvedPath,
|
14
|
+
options: {
|
15
|
+
lessOptions: {
|
16
|
+
paths: [path.resolve(__dirname, 'node_modules'), sourcePath, ...paths]
|
17
|
+
},
|
18
|
+
sourceMap: true
|
19
|
+
}
|
20
|
+
}
|
21
|
+
])
|
22
|
+
)
|
data/package/rules/sass.js
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
|
3
3
|
const getStyleRule = require('../utils/get_style_rule')
|
4
|
+
const { canProcess } = require('../utils/helpers')
|
4
5
|
const { additional_paths: includePaths } = require('../config')
|
5
6
|
|
6
|
-
module.exports =
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
sassOptions: {
|
13
|
-
includePaths
|
7
|
+
module.exports = canProcess('sass-loader', (resolvedPath) =>
|
8
|
+
getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
|
9
|
+
{
|
10
|
+
loader: resolvedPath,
|
11
|
+
options: {
|
12
|
+
sassOptions: { includePaths }
|
14
13
|
}
|
15
14
|
}
|
16
|
-
|
17
|
-
|
15
|
+
])
|
16
|
+
)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
const path = require('path')
|
2
|
+
const { canProcess } = require('../utils/helpers')
|
3
|
+
const getStyleRule = require('../utils/get_style_rule')
|
4
|
+
|
5
|
+
const {
|
6
|
+
additional_paths: paths,
|
7
|
+
source_path: sourcePath
|
8
|
+
} = require('../config')
|
9
|
+
|
10
|
+
module.exports = canProcess('stylus-loader', (resolvedPath) =>
|
11
|
+
getStyleRule(/\.(styl(us)?)(\.erb)?$/i, [
|
12
|
+
{
|
13
|
+
loader: resolvedPath,
|
14
|
+
options: {
|
15
|
+
stylusOptions: {
|
16
|
+
include: [
|
17
|
+
path.resolve(__dirname, 'node_modules'),
|
18
|
+
sourcePath,
|
19
|
+
...paths
|
20
|
+
]
|
21
|
+
},
|
22
|
+
sourceMap: true
|
23
|
+
}
|
24
|
+
}
|
25
|
+
])
|
26
|
+
)
|
@@ -1,45 +1,37 @@
|
|
1
|
-
|
2
|
-
const {
|
3
|
-
const
|
1
|
+
/* eslint global-require: 0 */
|
2
|
+
const { canProcess, moduleExists } = require('./helpers')
|
3
|
+
const inliningCss = require('../inliningCss')
|
4
4
|
|
5
|
-
const
|
6
|
-
|
7
|
-
|
5
|
+
const getStyleRule = (test, preprocessors = []) => {
|
6
|
+
if (moduleExists('css-loader')) {
|
7
|
+
const tryPostcss = () =>
|
8
|
+
canProcess('postcss-loader', (loaderPath) => ({
|
9
|
+
loader: loaderPath,
|
10
|
+
options: { sourceMap: true }
|
11
|
+
}))
|
8
12
|
|
9
|
-
|
10
|
-
const use = [
|
11
|
-
{
|
12
|
-
loader: 'css-loader',
|
13
|
-
options: {
|
14
|
-
sourceMap: true,
|
15
|
-
importLoaders: 2,
|
16
|
-
modules: modules ? {
|
17
|
-
localIdentName: '[name]__[local]___[hash:base64:5]'
|
18
|
-
} : false
|
19
|
-
}
|
20
|
-
},
|
21
|
-
{
|
22
|
-
loader: 'postcss-loader',
|
23
|
-
options: {
|
24
|
-
config: { path: resolve() },
|
25
|
-
sourceMap: true
|
26
|
-
}
|
27
|
-
},
|
28
|
-
...preprocessors
|
29
|
-
]
|
13
|
+
// style-loader is required when using css modules with HMR on the webpack-dev-server
|
30
14
|
|
31
|
-
|
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
|
-
|
36
|
-
|
28
|
+
return {
|
29
|
+
test,
|
30
|
+
use
|
31
|
+
}
|
37
32
|
}
|
38
33
|
|
39
|
-
|
40
|
-
return {
|
41
|
-
test, use, sideEffects: !modules, ...options
|
42
|
-
}
|
34
|
+
return null
|
43
35
|
}
|
44
36
|
|
45
37
|
module.exports = getStyleRule
|
data/package/utils/helpers.js
CHANGED
@@ -1,30 +1,5 @@
|
|
1
|
-
const { stringify } = require('flatted')
|
2
|
-
|
3
|
-
const isObject = (value) => typeof value === 'object'
|
4
|
-
&& value !== null
|
5
|
-
&& (value.length === undefined || value.length === null)
|
6
|
-
|
7
|
-
const isNotObject = (value) => !isObject(value)
|
8
|
-
|
9
|
-
const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
|
10
|
-
|
11
|
-
const isEmpty = (value) => value === null || value === undefined
|
12
|
-
|
13
|
-
const isString = (key) => key && typeof key === 'string'
|
14
|
-
|
15
|
-
const isStrPath = (key) => {
|
16
|
-
if (!isString(key)) throw new Error(`Key ${key} should be string`)
|
17
|
-
return isString(key) && key.includes('.')
|
18
|
-
}
|
19
|
-
|
20
1
|
const isArray = (value) => Array.isArray(value)
|
21
|
-
|
22
|
-
const isEqual = (target, source) => stringify(target) === stringify(source)
|
23
|
-
|
24
|
-
const canMerge = (value) => isObject(value) || isArray(value)
|
25
|
-
|
26
|
-
const prettyPrint = (obj) => JSON.stringify(obj, null, 2)
|
27
|
-
|
2
|
+
const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
|
28
3
|
const chdirTestApp = () => {
|
29
4
|
try {
|
30
5
|
return process.chdir('test/test_app')
|
@@ -41,18 +16,36 @@ const resetEnv = () => {
|
|
41
16
|
|
42
17
|
const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
|
43
18
|
|
19
|
+
const resolvedPath = (packageName) => {
|
20
|
+
try {
|
21
|
+
return require.resolve(packageName)
|
22
|
+
} catch (e) {
|
23
|
+
if (e.code !== 'MODULE_NOT_FOUND') {
|
24
|
+
throw e
|
25
|
+
}
|
26
|
+
return null
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
const moduleExists = (packageName) => (!!resolvedPath(packageName))
|
31
|
+
|
32
|
+
const canProcess = (rule, fn) => {
|
33
|
+
const modulePath = resolvedPath(rule)
|
34
|
+
|
35
|
+
if (modulePath) {
|
36
|
+
return fn(modulePath)
|
37
|
+
}
|
38
|
+
|
39
|
+
return null
|
40
|
+
}
|
41
|
+
|
44
42
|
module.exports = {
|
45
43
|
chdirTestApp,
|
46
44
|
chdirCwd,
|
47
|
-
ensureTrailingSlash,
|
48
|
-
isObject,
|
49
|
-
isNotObject,
|
50
|
-
isBoolean,
|
51
45
|
isArray,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
prettyPrint,
|
46
|
+
isBoolean,
|
47
|
+
ensureTrailingSlash,
|
48
|
+
canProcess,
|
49
|
+
moduleExists,
|
57
50
|
resetEnv
|
58
51
|
}
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rails/webpacker",
|
3
|
-
"version": "
|
3
|
+
"version": "6.0.0-rc.6",
|
4
4
|
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
5
5
|
"main": "package/index.js",
|
6
6
|
"files": [
|
@@ -8,56 +8,36 @@
|
|
8
8
|
"lib/install/config/webpacker.yml"
|
9
9
|
],
|
10
10
|
"engines": {
|
11
|
-
"node": ">=
|
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-
|
18
|
-
"@babel/
|
19
|
-
"@babel/
|
20
|
-
"@babel/plugin-transform-regenerator": "^7.13.15",
|
21
|
-
"@babel/plugin-transform-runtime": "^7.14.3",
|
22
|
-
"@babel/preset-env": "^7.14.2",
|
23
|
-
"@babel/runtime": "^7.14.0",
|
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",
|
24
20
|
"babel-loader": "^8.2.2",
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"compression-webpack-plugin": "^4.0.1",
|
29
|
-
"core-js": "^3.12.1",
|
30
|
-
"css-loader": "^3.6.0",
|
31
|
-
"file-loader": "^6.2.0",
|
32
|
-
"flatted": "^3.1.1",
|
33
|
-
"glob": "^7.1.7",
|
34
|
-
"js-yaml": "^3.14.1",
|
35
|
-
"mini-css-extract-plugin": "^0.9.0",
|
36
|
-
"optimize-css-assets-webpack-plugin": "^5.0.6",
|
21
|
+
"compression-webpack-plugin": "^9.0.0",
|
22
|
+
"glob": "^7.2.0",
|
23
|
+
"js-yaml": "^4.1.0",
|
37
24
|
"path-complete-extname": "^1.0.0",
|
38
|
-
"pnp-webpack-plugin": "^1.
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"sass": "^1.32.13",
|
46
|
-
"sass-loader": "10.1.1",
|
47
|
-
"style-loader": "^1.3.0",
|
48
|
-
"terser-webpack-plugin": "^4.2.3",
|
49
|
-
"webpack": "^4.46.0",
|
50
|
-
"webpack-assets-manifest": "^3.1.1",
|
51
|
-
"webpack-cli": "^3.3.12",
|
52
|
-
"webpack-sources": "^1.4.3"
|
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"
|
53
32
|
},
|
54
33
|
"devDependencies": {
|
55
|
-
"eslint": "^7.
|
34
|
+
"eslint": "^7.32.0",
|
56
35
|
"eslint-config-airbnb": "^18.2.1",
|
57
|
-
"eslint-
|
36
|
+
"eslint-config-prettier": "^8.3.0",
|
37
|
+
"eslint-plugin-import": "^2.24.2",
|
58
38
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
59
|
-
"eslint-plugin-react": "^7.
|
60
|
-
"jest": "^
|
39
|
+
"eslint-plugin-react": "^7.26.0",
|
40
|
+
"jest": "^27.2.1"
|
61
41
|
},
|
62
42
|
"jest": {
|
63
43
|
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|