UNPKG

7.53 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = getStyleRules;
7
8var _autoprefixer = _interopRequireDefault(require("autoprefixer"));
9
10var _path = _interopRequireDefault(require("path"));
11
12var _ramda = require("ramda");
13
14var _constants = require("./constants");
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
19
20function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
22const getCSSLoaders = ({
23 basePath
24}) => [{
25 loader: 'style-loader'
26}, {
27 loader: 'css-loader',
28 options: {}
29}, {
30 loader: 'postcss-loader',
31 options: {
32 plugins: [(0, _autoprefixer.default)()]
33 }
34}, {
35 loader: 'sass-loader',
36 options: {
37 outputStyle: 'expanded'
38 }
39}, {
40 loader: 'sass-resources-loader',
41 options: {
42 resources: [`${_path.default.join(_constants.ROOT_PATH, basePath)}/style/export.scss`]
43 }
44}];
45
46function getStyleRules({
47 basePath = 'src',
48 libraryInclude = (0, _ramda.always)(false),
49 libraryExclude = (0, _ramda.always)(false),
50 cssLoaderOptions = {}
51}) {
52 const absoluteBasePath = _path.default.join(_constants.ROOT_PATH, basePath);
53
54 const cssLoaders = getCSSLoaders({
55 basePath
56 });
57 return [// css modules (local styles)
58 {
59 test: /\.scss$/,
60 include: [absoluteBasePath, libraryInclude],
61 exclude: [/style\//g, libraryExclude],
62 use: cssLoaders.map(loader => {
63 if (loader.loader === 'css-loader') {
64 return _objectSpread({}, loader, {
65 options: _objectSpread({}, loader.options, {
66 modules: 'local',
67 camelCase: true
68 }, cssLoaderOptions)
69 });
70 }
71
72 return loader;
73 })
74 }, // global styles
75 {
76 test: /\.scss$/,
77 include: [absoluteBasePath],
78 exclude: /^((?!(style\/|node_modules\/)).)*$/,
79 use: cssLoaders
80 }, {
81 test: /\.css$/,
82 include: [/node_modules/],
83 use: cssLoaders.slice(0, -2)
84 }];
85}
86//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXNlL3Njc3MuanMiXSwibmFtZXMiOlsiZ2V0Q1NTTG9hZGVycyIsImJhc2VQYXRoIiwibG9hZGVyIiwib3B0aW9ucyIsInBsdWdpbnMiLCJvdXRwdXRTdHlsZSIsInJlc291cmNlcyIsInBhdGgiLCJqb2luIiwiUk9PVF9QQVRIIiwiZ2V0U3R5bGVSdWxlcyIsImxpYnJhcnlJbmNsdWRlIiwibGlicmFyeUV4Y2x1ZGUiLCJjc3NMb2FkZXJPcHRpb25zIiwiYWJzb2x1dGVCYXNlUGF0aCIsImNzc0xvYWRlcnMiLCJ0ZXN0IiwiaW5jbHVkZSIsImV4Y2x1ZGUiLCJ1c2UiLCJtYXAiLCJtb2R1bGVzIiwiY2FtZWxDYXNlIiwic2xpY2UiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7QUFBQTs7QUFDQTs7QUFDQTs7QUFFQTs7Ozs7Ozs7QUFHQSxNQUFNQSxhQUFhLEdBQUcsQ0FBQztBQUFFQyxFQUFBQTtBQUFGLENBQUQsS0FBa0IsQ0FDdEM7QUFBRUMsRUFBQUEsTUFBTSxFQUFFO0FBQVYsQ0FEc0MsRUFFdEM7QUFDRUEsRUFBQUEsTUFBTSxFQUFFLFlBRFY7QUFFRUMsRUFBQUEsT0FBTyxFQUFFO0FBRlgsQ0FGc0MsRUFNdEM7QUFDRUQsRUFBQUEsTUFBTSxFQUFFLGdCQURWO0FBRUVDL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gICAgIGV4Y2x1ZGU6IFsvc3R5bGVcXC8vZywgbGlicmFyeUV4Y2x1ZGVdLFxuICAgICAgdXNlOiBjc3NMb2FkZXJzLm1hcCgobG9hZGVyKSA9PiB7XG4gICAgICAgIGlmIChsb2FkZXIubG9hZGVyID09PSAnY3NzLWxvYWRlcicpIHtcbiAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgLi4ubG9hZGVyLFxuICAgICAgICAgICAgb3B0aW9uczoge1xuICAgICAgICAgICAgICAuLi5sb2FkZXIub3B0aW9ucyxcbiAgICAgICAgICAgICAgbW9kdWxlczogJ2xvY2FsJyxcbiAgICAgICAgICAgICAgY2FtZWxDYXNlOiB0cnVlLFxuICAgICAgICAgICAgICAuLi5jc3NMb2FkZXJPcHRpb25zLFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICB9O1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBsb2FkZXI7XG4gICAgICB9KSxcbiAgICB9LFxuICAgIC8vIGdsb2JhbCBzdHlsZXNcbiAgICB7XG4gICAgICB0ZXN0OiAvXFwuc2NzcyQvLFxuICAgICAgaW5jbHVkZTogW2Fic29sdXRlQmFzZVBhdGhdLFxuICAgICAgZXhjbHVkZTogL14oKD8hKHN0eWxlXFwvfG5vZGVfbW9kdWxlc1xcLykpLikqJC8sXG4gICAgICB1c2U6IGNzc0xvYWRlcnMsXG4gICAgfSxcbiAgICB7XG4gICAgICB0ZXN0OiAvXFwuY3NzJC8sXG4gICAgICBpbmNsdWRlOiBbL25vZGVfbW9kdWxlcy9dLFxuICAgICAgdXNlOiBjc3NMb2FkZXJzLnNsaWNlKDAsIC0yKSxcbiAgICB9LFxuICBdO1xufVxuIl19
\No newline at end of file