{"id":318461,"date":"2021-12-31T13:07:22","date_gmt":"2021-12-31T13:07:22","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=318461"},"modified":"2021-12-31T13:07:25","modified_gmt":"2021-12-31T13:07:25","slug":"adding-npm-package-to-the-administration-or-storefront-in-shopware6","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/","title":{"rendered":"Adding NPM package to the Administration or Storefront in Shopware6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>In this blog, we will discuss how to add a custom NPM package to the Administration or Storefront.  If you are working on a plugin and you need to write a custom Javascript plugin. For this approach, we can add a custom NPM package to our plugin directory.  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding a npm package to the Administration or the Storefront<\/h2>\n\n\n\n<p>Now we add a custom NPM package to the Administration or Storefront. assume you have installed NPM, run <code>npm init -y<\/code> it in the plugin directory <code>&lt;plugin root&gt;src\/Resources\/app\/administration\/<\/code> or the <code>&lt;plugin root&gt;src\/Resources\/app\/storefront\/<\/code> directory. This commands creates a <code>package.json<\/code> file in the respective folder. To add a package to the <code>package.json<\/code> file simply run the <code>npm install<\/code> command and your desired package will be installed in your node_module folder. In this example, we will be installing <a href=\"https:\/\/www.npmjs.com\/package\/missionlog\" target=\"_blank\" rel=\"noreferrer noopener\">missionlog<\/a> package in our plugin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Registering a package in the build system<\/h2>\n\n\n\n<p>Shopware&#8217;s Storefront, as well as Administration, is based on the build system Webpack. Webpack is a source file bundler: In essence, it bundles all the source files into a single <code>bundle.js<\/code> to be shipped to a browser. To make Webpack know of the new dependency. We have to register it and give it an alias so that the package can be bundled correctly.<\/p>\n\n\n\n<p>To do this we create a new folder called &#8220;build&#8221; under either <code>Resources\/app\/storefront<\/code> or <code>Resources\/app\/administration<\/code>. In this build folder, we create a new file with the name <code>webpack.config.js<\/code>. We thereby make it possible to extend the Webpack configuration of Shopware.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">const { join, resolve } = require(&#039;path&#039;); \nmodule.exports = () =&gt; { \n    return { \n        resolve: { \n           alias: { \n               &#039;@missionlog&#039;: resolve( \n                    join(__dirname, &#039;..&#039;, &#039;node_modules&#039;, &#039;missionlog&#039;) \n               ) \n           } \n       } \n   }; \n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Using the dependency<\/h2>\n\n\n\n<p>Once we have installed all the dependencies and registered the package in the build system with an alias, we can use the package in our own code.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">import Plugin from &#039;src\/plugin-system\/plugin.class&#039;;\n\n\/\/ Import logger\nimport { log } from &#039;@missionlog&#039;;\n\n\/\/ Initializing the logger\nlog.init({ initializer: &#039;INFO&#039; }, (level, tag, msg, params) =&gt; {\n    console.log(`${level}: &#091;${tag}] `, msg, ...params);\n});\n\n\/\/ The plugin skeleton\nexport default class ExamplePlugin extends Plugin {\n    init() {\n        console.log(&#039;init&#039;);\n\n        \/\/ Use logger\n        log.info(&#039;initializer&#039;, &#039;example plugin got started&#039;, this);\n    }\n}<\/pre>\n\n\n\n<p>Now you can see the log info in the browser console of the custom Javascript plugin in your Storefront.<\/p>\n\n\n\n<p><a href=\"https:\/\/webkul.com\/blog\/shopware-multi-seller-marketplace\/\" target=\"_blank\" rel=\"noreferrer noopener\">Multi-Seller Marketplace Plugin<\/a><\/p>\n\n\n\n<p>Thanks for reading this blog, I hope it will help you. Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview In this blog, we will discuss how to add a custom NPM package to the Administration or Storefront. If you are working on a plugin and you need to write a custom Javascript plugin. For this approach, we can add a custom NPM package to our plugin directory. Adding a npm package to the <a href=\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":325,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-318461","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Adding NPM package to the Administration or Storefront in Shopware6<\/title>\n<meta name=\"description\" content=\"Adding NPM package to the Administration or Storefront in Shopware6 | How to add NPM package to the custom Plugins.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding NPM package to the Administration or Storefront in Shopware6\" \/>\n<meta property=\"og:description\" content=\"Adding NPM package to the Administration or Storefront in Shopware6 | How to add NPM package to the custom Plugins.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-31T13:07:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-31T13:07:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prince Gupta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prince Gupta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/\"},\"author\":{\"name\":\"Prince Gupta\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd\"},\"headline\":\"Adding NPM package to the Administration or Storefront in Shopware6\",\"datePublished\":\"2021-12-31T13:07:22+00:00\",\"dateModified\":\"2021-12-31T13:07:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/\"},\"wordCount\":310,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/\",\"url\":\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/\",\"name\":\"Adding NPM package to the Administration or Storefront in Shopware6\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2021-12-31T13:07:22+00:00\",\"dateModified\":\"2021-12-31T13:07:25+00:00\",\"description\":\"Adding NPM package to the Administration or Storefront in Shopware6 | How to add NPM package to the custom Plugins.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Adding NPM package to the Administration or Storefront in Shopware6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd\",\"name\":\"Prince Gupta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Prince Gupta\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/princegupta-wp031\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adding NPM package to the Administration or Storefront in Shopware6","description":"Adding NPM package to the Administration or Storefront in Shopware6 | How to add NPM package to the custom Plugins.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/","og_locale":"en_US","og_type":"article","og_title":"Adding NPM package to the Administration or Storefront in Shopware6","og_description":"Adding NPM package to the Administration or Storefront in Shopware6 | How to add NPM package to the custom Plugins.","og_url":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2021-12-31T13:07:22+00:00","article_modified_time":"2021-12-31T13:07:25+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Prince Gupta","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Prince Gupta","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/"},"author":{"name":"Prince Gupta","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd"},"headline":"Adding NPM package to the Administration or Storefront in Shopware6","datePublished":"2021-12-31T13:07:22+00:00","dateModified":"2021-12-31T13:07:25+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/"},"wordCount":310,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/","url":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/","name":"Adding NPM package to the Administration or Storefront in Shopware6","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2021-12-31T13:07:22+00:00","dateModified":"2021-12-31T13:07:25+00:00","description":"Adding NPM package to the Administration or Storefront in Shopware6 | How to add NPM package to the custom Plugins.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/adding-npm-package-to-the-administration-or-storefront-in-shopware6\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Adding NPM package to the Administration or Storefront in Shopware6"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/669b7c5067f73a7ae2204ff4aca829fd","name":"Prince Gupta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd55a986709c72a714a8135a38f3b2cba1009ea371caec823a8547b2e01df18d?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Prince Gupta"},"url":"https:\/\/webkul.com\/blog\/author\/princegupta-wp031\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/318461","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/325"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=318461"}],"version-history":[{"count":1,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/318461\/revisions"}],"predecessor-version":[{"id":318546,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/318461\/revisions\/318546"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=318461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=318461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=318461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}