Prepare and create the library.yml file for Drupal
View the Project on GitHub ducks-project/drupal-librarify-webpack-plugin
Prepare and create the library.yml file for Drupal.
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.
| Name | Type | Default | Description |
| :———————————: | :——————: | :——————————————————————————————————————————: | :———————————————————————————————————————— |
| version | {Boolean\|String} | undefined | Include version in library.yaml assertion |
| header | {Boolean} | false | Indicate 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} | auto | Global css minified options. |
| js | {Object} | {} | In order to override js options for your library. |
| **[css](#css)** | {Object} | {} | In order to override css options for your library. |
| **[dependencies](#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](#weight)** | {Number} | undefined` | Adjusts order relative to other assets. Discouraged for JS |
versionType: 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',
}),
],
};
headerType: 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,
}),
],
};
prefixType: String|Function
Default: drupal.
Prefix your library name.
Stringwebpack.config.js
module.exports = {
plugins: [
new DrupalLibrarifyPlugin({
prefix: 'custom.',
}),
],
};
Functionwebpack.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}.`;
},
}),
],
};
minifiedType: Boolean\|String
Default: auto
Global css minified options.
Booleanwebpack.config.js
module.exports = {
plugins: [
new DrupalLibrarifyPlugin({
minified: false,
}),
],
};
Stringwebpack.config.js
module.exports = {
plugins: [
new DrupalLibrarifyPlugin({
minified: 'auto',
}),
],
};
jsType: 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,
},
},
}),
],
};
cssType: 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,
},
},
}),
],
};
dependenciesType: 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
Arraymodule.exports = {
plugins: [
new DrupalLibrarifyPlugin({
dependencies: ['core/drupal.form'],
}),
],
};
Objectmodule.exports = {
plugins: [
new DrupalLibrarifyPlugin({
dependencies: {
'core/jquery.once': false,
'core/drupal.form': true,
},
}),
],
};
weightType: Number
Default: undefined
Adjusts order relative to other assets. Discouraged for JS.
webpack.config.js
module.exports = {
plugins: [
new DrupalLibrarifyPlugin({
weight: -10,
}),
],
};
entriesType: 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',
},
},
}),
],
};
Please take a moment to read our contributing guidelines if you haven’t yet done so.