Uglify example

master
Juan 3 years ago
parent f28db14896
commit 1dfc3e25a3

@ -0,0 +1,62 @@
// commencer par importer gulp
// si on veux utiliser import il faut décalrer dans le package que l'on est en modules
// => "type":"module", et pas "type":"commonjs",
// dans le futur :
// import * as gulp from gulp;
// mais en version actuelle :
const gulp = require('gulp');
const gsass = require('gulp-sass')(require('sass')); // on require gsass et lui assigne sass comme compilateur
const gugly = require('gulp-uglify-es');
const sourcemaps = require('gulp-sourcemaps');
const { SourceMap } = require('module');
const {basename} = require('path'); // ceci permet de récupérer la fonction basename initialisée dans le module node "path"
const {dirname:basedir,normalize:normalize_path} = require('path'); // ceci permet de récupérer la fonction dirname initialisée dans le module node "path" en la renommant en basedir
// !! => cast en boolean
const [un,deux,,quatre] = [!!1,2,gulp,"four"]; //assigne chaque case de tableau de droite à une const définie dans le tableau gauche en ignorant les éléments vide (ici le 3e element de gauche)
const two = null;
const undefined2 = two ?? 2; // defini undefined2 a two si elle est non "nullable", sinon assigne 2
const struct_of_twos = {
two: { arab : 2, roman : 'II' },
deux : 2
}
let redefine2 = deux?.arab;
// redefine2 vaut ici 2 ça s'arrête à la première prop valide trouvée.
// pour voir la console faire "node gulpfile.js"
console.log(basedir(__filename));
// __dirname existe
function sass() {
return gulp.src(normalize_path(basedir(__filename)+'/style-main.scss'))
.pipe(sourcemaps.init())
.pipe(gsass())
.pipe(sourcemaps.write(basedir(__filename)))
.pipe(gulp.dest(basedir(__filename)));
}
function uglify() {
var dest = normalize_path(basedir(__filename)+'/scripts/');
return gulp.src(normalize_path(basedir(__filename)+'/scripts-sources/**/*.js'))
.pipe(sourcemaps.init())
.pipe(gugly.default())
.pipe(sourcemaps.write(dest))
.pipe(gulp.dest(dest));
}
// à afficher avec gulp --tasks
module.exports = {
sass,
uglify,
'default' : gulp.parallel(sass,uglify),
};
// exports.sass = sass;
// ou module.exports.sass = sass;
// ou exports['default'] =
// cwd à check pour gulp car il indique le "current working dir"

File diff suppressed because it is too large Load Diff

@ -0,0 +1,21 @@
{
"name": "uglifyjs-test",
"version": "1.0.0",
"description": "test gulp et uglify pour compilation ",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"type": "commonjs",
"dependencies": {
"del": "^6.0.0",
"gulp": "^4.0.2",
"gulp-sass": "^5.0.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-uglify-es": "^3.0.0",
"gulp-watch": "^5.0.1",
"sass": "^1.43.4"
}
}

