網頁前端自動化工具 – Grunt
今天為各位介紹的是一個前端工程師所使用的自動化工具「Grunt」,為何我們要使用這個工具呢?其實使用這個工具的原因有很多,因為他的擴充模組(Plugin)也很多,不過今天馬老師從自動最小化(Minify)的角度來介紹這個工具該如何使用。
一般來說前端網頁開發不外乎HTML、CSS、Javascript這三種語法,而在開發完成之後,為了要節省流量,我們可能會把這三個檔案壓縮後再上傳到網站伺服器上,何謂壓縮請參考下圖:
從上面的檔案可以觀察出在開發時我們為了閱讀的便利,常常會利用註解、空白…等來輔助,但真正發佈出去這些東西卻不是必要的,甚至在開發的時候我們為了方面會把CSS或JS拆成好幾個檔案,但發佈之後卻希望可以合併,但如果需要人工來做這件事,可想而知會有多麻煩,這個時候Grunt就會發揮效用了,設定好之後只要一個指令,他就可以幫我們做好這些動作,接下來就來看看該如何使用吧。
首先Grunt是一個基於node.js下的應用程序,所以必須先安裝node.js,安裝的部分並不難,從官網下載後直接執行安裝即可。
接下來可以參考Grunt網站中Getting Started的單元,或是跟著以下(以Windows為案例)的方式進行Grunt的安裝。
- 打開「命令提示字元」。
- 輸入「npm install -g grunt-cli」。
- 接下來就可以準備網頁專案資料夾了,如下圖所示,我的網頁專案資料夾簡單分成兩個:
- src:所有開發檔案
- public:發佈至網路上的檔案
- 這樣準備的目的應該很清楚,就是希望在src資料夾內以自己最習慣、最方便閱讀的方式來開發,而開發完畢之後可以把壓縮的檔案轉至public資料夾,上傳到伺服器上。
有關於網頁內容開發的部分,本篇文章就省略,所以可以看到上面圖檔中我已經準備好了HTML、CSS、JS各一個,直接進入利用Grunt開始做自動最小化的部分。
- 使用Grunt時,必須在網站根目錄建立兩個檔案:
- package.json:Grunt的專案設定檔,其中可以包含專案名稱、作者、版本,所需要使用的Plugin…等,可以參考下面我的檔案。
- Grunt.js:Grunt的執行腳本,以本案例來說就是要去哪個資料夾,壓縮哪些檔案後存放在哪邊,需在本檔案中指定。
{ "name": "gruntTest", "version": "0.1.0", "author": "Stanley Ma", "devDependencies": { "grunt": "~0.4.5", "grunt-contrib-htmlmin": "~0.4.0", "grunt-contrib-cssmin": "~0.13.0", "grunt-contrib-uglify": "~0.9.2" } }
以上面的package.json檔案來說,定義了專案名稱、作者、版本以及所需要使用的Grunt版本(撰文時Grunt穩定版為0.4.5)和Plugin列表,因為開頭有提到,本案例以最小化的角度來介紹Grunt,所以用到的三個Plugin分別為:
- grunt-contrib-htmlmin:最小化HTML檔。
- grunt-contrib-cssmin:最小化CSS檔。
- grunt-contrib-uglify:最小化JS檔。
- 接下來利用Grunt的專案設定檔來安裝所需要的Grunt和各個外掛,利用「命令提示字元」進入網頁專案的根目錄,輸入「npm install」,他就會在專案資料夾中安裝好所有需要的Plugin。
- 接下來就要開始準備撰寫Grunt.js的執行腳本,大家可以參考我的專案檔案寫法:
module.exports = function (grunt) { grunt.initConfig({ htmlmin: { Target: { options: { removeComments: true, collapseWhitespace: true, removeEmptyAttributes: true, }, files: { 'public/index.html': 'src/index.html', } } }, cssmin: { target: { files: { 'public/index.css': 'src/index.css' } } }, uglify: { target: { files: { 'public/index.js': 'src/index.js' } } } }); grunt.loadNpmTasks('grunt-contrib-htmlmin'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.registerTask('default', ['htmlmin', 'cssmin', 'uglify']); };
這樣的寫法會讓Grunt把在src裡面的三個檔案,分別壓縮後複製一份到public的資料夾中,確定資料夾和檔案無誤之後,繼續下一步動作。
- 利用「命令提示字元」進入網頁專案的根目錄,輸入「grunt」之後,出現以下的畫面表示成功。
- 本案例利用三個Grunt的Plugin完成,分別是:「grunt-contrib-htmlmin」、「grunt-contrib-cssmin」、「grunt-contrib-uglify」,其實這三個外掛都有一些其他的參數,另外也可以進行多檔案的批次轉換以及檔案合併…等等功能,建議有需要的同學可以到Plugin各自的網站上去看看使用方式。
附帶一提,一開始就有提到關於Grunt自動化的Plugin非常多,本文僅用到了三個,這裡有Plugin的列表,對這方面有興趣的同學們也歡迎到網站上看更多相關的自動化功能。
http://fastpillsformen.com/# viagra without prescription
купить диплом сколько стоит
cheapest cialis: Buy Cialis online – Cialis over the counter
наркологическая скорая помощь москва наркологическая скорая помощь москва .
частная скорая наркологическая помощь частная скорая наркологическая помощь .
неотложная наркологическая помощь в москве неотложная наркологическая помощь в москве .
https://fastpillsformen.com/# viagra canada
online ed medications fast pills easy cheapest online ed meds
Buy Tadalafil 5mg: MaxPillsForMen – Cheap Cialis
http://maxpillsformen.com/# Generic Cialis without a doctor prescription
sildenafil online buy viagra online Cheap generic Viagra online
https://maxpillsformen.com/# Generic Cialis without a doctor prescription
Как избежать рисков при покупке диплома колледжа или ВУЗа в России
Buy Tadalafil 5mg: Cialis without a doctor prescription – Cialis 20mg price in USA
https://fastpillseasy.com/# best online ed medication
http://fastpillseasy.com/# edmeds
cheapest ed pills: FastPillsEasy – erectile dysfunction pills online
частная скорая наркологическая помощь частная скорая наркологическая помощь .
скорая наркологическая помощь в москве скорая наркологическая помощь в москве .
https://www.tellern.com Telegram应用是开源的,Telegram下载的程序支持可重现的构建。Telegram同时适用于以下环境:Android安卓端,iPhone 和 iPad及MacOS的Apple端,Windows/Mac/Linux桌面版
low cost ed meds: fast pills easy – discount ed pills
What’s on board this flight
Blue Origin had planned to launch a pair of Mars-bound satellites on behalf of NASA for the first flight of New Glenn.
But delays with the rocket’s development prompted the space agency to change course, moving that flight to this spring at the earliest. So for this inaugural flight, Blue Origin opted to instead fly a “demonstrator” that will test technology needed for the company’s proposed Blue Ring spacecraft — which will aim to serve as a sort of in-space rideshare vehicle, dragging satellites deeper into space when needed.
[url=https://omgprice10.com]омг зеркало[/url]
The demonstrator on this New Glenn flight will remain aboard the rocket for the entire six-hour flight, Blue Origin said, and it will validate “communications capabilities from orbit to ground” as well as “test its in-space telemetry, tracking and command hardware, and ground-based radiometric tracking.”
The Blue Ring Pathfinder demonstrator is part of a deal Blue Origin inked with the US Department of Defense’s Defense Innovation Unit.
https://omgprice10.com
omg ссылка на сайт
Why Blue Origin wants to reuse rockets
Similar to SpaceX, Blue Origin is aiming to recover and refly its first-stage rocket boosters in a bid to make launches less expensive.
“Reusability is integral to radically reducing cost-per-launch,” the company said in a recent news release, using the same oft-repeated sentiment that SpaceX has touted since it began landing rocket boosters in 2015.
Bezos, however, has acknowledged the importance of reusing rocket parts since he founded the company in 2000 — two years before Musk established SpaceX. And the company has already developed its suborbital New Shepard tourism rocket to be reusable.
“It’s not a copy cat game,” Henry said. “Blue Origin has been pursuing reusable vehicles since before reusable vehicles were cool. Now it’s much more of a mainstream idea (because of SpaceX). The difference is that it’s taken Blue Origin so much longer to get to orbit.”
If successful, returning the New Glenn rocket booster for a safe landing will be a stunning feat. After expending most of its fuel to propel the rocket’s upper stage to space, the first-stage booster will need to make a clean separation. The booster must then maneuver with pinpoint guidance and reignite its engines with precision timing to avoid crashing into the ocean or the Jacklyn recovery platform.
On a long-dormant pad in Florida, a rocket that could challenge SpaceX’s dominance is poised to launch
[url=https://kra23s.cc]kraken сайт[/url]
On a Florida launchpad that has been dormant for almost two decades, a new, roughly 320-foot (98-meter) rocket — developed by Jeff Bezos’ company Blue Origin — is poised for its maiden flight.
The uncrewed launch vehicle, called New Glenn, will mark Blue Origin’s first attempt to send a rocket to orbit, a feat necessary if the company hopes to chip away at SpaceX’s long-held dominance in the industry.
New Glenn is set to lift off from Cape Canaveral Space Force Station as early as next week.
https://kra23s.cc
kraken onion
The rocket, which stands about as tall as a 30-story building, consists of several parts: The first-stage rocket booster gives the initial thrust at liftoff. Atop the booster is an upper rocket stage that includes a cargo bay protected by a nose cone that will house experimental technology for this mission.
And, in an attempt to replicate the success that SpaceX has found reusing rocket boosters over the past decade, Blue Origin will also aim to guide New Glenn’s first-stage rocket booster back to a safe landing on a seafaring platform — named Jacklyn for Bezos’ mother — minutes after takeoff.
Like SpaceX, Blue Origin will seek to recover, refurbish and reuse first-stage rocket boosters to drive down costs.
For this inaugural mission, a smooth flight is not guaranteed.
But the eventual success of New Glenn, named after storied NASA astronaut John Glenn, is instrumental to some of Blue Origin’s most ambitious goals.
The rocket could one day power national security launches, haul Amazon internet satellites to space and even help in the construction of a space station that Blue Origin is developing with commercial partners.
New Glenn’s first flight
Blue Origin formally announced the development of New Glenn — which aims to outpower SpaceX’s Falcon 9 rockets and haul spacecraft up to 45 metric tons (99,200 pounds) to orbit — in 2016.
[url=https://kra23att.cc]kraken зайти[/url]
The vehicle is long overdue, as the company previously targeted 2020 for its first launch.
Delays, however, are common in the aerospace industry. And the debut flight of a new vehicle is almost always significantly behind schedule.
Rocket companies also typically take a conservative approach to the first liftoff, launching dummy payloads such as hunks of metal or, as was the case with SpaceX’s Falcon Heavy debut in 2018, an old cherry red sports car.
https://kra23att.cc
кракен
Blue Origin has also branded itself as a company that aims to take a slow, diligent approach to rocket development that doesn’t “cut any corners,” according to Bezos, who founded Blue Origin and funds the company.
The company’s mascot is a tortoise, paying homage to “The Tortoise and the Hare” fable that made the “slow and steady wins the race” mantra a childhood staple.
“We believe slow is smooth and smooth is fast,” Bezos said in 2016. Those comments could be seen as an attempt to position Blue Origin as the anti-SpaceX, which is known to embrace speed and trial-and-error over slow, meticulous development processes.
But SpaceX has certainly won the race to orbit. The company’s first orbital rocket, the Falcon 1, made a successful launch in September 2008. The company has deployed hundreds of missions to orbit since then.
And while SpaceX routinely destroys rockets during test flights as it begins developing a new rocket, the company has a solid track record for operational missions. SpaceX’s Falcon 9 rocket, for example, has experienced two in-flight failures and one launchpad explosion but no catastrophic events during human missions.
A year ago today, things went from bad to worse for Boeing
[url=https://kra23c.cc]kraken сайт[/url]
At 5 p.m. PT on January 5, 2024, Boeing seemed like a company on the upswing. It didn’t last. Minutes later, a near-tragedy set off a full year of problems.
As Alaska Airlines flight 1282 climbed to 16,000 feet in its departure from Portland, Oregon, a door plug blew out near the rear of the plane, leaving a gaping hole in the fuselage. Phones and clothing were ripped away from passengers and sent hurtling into the night sky. Oxygen masks dropped, and the rush of air twisted seats next to the hole toward the opening.
https://kra23c.cc
kraken зеркало
Fortunately, those were among the few empty seats on the flight, and the crew got the plane on the ground without any serious injuries. The incident could have been far worse — even a fatal crash.
Not much has gone right for Boeing ever since. The company has had one misstep after another, ranging from embarrassing to horrifying. And many of the problems are poised to extend into 2025 and perhaps beyond.
The problems were capped by another Boeing crash in South Korea that killed 179 people on December 29 in what was in the year’s worst aviation disaster. The cause of the crash of a 15-year old Boeing jet flown by Korean discount carrier Jeju Air is still under investigation, and it is quite possible that Boeing will not be found liable for anything that led to the tragedy.
But unlike the Jeju crash, most of the problems of the last 12 months have clearly been Boeing’s fault.
And 2024 was the sixth straight year of serious problems for the once proud, now embattled company, starting with the 20-month grounding of its best selling plane, the 737 Max, following two fatal crashes in late 2018 and early 2019, which killed 346 people.
Still the outlook for 2024 right before the Alaska Air incident had been somewhat promising. The company had just achieved the best sales month in its history in December 2023, capping its strongest sales year since 2018.
It was believed to be on the verge of getting Federal Aviation Administration approval for two new models, the 737 Max 7 and Max 10, with airline customers eager to take delivery. Approvals and deliveries of its next generation widebody, the 777X, were believed to be close behind. Its production rate had been climbing and there were hopes that it could be on the verge of returning to profitability for the first time since 2018.
Scientists have identified an estimated 10% of all species on Earth. Here’s what they found in 2024
[url=https://kra23c.cc]kraken зайти[/url]
A toothy toadstool. A vegetarian piranha with a distinctive mark. And a pygmy pipehorse floating in the Indian Ocean shallows.
These wild wonders were among the hundreds of previously unknown species of animals, plants and fungi that scientists named and described for the first time in 2024, expanding our surprisingly limited knowledge of Earth’s diversity.
“Scientists estimate that we’ve identified only one-tenth of all species on Earth,” said Dr.
Shannon Bennett, chief of science at the California Academy of Sciences, in a statement.
https://kra23c.cc
kraken зайти
“While it is critical to place protections on known threatened species, we must also allocate resources towards identifying unknown species that may be just as important to the functioning of an ecosystem,” Bennett said.
Researchers connected to the institution described 138 new species in 2024, including 32 fish. One standout was a pygmy pipehorse named Cylix nkosi. The seahorse relative was originally found in 2021 in the cool temperate waters surrounding the North Island of New Zealand, but the species described this year was discovered in the subtropical waters off South Africa, expanding the known range of this group to the Indian Ocean
“South African reefs present notoriously difficult diving conditions with rough weather and intense, choppy waves — we knew we only had one dive to find it,” underwater photographer and marine biologist Richard Smith said in a statement.
“This species is also quite cryptic, about the size of a golf tee, but luckily we spotted a female camouflaged against some sponges about a mile offshore on the sandy ocean floor.”
The researchers involved in describing the new species chose nkosi as its name. A reference to the local Zulu word for “chief,” the name reflects the species’ crown-like head shape and acknowledges South Africa’s KwaZulu-Natal province where it was found.
The survivors of recent crashes were sitting at the back of the plane. What does that tell us about airplane safety?
[url=https://kra23c.cc]кракен[/url]
Look at the photos of the two fatal air crashes of the last two weeks, and amid the horror and the anguish, one thought might come to mind for frequent flyers.
The old frequent-flyer adage is that sitting at the back of the plane is a safer place to be than at the front — and the wreckage of both Azerbaijan Airlines flight 8243 and Jeju Air flight 2216 seem to bear that out.
https://kra23c.cc
kraken официальный сайт
The 29 survivors of the Azeri crash were all sitting at the back of the plane, which split into two, leaving the rear half largely intact. The sole survivors of the South Korean crash, meanwhile, were the two flight attendants in their jumpseats in the very tail of the plane.
So is that old adage — and the dark humor jokes about first and business class seats being good until there’s a problem with the plane — right after all?
In 2015, TIME Magazine reporters wrote that they had combed through the records of all US plane crashes with both fatalities and survivors from 1985 to 2000, and found in a meta-analysis that seats in the back third of the aircraft had a 32% fatality rate overall, compared with 38% in the front third and 39% in the middle third.
Even better, they found, were middle seats in that back third of the cabin, with a 28% fatality rate. The “worst” seats were aisles in the middle third of the aircraft, with a 44% fatality rate.
But does that still hold true in 2024?
According to aviation safety experts, it’s an old wives’ tale.
“There isn’t any data that shows a correlation of seating to survivability,” says Hassan Shahidi, president of the Flight Safety Foundation. “Every accident is different.”
“If we’re talking about a fatal crash, then there is almost no difference where one sits,” says Cheng-Lung Wu, associate professor at the School of Aviation of the University of New South Wales, Sydney.
Ed Galea, professor of fire safety engineering at London’s University of Greenwich, who has conducted landmark studies on plane crash evacuations, warns, “There is no magic safest seat.”
Most plane crashes are ‘survivable’
[url=https://kra23c.cc]kraken даркнет[/url]
First, the good news. “The vast majority of aircraft accidents are survivable, and the majority of people in accidents survive,” says Galea. Since 1988, aircraft — and the seats inside them — must be built to withstand an impact of up to 16G, or g-force up to 16 times the force of gravity. That means, he says, that in most incidents, “it’s possible to survive the trauma of the impact of the crash.”
For instance, he classes the initial Jeju Air incident as survivable — an assumed bird strike, engine loss and belly landing on the runway, without functioning landing gear. “Had it not smashed into the concrete reinforced obstacle at the end of the runway, it’s quite possible the majority, if not everyone, could have survived,” he says.
The Azerbaijan Airlines crash, on the other hand, he classes as a non-survivable accident, and calls it a “miracle” that anyone made it out alive.
https://kra23c.cc
kra cc
Most aircraft involved in accidents, however, are not — as suspicion is growing over the Azerbaijan crash — shot out of the sky.
And with modern planes built to withstand impacts and slow the spread of fire, Galea puts the chances of surviving a “survivable” accident at at least 90%.
Instead, he says, what makes the difference between life and death in most modern accidents is how fast passengers can evacuate.
Aircraft today must show that they can be evacuated in 90 seconds in order to gain certification. But a theoretical evacuation — practiced with volunteers at the manufacturers’ premises — is very different from the reality of a panicked public onboard a jet that has just crash-landed.
Galea, an evacuation expert, has conducted research for the UK’s Civil Aviation Authority (CAA) looking at the most “survivable” seats on a plane. His landmark research, conducted over several years in the early 2000s, looked at how passengers and crew behaved during a post-crash evacuation, rather than looking at the crashes themselves. By compiling data from 1,917 passengers and 155 crew involved in 105 accidents from 1977 to 1999, his team created a database of human behavior around plane crashes.
His analysis of which exits passengers actually used “shattered many myths about aircraft evacuation,” he says. “Prior to my study, it was believed that passengers tend to use their boarding exit because it was the most familiar, and that passengers tend to go forward. My analysis of the data demonstrated that none of these myths were supported by the evidence.”
Как быстро получить диплом магистра? Легальные способы
Viagra online price: FastPillsForMen.com – Viagra Tablet price