Skip to content

Commit f936614

Browse files
Install shakapacker
1 parent 18142d5 commit f936614

21 files changed

+3629
-500
lines changed

bin/webpacker renamed to bin/shakapacker

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ require "bundler/setup"
77

88
# Add the Decidim override load path to override webpacker functionality
99
$LOAD_PATH.unshift "#{Gem.loaded_specs["decidim-core"].full_gem_path}/lib/gem_overrides"
10-
require "webpacker"
11-
require "webpacker/webpack_runner"
10+
require "shakapacker"
11+
require "shakapacker/webpack_runner"
1212

1313
APP_ROOT = File.expand_path("..", __dir__)
1414
Dir.chdir(APP_ROOT) do
15-
Webpacker::WebpackRunner.run(ARGV)
15+
Shakapacker::WebpackRunner.run(ARGV)
1616
end

bin/webpacker-dev-server renamed to bin/shakapacker-dev-server

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ require "bundler/setup"
77

88
# Add the Decidim override load path to override webpacker functionality
99
$LOAD_PATH.unshift "#{Gem.loaded_specs["decidim-core"].full_gem_path}/lib/gem_overrides"
10-
require "webpacker"
11-
require "webpacker/dev_server_runner"
10+
require "shakapacker"
11+
require "shakapacker/dev_server_runner"
1212

1313
APP_ROOT = File.expand_path("..", __dir__)
1414
Dir.chdir(APP_ROOT) do
15-
Webpacker::DevServerRunner.run(ARGV)
15+
Shakapacker::DevServerRunner.run(ARGV)
1616
end

config/webpacker.yml renamed to config/shakapacker.yml

+27-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
default: &default
55
source_path: app/packs
66
source_entry_path: entrypoints
7-
public_output_path: decidim-packs
7+
nested_entries: true
8+
css_extract_ignore_order_warnings: false
9+
810
public_root_path: public
11+
public_output_path: decidim-packs
12+
cache_path: tmp/shakapacker
913
webpack_compile_output: true
10-
cache_path: tmp/webpacker-cache
1114
extract_css: true
15+
shakapacker_precompile: true
1216

1317
additional_paths:
1418
- node_modules
@@ -17,9 +21,24 @@ default: &default
1721
# Reload manifest.json on all requests so we reload latest compiled packs
1822
cache_manifest: false
1923

24+
# Select loader to use, available options are 'babel' (default), 'swc' or 'esbuild'
25+
webpack_loader: 'babel'
26+
27+
# Set to true to enable check for matching versions of shakapacker gem and NPM package - will raise an error if there is a mismatch or wildcard versioning is used
28+
ensure_consistent_versioning: true
29+
30+
# Select whether the compiler will use SHA digest ('digest' option) or most most recent modified timestamp ('mtime') to determine freshness
31+
compiler_strategy: digest
32+
33+
# Select whether the compiler will always use a content hash and not just in production
34+
# Do not use contentHash except for production for performance
35+
# https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
36+
useContentHash: false
37+
2038
development:
2139
<<: *default
2240
compile: true
41+
compiler_strategy: mtime
2342
# Compile test packs to decidim decidim-packs folder
2443

2544
# Reference: https://webpack.js.org/configuration/dev-server/
@@ -31,9 +50,11 @@ development:
3150
port: 3035
3251
# Hot Module Replacement updates modules while the application is running without a full reload
3352
hmr: false
53+
# mini-css-extract-plugin is a required dependency in both cases.
54+
inline_css: true
3455
client:
3556
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
36-
overlay: true
57+
overlay: false
3758
# May also be a string
3859
# webSocketURL:
3960
# hostname: "0.0.0.0"
@@ -61,5 +82,8 @@ production:
6182
# Production depends on precompilation of packs prior to booting for performance.
6283
compile: false
6384

85+
# Use content hash for naming assets. Cannot be overridden by for production.
86+
useContentHash: true
87+
6488
# Cache manifest.json for performance
6589
cache_manifest: true

config/webpack/base.js

-6
This file was deleted.

config/webpack/custom.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable */
22
const { config } = require("shakapacker");
33
const { InjectManifest } = require("workbox-webpack-plugin");
4+
const TerserPlugin = require('terser-webpack-plugin')
45

56
module.exports = {
67
module: {
@@ -83,7 +84,29 @@ module.exports = {
8384
// https://github.com/rails/webpacker/issues/2932
8485
// As Decidim uses multiple packs, we need to enforce a single runtime, to prevent duplication
8586
optimization: {
86-
runtimeChunk: false
87+
minimizer: [
88+
new TerserPlugin({
89+
parallel: Number.parseInt(process.env.SHAKAPACKER_PARALLEL, 10) || true,
90+
terserOptions: {
91+
parse: {
92+
// Let terser parse ecma 8 code but always output
93+
// ES5 compliant code for older browsers
94+
ecma: 8
95+
},
96+
compress: {
97+
ecma: 5,
98+
warnings: false,
99+
comparisons: false
100+
},
101+
mangle: { safari10: true },
102+
output: {
103+
ecma: 5,
104+
comments: false,
105+
ascii_only: true
106+
}
107+
}
108+
})
109+
].filter(Boolean)
87110
},
88111
entry: config.entrypoints,
89112
plugins: [

config/webpack/development.js

-7
This file was deleted.

config/webpack/production.js

-7
This file was deleted.

config/webpack/test.js

-7
This file was deleted.

config/webpack/webpack.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ process.env.NODE_ENV ??= "development"
44
const { webpackConfig, merge } = require("@decidim/webpacker")
55
const customConfig = require("./custom")
66

7-
module.exports = merge(webpackConfig, customConfig)
7+
webpackConfig.optimization = {}
8+
const combinedConfig = merge(webpackConfig, customConfig)
9+
10+
module.exports = combinedConfig

0 commit comments

Comments
 (0)