No matter what language was used to develop websites in the past, parent sets such as image optimization, JavaScript folding, connection, SCSS and coffeescript will be compiled into basic counterparts, and finally built Do a few words. Fortunately, build scripts such as gulp and Gront can replace these tedious tasks. What is needed is some settings and some command-line skills. This is the fifth post in a six episode series of WordPress for advanced developers. This series is a follow-up to the popular WordPress development for intermediate users, including details of theme development, theme customization preparation, plug-in construction, custom post types and classifications, query and circulation, custom fields and metadata, and localization. The
This tutorial will focus on how to make the most of gulp. How to delegate regular tasks to gulp to focus on more important tasks, such as actual coding. Note: PHP is the basic language of WordPress, a high-level theme for developers in this series, so you must have practical knowledge of PHP. In this series, see code snippets. Gulf install gulp is the abbreviation NPM of node package manager, which is easy to install. Node itself is a very popular and useful JavaScript runtime environment, including NPM. To get started, first install node using its convenient installer. The
To get started, first install the node on the default node site using a convenient installer. Then install gulp using the following code. That’s all! Notes on loading the summary 149e592a5bb2fc28839e2f2080e4c333 node and NPM software package NPM is a tool for installing gulp and other software packages. Most packages are installed locally. Can only be used in the folder of the project to which the package is added. NPM is a package that contains project metadata. Use a special file named JSON. Name, description, version, and most importantly, the package used. The
Therefore, the node project is very agile. No need to share all used packages or check in version control. Package Make sure JSON is available, and anyone can use the NPM install command to get all the prerequisites in seconds. Some software packages, such as gulp, can be installed globally. This is not necessary, but it is convenient for the tools we often use, especially the development tools. Package installation this tutorial installs several gulp related packages. The syntax for performing this operation is as follows: The
Load summary 149e592a5bb2fc28839e2f2080e4c333 names can be separated by spaces to install one or more packages– Save dev or -d means to save the package as a development dependency. They are placed in the package file for our use. The first example of a new project launch creates a word press theme. Now index. Create a new folder in the PHP theme directory with an index containing the appropriate information. PHP and style. You should know how to add CSS files, etc. In addition, package. Implement dependencies by adding JSON files. The
Let’s set everything up in the terminal. Load summary 149e592a5bb2fc28839e2f2080e4c333 execute this command one by one. Note the & & of the first command. This allows you to execute the second command. That is, create the directory on the first line and immediately switch to the directory. The NPM init command is package. Wizard for JSON files. A series of questions will be displayed, each
For questions, you can press enter to use the default values. The problem after NPM init command gulp must be installed locally for use in the project. The following command handles this: The
Load summary 149e592a5bb2fc28839e2f2080e4c333 after installing the first dependency, a new folder named node\u modules is displayed. This includes many packages (each package installed has multiple dependencies on itself). You do not need to add it to the repository. All you need is the package file. Male package The default gulp is essentially a task manager. Define the conditions under which a task must run, and then precisely define the tasks that a task must perform. For example, if you run gulp gulp optimization from the command line, gulp must find and optimize all images in the project. The
Gulp is not a magic solution for everything, but a framework. Therefore, you must tell us what conditions are and what we should do if the conditions are met. The gulpfile contains all the information gulp needs to perform the task. Use the JS file. Now, let’s create a gulpfile with minimal information. Load the first line of summary 149e592a5bb2fc28839e2f2080e4c333 to get gulp itself. \
To create a task from beginning to end, you must follow a simple checklist. Configure tasks by finding packages that can perform tasks, installing packages, adding to gulpfile, setting conditions, and corresponding options. Let’s follow the steps above in the first gudu gudu task to perform image optimization. But before that, take a screenshot on the subject. Let’s add a PNG image. Unsplash photos are used, and the recommended size of this file is 880 × Cut it to 660. Eventually 1 MB. A quick Google search found a gulp-imagemin package that can shrink PNG, GIF, and jpg images. Perfect! Installation and operation instructions are usually provided on site. To install this plug-in, use the following command: The
To add to the load summary 149e592a5bb2f28839e2f2080e4c333 gulpfile, it will be included directly below the initial inclusion of the gulp itself. The loading summary 149 e592a5bb2fc28839e2f2080e4c333 finally defines the conditions for running the task and tells gulp what to do. Here is the code for the new task \
Then, using the function \
Read the file target content and pass it to a function, or the pipeline occurs more than once in the operation. Each function gets, modifies, and passes the results of the previous function. Get the result stream and output it to the specified location. Another example is sass file processing. The following is how to apply the above algorithm when compiling all sass files, automatically adding vendor prefixes, and shrinking results: All. Pass the contents of the SCSS file lookup to the sass compiler, the result contents to the automatic prefix, and the results to the reducer, so that the transfer results can be saved in the same source file. Gulp allows this. Three packages are required. Gudu gudu gudu automatic prefix gudu gudu – cleaning -css use the following command to install at one time. After loading the summary 149e592a5bb2fc28839e2f2080e4c333, add it to the top gulpfile. Loading the summary 149e592a5bb2fc28839e2f2080e4c333 also requires adding sass to the topic. Style as the next content. Let’s create a sass file in the default directory named SCSS. Load summary 149e592a5bb2fc28839e2f2080e4c333 finally, you must create tasks to perform all necessary tasks. Here is the complete code with instructions. Load all SCSS files in the root directory of summary 149e592a5bb2fc28839e2f2080e4c333, pipe them into sass() function, and then pipe all contents into the default directory after autoprefixer and cleancss functions, style. Make SCSS output. Style CSS The result CSS is: Load summary 149e592a5bb2fc28839e2f2080e4c333 as you can see, everything has shrunk. The variable is replaced by this value, and the supplier prefix is added if necessary. To write this code, we navigate to each document, copy and paste the pipe section in the example. It’s really simple. The command can have several options worth investigating, but most work well by default. By giving the order to view the document, we have come all the way. Gulp can perform any task as long as it finds the correct package and adds it to the gulpfile. But you can do more. Especially when developing CSS, it is more inclined to save and modify. You must continue running the gulp CSS command. Gulp has an excellent monitoring mechanism that can detect changes to files and automatically execute commands. We can build it on anything we have already done. By default, new directives must be added. If the files in the specified collection change, do so. Start by installing gulp watch and adding it to the gulpfile. It has been implemented twice, so it is easy to do so. The new task is very simple. Our job is to set the files to be monitored. If one of the files matches, we will perform one of the existing operations. Load the summary 149e592a5bb2fc28839e2f2080e4c333 gulp watch CSS. After this operation, the terminal must display the contents shown in the following screenshot. Do not return the prompt \
Is the tutorial helpful? Why do you want to learn WordPress development? What else do you want to know? Please tell us the following comments. Label: development Gudong