Add as dev dependency for any pk-
module.
-
From within your
pk-
module project, add both awebpack-dev.js
and awebpack-prod.js
file. These will handle both dev environments. -
Inside your
package.json
, add them as executablenpm
scripts:
package.json
...
"scripts": {
"dev": "node webpack-dev.js",
"prod": "node webpack-prod.js"
},
- Following the syntax below, add these into your executable
webpack-x.js
files:
webpack-dev.js
...
const pkWebpack = require('pk-webpack');
const path = require('path');
const appRoot = path.resolve(__dirname, '../');
const config = {
'mode': 'development'
};
pkWebpack(appRoot, config);
This initializes Webpack with the proper dev environment, and passes along the root of the project for proper "build" context. In other words, it gives Webpack knowledge of where to look for, and compile assets. "mode" could either be development
or production
, depending on the context and the file that you're in. This gets merged with Webpack's standard configuration object, so you can pass other parameters here as well.
-
pk-webpack
will look inside yoursrc
folder for javascript, and sass files withinjs
, andscss
folders respectively. Following best practices, the entry points are/src/js/site.js
and/src/scss/site.scss
. -
pk-webpack
will build these files into your/public
directory asalways.css
andalways.js
files, that yourpk-
module must push in afterConstruct.
Running npm run dev
from within your pk-
module will start Webpack in watch
mode.
Running npm run prod
will simply run Webpack once to build the files