1.1.7 • Published 6 years ago

stylable-webpack-plugin v1.1.7

Weekly downloads
22
License
BSD-3-Clause
Repository
github
Last release
6 years ago

Stylable Webpack Plugin

The Stylable Webpack Plugin (for Webpack version 4x) is the main build utility for Stylable. It supports both development and production modes, providing various configurations that can be tweaked according to your specific needs. It enables loading Stylable files (.st.css) from local projects or imported from a 3rd party source (for example, NPM node modules).

Getting started

Install stylable-webpack-plugin as a dev dependency in your local project.

Install using npm:

npm install stylable-webpack-plugin --save-dev

Install using yarn:

yarn add stylable-webpack-plugin --dev

Sample dev config:

// webpack.config.js
module.exports = {
  …
  plugins: [new StylableWebpackPlugin()]
  …
};

Plugin Configuration Options

Some of the default values given to configuration parameters depend on what environment mode is currently active in webpack (development or production). Below you can see the various possible configuration parameters and their default values.

OptionTypeDevelopment Mode DefaultProduction Mode DefaultDescription
outputCSSbooleanfalsetrueGenerate CSS asset files per bundle
filenamestring-name.bundle.cssThe name of the CSS bundle file when outputCSS is enabled
includeCSSInJSbooleantruefalseInclude target CSS in the JavaScript modules (used by runtime renderer)
createRuntimeChunkbooleanfalsefalseMove all Stylable modules into a separate chunk with a runtime renderer
rootScopebooleantruetrueEnable automatically scoping the root component (will default to false in the upcoming future)
bootstrap.autoInitbooleantruetrueInitialize the rendering of the CSS in the browser
optimize.removeUnusedComponentsbooleantruetrueRemove selectors that contain namespaces (classes) that are not imported by JavaScript
optimize.removeCommentsbooleanfalsetrueRemove CSS comments from the target
optimize.removeStylableDirectivesbooleantruetrueRemove all -st-* from target (currently also removes empty rules which will be a separate option coming soon)
optimize.classNameOptimizationsbooleanfalsetrueShorten all class names and replace them in the JavaScript modules
optimize.shortNamespacesbooleanfalsetrueShorten all namespaces which affects the resulting data-* selectors and DOM attributes
optimize.minifybooleanfalsetrueMinify each css asset.

Sample production configuration

new StylableWebpackPlugin({ 
    outputCSS: true, 
    includeCSSInJS: false,
    optimize: {
      removeUnusedComponents: true,
      removeComments: true,
      removeStylableDirectives: true,
      classNameOptimizations: true,
      shortNamespaces: true,
      minify: true
    }
})

Asset handling

CSS assets are handled by a url-loader + file-loader combination.

 module: {
    rules: [
      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: "url-loader",
            options: {
              limit: 8192
            }
          }
        ]
      }
    ]
  }

Compatibilities with existing loading mechanisms

If you're using css_loader/extract make sure to exclude .st.css files from the process. You cannot use loaders with Stylable .st.css files

How it works (in case you're wondering)

The plugin transforms all Stylable files into JavaScript modules with CSS rendering capabilities.

Every bundle that contains Stylable modules is injected with a stylable-bootstrap-module as its entrypoint. This module is responsible for:

  • Ensuring that all of the transformed modules are imported in the proper order.
  • Initializing the runtime DOM renderer.

The resulting renderer orders the CSS by the depth of each module, calculated from its dependencies and component dependencies.

Stylable bootstrap module The stylable-bootstrap-module is a generated module injected into the bundle as its entrypoint and ensures all Stylable modules are injected into the runtime renderer.

Runtime DOM renderer The core Stylable runtime renderer in the browser is responsible for rendering stylesheets in the correct order in the DOM.

1.1.7

6 years ago

1.1.6

6 years ago

1.1.6-rc.1

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago