1.0.25 • Published 3 years ago

drupal-librarify-webpack-plugin v1.0.25

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

npm node deps tests cover chat size

drupal-librarify-webpack-plugin

Prepare and create the library.yml file for Drupal.

Getting Started

To begin, you'll need to install drupal-librarify-webpack-plugin:

$ npm install drupal-librarify-webpack-plugin --save-dev

Then add the plugin to your webpack config. For example:

webpack.config.js

const DrupalLibrarifyPlugin = require('drupal-librarify-webpack-plugin');

module.exports = {
  plugins: [new DrupalLibrarifyPlugin()],
};

And run webpack via your preferred method.

Options

NameTypeDefaultDescription
version{Boolean\|String}undefinedInclude version in library.yaml assertion
header{Boolean}falseIndicate that the JavaScript assets in that asset library are in the 'critical path' and should be loaded from the header
prefix{String\|Function}drupal.Prefix your libary name
minified{String\|Boolean}autoGlobal css minified options.
js{Object}{}In order to override js options for your library.`
css{Object}{}In order to override css options for your library.
dependencies{Array\|Object}{ 'core/jquery': true, 'core/jquery.once': true, 'core/drupal': true, 'core/drupal.form': false, 'core/drupalSettings': true }Manually specify the dependencies for your library
weight{Number}undefinedAdjusts order relative to other assets. Discouraged for JS

version

Type: Boolean\|String Default: undefined

Include version in library.yaml. If true, then it will "guess" the version in the package.json file.

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      version: '1.0.0',
    }),
  ],
};

header

Type: Boolean Default: false

Indicate that the JavaScript assets in that asset library are in the 'critical path' and should be loaded from the header.

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      header: true,
    }),
  ],
};

prefix

Type: String|Function Default: drupal.

Prefix your library name.

String

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      prefix: 'custom.',
    }),
  ],
};

Function

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      prefix(info) {
        // info.file is the original asset filename
        // info.path is the path of the original asset
        // info.query is the query
        return `${info.path}.${info.query}.`;
      },
    }),
  ],
};

minified

Type: Boolean\|String Default: auto

Global css minified options.

Boolean

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      minified: false,
    }),
  ],
};

String

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      minified: 'auto',
    }),
  ],
};

js

Type: Object Default: {}

In order to override js options for your library.

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      js: {
        'my/library/path/filename.js': {
          preprocess: false,
        },
      },
    }),
  ],
};

css

Type: Object Default: {}

In order to override css options for your library.

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      css: {
        'my/library/path/filename.css': {
          minified: true,
        },
      },
    }),
  ],
};

dependencies

Type: Array\|Object Default: { 'core/jquery': true, 'core/jquery.once': true, 'core/drupal': true, 'core/drupal.form': false, 'core/drupalSettings': true }

In order to override css options for your library.

webpack.config.js

Array

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      dependencies: ['core/drupal.form'],
    }),
  ],
};

Object

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      dependencies: {
        'core/jquery.once': false,
        'core/drupal.form': true,
      },
    }),
  ],
};

weight

Type: Number Default: undefined

Adjusts order relative to other assets. Discouraged for JS.

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      weight: -10,
    }),
  ],
};

entries

Type: Object Default: {}

In order to override entries options for your library.

webpack.config.js

module.exports = {
  plugins: [
    new DrupalLibrarifyPlugin({
      entries: {
        mySublibraryModule: {
          version: '2.0.0',
        },
      },
    }),
  ],
};

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT

1.0.19

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.9

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago