
You are probably using other tools to do this, but it’s nice to have everything in one place. Note: If you get this error: ENOENT no such file or directory, scandir, you can fix it by running the command npm rebuild node-sass. The first way makes more sense if the CSS is related to the script. The second way is to add a new entry point in your config: //. Import datepicker from './js-datepicker.js' The first way is to directly import them in your JS: import './css/style.sass' But if you followed our setup above, it has extra packages to handle CSS or Sass. To do this, you need to quit the dev command, then run:īy default, Webpack only supports JS files. Before launching, you need to minify the code.Every time you save your JS, it will automatically re-compile. To start compiling, run the command below.
#How to run webpack for dev windows#
For Windows users, you might see an error saying unable to remove the directory.
#How to run webpack for dev code#
The code above assumes your theme’s structure looks like below. Uncomment this if you want to use CSS Live reload Path: path.resolve(_dirname, outputPath), 'app' is the output name, people commonly use 'bundle' change these variables to fit your project "presets": MiniCssExtractPlugin = require('mini-css-extract-plugin') Ĭonst BrowserSyncPlugin = require('browser-sync-webpack-plugin') "dev": "webpack -mode development -watch" Create package.json and files in your theme and paste in the code below:.In this tutorial, we will learn to do the first three of that list. Allow use of advanced syntaxes for your Vue or React code.Moreover, Webpack has many other utilities such as: This seems like a minor benefit but it will become more apparent when you have a lot of files. All the codes are now combined into one file: import datepicker from './js-datepicker.js' With Webpack, we can use import to embed the libraries inside app.js. In the old way, you would enqueue them separately resulting in this output: This is a feature that is quite a pain to do without Webpack.įor example, we have app.js that needs 2 libraries: js-datepicker.js and swiper.js. Webpack is a command-line tool to allow the use of JavaScript modules. So I will show you how useful it is for developing a theme.ĥ. You might think it is unnecessary and too complex. Does a WordPress developer need to know Webpack?
