Skip to content

Commit 2527c46

Browse files
Migrating from Webpack Encore to AssetMapper (#77)
1 parent 746503a commit 2527c46

27 files changed

+764
-9011
lines changed

.dockerignore

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ vendor
1313
phpunit.xml
1414
###< symfony/phpunit-bridge ###
1515

16-
###> symfony/webpack-encore-bundle ###
17-
node_modules
18-
public/build
19-
npm-debug.log
20-
yarn-error.log
21-
###< symfony/webpack-encore-bundle ###
16+
###> symfony/asset-mapper ###
17+
/public/assets/
18+
/assets/vendor/
19+
###< symfony/asset-mapper ###
2220

2321
.dockerignore
2422
.DS_Store

.github/workflows/build.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,7 @@ jobs:
4444
- name: Install dependencies
4545
run: composer install --optimize-autoloader --no-interaction --no-progress
4646

47-
- name: Use Node.js
48-
uses: actions/setup-node@v3
49-
with:
50-
node-version: 18
51-
52-
- run: npm install
53-
- run: npm run build
47+
- run: bin/console asset-map:compile
5448

5549
- run: sudo chown -R $USER:$USER /home/runner/work/elasticsearch-admin/elasticsearch-admin
5650
- run: bin/console app:phpunit

.gitignore

+5-7
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
.phpunit.result.cache
2121
###< phpunit/phpunit ###
2222

23-
###> symfony/webpack-encore-bundle ###
24-
/node_modules/
25-
/public/build/
26-
npm-debug.log
27-
yarn-error.log
28-
###< symfony/webpack-encore-bundle ###
29-
3023
###> app ###
3124
.env
3225
.php_cs.cache
3326
.php-cs-fixer.cache
3427
info.json
3528
public/.htaccess
3629
###< app ###
30+
31+
###> symfony/asset-mapper ###
32+
/public/assets/
33+
/assets/vendor/
34+
###< symfony/asset-mapper ###

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ env:
2525

2626
install:
2727
- composer install
28-
- npm install
29-
- npm run build
28+
- bin/console asset-map:compile
3029

3130
script:
3231
- bin/console app:phpunit

Dockerfile

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ ENV SECRET_REGISTER=$SECRET_REGISTER
1818
RUN apk --no-cache add php82 php82-fpm php82-opcache php82-json php82-openssl php82-curl php82-zlib php82-fileinfo \
1919
php82-xml php82-simplexml php82-phar php82-intl php82-dom php82-xmlreader php82-ctype php82-session php82-gd \
2020
php82-tokenizer php82-pdo php82-pdo_mysql php82-pdo_pgsql php82-iconv php82-zip php82-gmp php82-mbstring php82-xmlwriter \
21-
nginx supervisor nodejs npm curl
21+
nginx supervisor curl
2222

2323
# Create symlink so programs depending on `php` still function
24-
#RUN ln -s /usr/bin/php82 /usr/bin/php
24+
RUN ln -s /usr/bin/php82 /usr/bin/php
2525

2626
# Configure nginx
2727
COPY docker/nginx.conf /etc/nginx/nginx.conf
@@ -37,12 +37,11 @@ COPY docker/php.ini /etc/php82/conf.d/custom.ini
3737
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
3838

3939
# Create folders
40-
RUN mkdir -p /var/www/html && mkdir -p /.composer && mkdir -p /.npm
40+
RUN mkdir -p /var/www/html && mkdir -p /.composer
4141

4242
# Make sure files/folders needed by the processes are accessable when they run under the nobody user
4343
RUN chown -R nobody.nobody /var/www/html && \
4444
chown -R nobody.nobody /.composer && \
45-
chown -R nobody.nobody /.npm && \
4645
chown -R nobody.nobody /etc/nginx && \
4746
chown -R nobody.nobody /run && \
4847
chown -R nobody.nobody /var/lib/nginx && \
@@ -61,8 +60,7 @@ COPY --from=composer /usr/bin/composer /usr/bin/composer
6160
# Run composer install to install the dependencies
6261
RUN composer install --optimize-autoloader --no-interaction --no-progress --no-dev
6362

64-
RUN npm install
65-
RUN npm run build
63+
RUN bin/console asset-map:compile
6664

6765
COPY --chown=nobody .env.dist .env
6866

File renamed without changes.
File renamed without changes.
File renamed without changes.

assets/js/app.js renamed to assets/app.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import 'bootstrap/dist/css/bootstrap.min.css';
2+
import 'bootstrap-icons/font/bootstrap-icons.min.css';
3+
import './styles/app.css';
4+
5+
import { Dropdown, Modal, Toast } from 'bootstrap';
6+
7+
const dropdownElementList = document.querySelectorAll('.dropdown-toggle');
8+
const dropdownList = [...dropdownElementList].map(dropdownToggleEl => new Dropdown(dropdownToggleEl));
9+
110
(() => {
211
'use strict'
312

@@ -53,23 +62,17 @@
5362
})
5463
})();
5564

