webpack-genius
Version:
**For chinese developers:** you'd better add taobao mirror before everything start. Or you may fail to install. ```bash yarn config set registry http://registry.npm.taobao.org ```
73 lines (72 loc) • 2.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CssHandle = void 0;
var tslib_1 = require("tslib");
var RuleHandle_1 = require("./RuleHandle");
var cosmiconfig_1 = require("cosmiconfig");
var node_1 = require("browserslist/node");
var CssHandle = /** @class */ (function (_super) {
tslib_1.__extends(CssHandle, _super);
function CssHandle() {
return _super !== null && _super.apply(this, arguments) || this;
}
CssHandle.prototype.disableCssModules = function () {
this.setOptions('css-loader', function (options) {
options.modules = false;
});
return this;
};
CssHandle.prototype.addPostCssPlugin = function (plugin) {
this.setOptions('postcss-loader', function (options) {
var plugins = options.postcssOptions.plugins = options.postcssOptions.plugins || [];
plugins.push(plugin);
});
return this;
};
CssHandle.prototype.loaders = function () {
return [
{
loader: 'css-loader',
options: {
modules: {
// https://github.com/webpack-contrib/css-loader#localidentname
localIdentName: this.genius.isHot() ? '[path][name]__[local]' : '[hash:base64]',
},
esModule: false,
sourceMap: this.genius.isHot(),
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: this.genius.isHot(),
postcssOptions: {},
},
},
];
};
CssHandle.prototype.collect = function () {
var _this = this;
this.setOptions('postcss-loader', function (options) {
// should have browserslist configuration file.
// User didn't set plugins into loader directly.
if (!options.postcssOptions.plugins) {
var postcssConfigFile = cosmiconfig_1.cosmiconfigSync('postcss').search(process.cwd());
var browserslistConfig = node_1.findConfig(process.cwd());
// User didn't add postcss configuration file.
if (postcssConfigFile === null) {
if (browserslistConfig) {
options.postcssOptions.plugins = [require.resolve('autoprefixer')];
}
else {
// Just disable postcss-loader to against warning
_this.disableLoader('postcss-loader');
}
}
}
});
return _super.prototype.collect.call(this);
};
return CssHandle;
}(RuleHandle_1.RuleHandle));
exports.CssHandle = CssHandle;