14.16.x LTS
.[unpacked path]/theme/tools/
:
cd theme/tools/
npm install --global npm@latest
npm install --global yarn
yarn upgrade
after every Metronic update is released in order to receive newly added or updated 3rd-party plugins.
npm cache clean --force
command, if the installation had failed at any step. Retry again from beginning once it's done.[unpacked path]/theme/tools/
folder.
yarn
Yarn
instead
NPM
for the Metronic dependencies setup.
Yarn
supports nested dependencies resolutions in
package.json
where spesific version of sub dependacies are required such as
resolutions: { "gulp-dart-sass/sass": "1.32.13" }
.dist/assets/
folder: State which demo to compile and append at the end of the command. Eg.
--demo1
package.json
file. This step is very important for Webpack in Metronic template. The default
package.json
works for Gulp. To make it work for Webpack, you have to modify
tools/package.json
and remove
"type": "module"
. Otherwise, it will cause compilation error when running the next command.
npm run build --demo1
gulp localhost
http://localhost:8080/demo1/dist/
. It will take a few seconds for the build to finish. To stop a localhost environment, press
Ctrl+C
.ReferenceError: require is not defined
. Check on the "Note on the
package.json
file" above.tools/webpack.config.js
and you can fully customize the build settings to meet your project requirements.SASS
JavaScriptfiles and automatically recompile whenever the source files are changed.
npm run watch
npm run localhost --demo1
--rtl
parameter to generate RTL version of required
CSS
files.
npm run build --rtl --demo1
--prod
to build assets for production with minified
CSS
and
JavaScript
files.
npm run build --prod --demo1
--css
to build only
CSS
files.
npm run build --css --demo1
--js
to build only
JavaScript
files.
npm run build --js --demo1
tools/webpack/plugins/plugins.js
bundle or in separate bundle. To create a separate bundle, check on these existing samples in
tools/webpack/plugins/custom/*
packages.json
yarn add [package name]
packages.json
yarn add [package name]
node_modules
folder.
require("[package]");
require("path/to/dist/package.js");
new Dropzone()
.
window.Dropzone = require("dropzone/dist/min/dropzone.min.js");
require("path/to/dist/package.css");
tools/webpack
folder.Path | Description |
---|---|
plugins
|
3rd party vendor's plugins from
node_modules . |
custom
|
This folder contains separate vendor's bundles. |
plugins.js
|
This is the global vendor includes which required for all pages. |
plugins.scss
|
This is the global vendor includes which required for all pages. |
custom
|
The theme's core plugins and scripts. |
theme/tools/webpack.config.js
for more details.
tools/webpack/
into your application. This folder contains the asset paths and plugin JS definition. For example, this file is for plugin CSS
tools/webpack/plugins/plugins.scss
// tools/webpack/plugins/plugins.scss
@import "~apexcharts/dist/apexcharts.css";
@import "~@/src/plugins/formvalidation/dist/css/formValidation.css";
@import "~bootstrap-daterangepicker/daterangepicker.css";
// ....
tools/webpack/plugins/plugins.js
.
// tools/webpack/plugins/plugins.js
window.jQuery = window.$ = require('jquery');
window.bootstrap = require('bootstrap');
window.Popper = require('@popperjs/core');
// ....
function getEntryFiles() {
const entries = {
// 3rd party plugins css/js
'plugins/global/plugins.bundle': ['./webpack/plugins/plugins.js', './webpack/plugins/plugins.scss'],
// Theme css/js
'css/style.bundle': ['./' + path.relative('./', srcPath) + '/sass/style.scss', './' + path.relative('./', srcPath) + '/sass/plugins.scss'],
'js/scripts.bundle': './webpack/scripts.' + demo + '.js',
};
// Custom 3rd party plugins
(glob.sync('./webpack/{plugins,js}/custom/**/*.+(js)') || []).forEach(file => {
let loc = file.replace('webpack/', '').replace('./', '');
loc = loc.replace('.js', '.bundle');
entries[loc] = file;
});
// Custom JS files from src folder
(glob.sync(path.relative('./', srcPath) + '/js/custom/**/!(_)*.js') || []).forEach(file => {
entries[file.replace(/.*js\/(.*?)\.js$/ig, 'js/$1')] = './' + file;
});
return entries;
}
srcPath
is an absolute path to your
src
folder. Eg.
C:\wamp64\www\keenthemes\_releases\metronic_html_v8.0.37\theme\demo1\src
These are the example output entry file paths to be passed into the Webpack
entry
configuration. The array
key
is the destination output and the
value
is the source file paths.
{
'plugins/global/plugins.bundle': [ './webpack/plugins/plugins.js', './webpack/plugins/plugins.scss' ],
'css/style.bundle': './..\demo1\src/sass/style.scss',
'js/scripts.bundle': './webpack/scripts.demo1.js',
'js/custom/modals/create-project.bundle': './webpack/js/custom/modals/create-project.js',
'js/custom/modals/offer-a-deal.bundle': './webpack/js/custom/modals/offer-a-deal.js',
'plugins/custom/ckeditor/ckeditor-balloon-block.bundle': './webpack/plugins/custom/ckeditor/ckeditor-balloon-block.js',
'plugins/custom/ckeditor/ckeditor-balloon.bundle': './webpack/plugins/custom/ckeditor/ckeditor-balloon.js',
// ....
}
Call the function above, to get the list of asset files. It should pass into the
entry
option in the
webpack.config.js
along with other Webpack configurations.
resolve.alias
is required for alias symbol
@
to point to the demo
src
folder. It's been used in the
theme/tools/webpack/
.
Read more information about the
resolve.alias
on the Webpack documentation
https://webpack.js.org/configuration/resolve/#resolvealias
{
// ....
entry: getEntryFiles(),
resolve: {
alias: {
jquery: path.join(__dirname, 'node_modules/jquery/src/jquery'),
$: path.join(__dirname, 'node_modules/jquery/src/jquery'),
'@': demoPath,
},
extensions: ['.js', '.scss'],
fallback: {
util: false,
},
},
// ....
}