UNPKG

build-plugin-ignore-style

Version:

plugin for ignore style

52 lines 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var getStyleRule = function (libraryName, style) { if (style === void 0) { style = 'style'; } return "".concat(libraryName, "/(es|lib)/[-\\w+]+/(").concat(style, "|").concat(style, ".js|").concat(style, "/index.js)$"); }; var flattenId = function (id) { return id.replace(/(\s*>\s*)/g, '__').replace(/[/.]/g, '_'); }; var plugin = function (_a, options) { var onGetWebpackConfig = _a.onGetWebpackConfig, modifyUserConfig = _a.modifyUserConfig, log = _a.log, context = _a.context; var userConfig = context.userConfig; if (!options) { log.warn('config options to make build-plugin-ignore-style work properly'); } else { var libraryConfigs = Array.isArray(options) ? options : [options]; // default rule for external style var externalRule_1 = libraryConfigs.map(function (value) { var _a = value, libraryName = _a.libraryName, _b = _a.style, style = _b === void 0 ? 'style' : _b, rule = _a.rule; return rule !== null && rule !== void 0 ? rule : getStyleRule(libraryName, style); }).join('|'); onGetWebpackConfig(function (config) { config.module .rule('ignore-style') .test(new RegExp(externalRule_1)) .before('jsx') .use('null-loader').loader(require.resolve('./null-loader')); }); if (userConfig.vite) { modifyUserConfig('vite', { plugins: [ { name: 'vite-ignore-style', enforce: 'pre', resolveId: function (id) { // vite will flattenId when pre build dependencies if (id.match(new RegExp(flattenId(externalRule_1))) || id.match(new RegExp(externalRule_1))) { return '@null-module'; } }, load: function (id) { if (id === '@null-module') { return ''; } }, } ], }, { deepmerge: true }); } } }; exports.default = plugin; //# sourceMappingURL=index.js.map