rollup-plugin-block
v1.0.6
Published
Ensure certain files don't become part of the build.
Downloads
6
Maintainers
Readme
rollup-plugin-block
Ensure certain files don't become part of the build.
Why?
Sometimes you want to have separate builds for dev and production. You might use the replace
plugin to conditionally import certain files. This plugin lets you make sure that a file that is meant for one build isn't accidentally compiled into another.
Example
In this example if the __DEV_MODE__
check was missing, the non-dev build would fail because it would contain "debug-logger.devonly.js". With the __DEV_MODE__
check "debug-logger.devonly.js" would be omitted from the build by rollup given it's unused.
main.js
import { debugLogger } from './debug-logger.devonly.js';
if (__DEV_MODE__) {
debugLogger.log('In dev mode.');
}
debug-logger.devonly.js
export const debugLogger = {
log: msg => console.log(msg)
};
rollup.config.js
import rollupPluginBlock from 'rollup-plugin-block';
import replace from 'rollup-plugin-replace';
export default {
input: 'main.js',
plugins: [
replace({
__DEV_MODE__: JSON.stringify(!!process.env.DEV_BUILD)
}),
rollupPluginBlock({
blockPattern: '.devonly.'
})
]
};
Installation
npm install --save-dev rollup-plugin-block
Usage
import { rollup } from 'rollup';
import rollupPluginBlock from 'rollup-plugin-block';
export default {
input: 'main.js',
plugins: [
rollupPluginBlock({
blockPattern: '.devonly.' // or regex
})
]
});