@ -18,7 +18,7 @@ body, figure, img {
}
.img-wrap img {
width: calc(100% - (8px*2));
width: calc(100% - 16px);
height: auto;
margin: 8px;
top: 50%;
@ -35,12 +35,15 @@ picture {
#main-menu {
text-align: center;
}
#main-menu ul {
list-style: none;
}
#main-menu li {
text-align: left;
}
#main-menu li a,
#main-menu li span,
#main-menu li label {
@ -48,9 +51,11 @@ picture {
text-decoration: none;
font-size: 1.1rem;
}
#main-menu li span {
color: #666;
}
#main-menu .menu-label {
font-size: 1.5rem;
color: black;
@ -64,10 +69,12 @@ picture {
float: left;
margin: 3px 8px;
}
.burger b, .burger i {
display: block;
width: 20px;
}
.burger b {
height: 2px;
margin-bottom: 5px;
@ -76,9 +83,11 @@ picture {
border-radius: 2px;
z-index: 1;
}
.burger b:first-of-type {
margin-top: 5px;
}
.burger i {
color: blue;
}
@ -112,6 +121,7 @@ main, h1 {
left: 0;
right: 0;
}
.contact-form-wrap .h3 {
color: white;
text-align: center;
@ -127,6 +137,7 @@ main, h1 {
padding: 20px;
border-radius: 20px;
}
.cf-input, .cf-label {
min-height: 20px;
line-height: 20px;
@ -134,15 +145,18 @@ main, h1 {
width: 100%;
min-width: 30vh;
}
.cf-input {
border: solid 1px #666;
border-radius: 4px;
padding: 4px;
}
.cf-label {
line-height: 30px;
box-sizing: border-box;
}
.cf-btn {
background-color: black;
color: white;
@ -150,20 +164,24 @@ main, h1 {
padding-right: 10px;
margin-top: 4px;
}
.cf-btn:hover {
background-color: white;
color: black;
transition: color 0.5s;
}
.cf-input-group:after {
content: "";
display: table;
clear: both;
overflow: auto;
}
.cf-close-wrap {
margin: -10px -10px 0 -20px;
}
.cf-close {
display: block;
position: relative;
@ -185,6 +203,7 @@ main, h1 {
#abonnement-oui:checked ~ .ct-radio .icon-radio-checked {
display: inline;
}
#abonnement-oui:checked ~ .ct-radio .icon-radio-unchecked {
display: none;
}
@ -192,6 +211,7 @@ main, h1 {
#abonnement-non:checked ~ .ct-radio .icon-radio-checked {
display: inline;
}
#abonnement-non:checked ~ .ct-radio .icon-radio-unchecked {
display: none;
}
@ -225,6 +245,7 @@ aside {
top: 75px;
position: fixed;
}
aside img {
max-width: 100%;
}
@ -264,15 +285,19 @@ a[target=_blank]::after {
li[lang] {
color: #ccc;
}
li[lang=fr] {
color: darkblue;
}
li[lang^=fr] {
color: darkblue;
}
li[lang$=CA] {
color: blue;
}
li[lang*="-"] {
font-weight: bold;
}
@ -280,8 +305,10 @@ li[lang*="-"] {
span[class~=red] {
color: red;
}
span[class|=red] {
color: darkred;
}
/*# sourceMappingURL=style-main.css.map */
/*# sourceMappingURL=D:/home/MDS/cours/b2-cwd/integration/live/session4/uglifyjs/style-main.css.map */

@ -0,0 +1,287 @@
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
h4 {
font-size: 14px;
}
body, figure, img {
padding: 0;
border: none;
margin: 0;
}
#switch:checked ~ p {
background-color: green;
}
.img-wrap img {
width: calc(100% - (8px*2));
height: auto;
margin: 8px;
top: 50%;
transform: translateY(-25%);
}
picture {
position: relative;
display: block;
max-height: 40vh;
overflow: hidden;
}
#main-menu {
text-align: center;
}
#main-menu ul {
list-style: none;
}
#main-menu li {
text-align: left;
}
#main-menu li a,
#main-menu li span,
#main-menu li label {
color: black;
text-decoration: none;
font-size: 1.1rem;
}
#main-menu li span {
color: #666;
}
#main-menu .menu-label {
font-size: 1.5rem;
color: black;
text-decoration: none;
font-weight: bold;
display: inline-block;
line-height: 2rem;
}
.burger {
float: left;
margin: 3px 8px;
}
.burger b, .burger i {
display: block;
width: 20px;
}
.burger b {
height: 2px;
margin-bottom: 5px;
position: relative;
background: #000;
border-radius: 2px;
z-index: 1;
}
.burger b:first-of-type {
margin-top: 5px;
}
.burger i {
color: blue;
}
#main-menu ul {
display: none;
}
main, h1 {
margin: 1rem;
padding: 1rem;
}
#main-menu #switch:checked ~ ul {
display: block;
}
.contact-form-wrap {
display: none;
}
#show-contact:checked ~ .contact-form-wrap {
display: block;
}
.contact-form-wrap {
position: fixed;
background-color: rgba(0, 0, 0, 0.25);
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.contact-form-wrap .h3 {
color: white;
text-align: center;
margin-top: 120px;
}
.cf-form {
background-color: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
border-radius: 20px;
}
.cf-input, .cf-label {
min-height: 20px;
line-height: 20px;
box-sizing: border-box;
width: 100%;
min-width: 30vh;
}
.cf-input {
border: solid 1px #666;
border-radius: 4px;
padding: 4px;
}
.cf-label {
line-height: 30px;
box-sizing: border-box;
}
.cf-btn {
background-color: black;
color: white;
padding-left: 10px;
padding-right: 10px;
margin-top: 4px;
}
.cf-btn:hover {
background-color: white;
color: black;
transition: color 0.5s;
}
.cf-input-group:after {
content: "";
display: table;
clear: both;
overflow: auto;
}
.cf-close-wrap {
margin: -10px -10px 0 -20px;
}
.cf-close {
display: block;
position: relative;
box-sizing: border-box;
float: right;
clear: both;
font-size: 20px;
}
.icon-radio-checked {
display: none;
color: green;
}
.icon-radio-unchecked {
color: red;
}
#abonnement-oui:checked ~ .ct-radio .icon-radio-checked {
display: inline;
}
#abonnement-oui:checked ~ .ct-radio .icon-radio-unchecked {
display: none;
}
#abonnement-non:checked ~ .ct-radio .icon-radio-checked {
display: inline;
}
#abonnement-non:checked ~ .ct-radio .icon-radio-unchecked {
display: none;
}
.hidden,
*[aria-hidden] {
display: none !important;
}
.grand-L {
height: 16px;
}
main, aside {
box-sizing: border-box;
}
main {
width: calc(100% - 27vw);
}
.main-stat {
max-width: 73vw;
float: left;
margin: 10px 0 10px -2rem;
}
aside {
width: 25vw;
right: 0;
top: 75px;
position: fixed;
}
aside img {
max-width: 100%;
}
footer {
color: #a9a9a9;
border-top: solid 1px #000;
padding: 10px;
}
a[lang=fr]:after, a[target=_blank]:after {
color: blueviolet;
}
a[lang=fr]::after {
content: " [fr]";
}
a[target=_blank]::after {
content: " [^]";
}
#loaded {
background-color: #ccF;
border-left: solid 3px blue;
color: darkblue;
padding: 3px;
}
#warning {
background-color: #Fed;
border-left: solid 3px red;
color: darkred;
padding: 3px;
}
li[lang] {
color: #ccc;
}
li[lang=fr] {
color: darkblue;
}
li[lang^=fr] {
color: darkblue;
}
li[lang$=CA] {
color: blue;
}
li[lang*="-"] {
font-weight: bold;
}
span[class~=red] {
color: red;
}
span[class|=red] {
color: darkred;
}
/*# sourceMappingURL=style-main.css.map */

@ -0,0 +1,6 @@
//sur un item iterable
// ... permets de "split le tableau"
// ... sur objet permet de list les props
let tab = ['pomme', 'poire', 'pruneau'];
console.log(...tab);
Loading…
Cancel
Save