56-
require('jquery');
57-
global.$ = global.jQuery = $;
65+
import $ from 'jquery';
5866

59-
require('bootstrap');
67+
import saveAs from 'file-saver';
68+
69+
import slug from 'slug';
6070

61-
import { saveAs } from 'file-saver';
62-
var slug = require('slug');
6371
slug.charmap['/'] = '-';
6472
slug.charmap['?'] = '-';
6573
slug.charmap['='] = '-';
66-
global.slug = slug;
67-
68-
global.sleep = function sleep(ms) {
69-
return new Promise(resolve => setTimeout(resolve, ms));
70-
}
7174

72-
global.createToast = function createToast(body) {
75+
var createToast = function createToast(body) {
7376
var toast = `<div class="toast bg-dark text-light border border-secondary" role="alert" aria-live="assertive" aria-atomic="true">
7477
<div class="toast-body">
7578
${body}
@@ -108,12 +111,12 @@ if (buttonInstall) {
108111
});
109112
}
110113

111-
global.serviceWorkerEnabled = false;
114+
var serviceWorkerEnabled = false;
112115

113116
if('serviceWorker' in navigator && 'https:' == window.location.protocol) {
114117
navigator.serviceWorker.register(app_base_url + 'serviceworker.js')
115118
.then(function(ServiceWorkerRegistration) {
116-
global.serviceWorkerEnabled = true;
119+
serviceWorkerEnabled = true;
117120

118121
if (buttonInstall) {
119122
var standalone = window.matchMedia('(display-mode: standalone)');

assets/css/app.scss renamed to assets/styles/app.css

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
@import "~bootstrap/scss/bootstrap.scss";
2-
3-
@import "~bootstrap-icons/font/bootstrap-icons.scss";
4-
51
#toast-container {
62
position: fixed;
73
right: 20px;

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"minishlink/web-push": "^8.0.0",
1515
"phpoffice/phpspreadsheet": "^1.29",
1616
"symfony/asset": "7.0.*",
17+
"symfony/asset-mapper": "7.0.*",
1718
"symfony/console": "7.0.*",
1819
"symfony/dotenv": "7.0.*",
1920
"symfony/expression-language": "7.0.*",
@@ -33,7 +34,6 @@
3334
"symfony/translation": "7.0.*",
3435
"symfony/twig-bundle": "7.0.*",
3536
"symfony/validator": "7.0.*",
36-
"symfony/webpack-encore-bundle": "^2.1",
3737
"symfony/yaml": "7.0.*",
3838
"twig/extra-bundle": "^2.12|^3.0",
3939
"twig/twig": "^2.12|^3.0"
@@ -80,7 +80,8 @@
8080
"scripts": {
8181
"auto-scripts": {
8282
"cache:clear": "symfony-cmd",
83-
"assets:install %PUBLIC_DIR%": "symfony-cmd"
83+
"assets:install %PUBLIC_DIR%": "symfony-cmd",
84+
"importmap:install": "symfony-cmd"
8485
},
8586
"post-install-cmd": [
8687
"@auto-scripts"

0 commit comments

Comments
 (0)