1.0.1 • Published 7 years ago
@bb-cli/lib-build-plugin-helpers v1.0.1
lib-build-plugin-helpers
Helper functions for writing build plugins for bb-cli
Usage
- Install library
npm install --global @bb-cli/lib-build-plugin-helpers
Create a build plugin that adds a loader
const { createPlugin, addLoader } = require('@bb-cli/lib-build-plugin-helpers');
module.exports = createPlugin(
addLoader({ test: /\.css$/, loaders: [ 'css-loader' ])
);
Add loader modules
Note: the css-loader shown above is supported by default by the BB-CLI tools, but other loaders like the sass loader are not. To add all the loaders required by your plugin, provide the full paths to the loader directories:
const loaderBasedir = loader => path.dirname(require.resolve(`${loader}/package.json`));
const { createPlugin, addLoaderModules } = require('@bb-cli/lib-build-plugin-helpers');
module.exports = createPlugin(
addLoaderModules(
[
'style-loader',
'css-loader',
'sass-loader',
].map(loaderBasedir)
)
);
Chaining rules
You can pass as many rules as you like to createPlugin.
const { createPlugin, addLoader, addLoaderModules } = require('@bb-cli/lib-build-plugin-helpers');
const path = require('path');
const loaderBasedir = loader => path.dirname(require.resolve(`${loader}/package.json`));
module.exports = createPlugin(
addLoader({
test: /\.(scss|sass)$/,
loaders: [
'style-loader',
'css-loader?sourceMap&minimize',
'sass-loader?sourceMap',
],
}),
// Provide full path to the loader modules
addLoaderModules(
[
'style-loader',
'css-loader',
'sass-loader',
].map(loaderBasedir)
)
);
1.0.1
7 years ago