Getting Started

Webpack is used to compile JavaScript modules. Once installed, you can interface with webpack either from its CLI or API. If you're still new to webpack, please look at:


Using Smart Elements with Webpack

For the purpose of the tutorial, we will create a web page with a Smart.Button web component.

  |- package.json
+ |- webpack.config.js
  |- /dist
    |- index.html
  |- /src
    |- index.js
    |- /source
       |- /smart.elements.js
       |- /styles
          |- /smart.default.css
          |- /font
          |- /images

As you can see from the project structure, we place the smart scripts and CSS files which we want to use within the /src/source folder.

const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist')

    "name": "webpack-demo",
    "version": "1.0.0",
    "description": "",
    "scripts": {
       "build": "webpack"
    "keywords": [],
    "author": "",
    "license": "ISC",
    "devDependencies": {
      "webpack": "^4.20.2",
      "webpack-cli": "^3.1.2"
    "dependencies": {
      "lodash": "^4.17.5"

 <!doctype html>  
   <title>Getting Started</title>  
   <link rel="stylesheet" href="../src/source/styles/smart.default.css">  
   <script src="main.js"></script>  

import './source/smart.elements.js';

const button = document.createElement('smart-button');

button.innerHTML = 'Click Me';


Install and Run Webpack

1. Run the npm install command to install the required node modules. (When installing a package that will be bundled into your production bundle, you should use npm install --save. If you're installing a package for development purposes (e.g. a linter, testing libraries, etc.) then you should use npm install --save-dev.)
2. Now the npm run build command can be used. Note that within scripts we can reference locally installed npm packages by name.


webpack getting started with web components