1 | 'use strict';
|
2 |
|
3 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
4 |
|
5 | var ExtractTextPlugin = _interopDefault(require('extract-text-webpack-plugin'));
|
6 |
|
7 | var HandleCSSLoader = function HandleCSSLoader(ref) {
|
8 | if ( ref === void 0 ) ref = {};
|
9 | var fallbackLoader = ref.fallbackLoader; if ( fallbackLoader === void 0 ) fallbackLoader = 'style-loader';
|
10 | var cssLoader = ref.cssLoader; if ( cssLoader === void 0 ) cssLoader = 'css-loader';
|
11 | var postcss = ref.postcss;
|
12 | var sourceMap = ref.sourceMap;
|
13 | var extract = ref.extract;
|
14 | var minimize = ref.minimize;
|
15 | var cssModules = ref.cssModules;
|
16 |
|
17 | this.fallbackLoader = fallbackLoader;
|
18 | this.cssLoader = cssLoader;
|
19 | this.postcssOptions = postcss;
|
20 | this.sourceMap = sourceMap;
|
21 | this.extract = extract;
|
22 | this.minimize = minimize;
|
23 | this.cssModules = cssModules;
|
24 | };
|
25 |
|
26 | HandleCSSLoader.prototype.getLoader = function getLoader (test, loader, options) {
|
27 | if ( options === void 0 ) options = {};
|
28 |
|
29 | var cssLoaderOptions = {
|
30 | autoprefixer: false,
|
31 | sourceMap: this.sourceMap,
|
32 | minimize: this.minimize
|
33 | };
|
34 |
|
35 | if (this.cssModules) {
|
36 | cssLoaderOptions.modules = true;
|
37 | cssLoaderOptions.importLoaders = 1;
|
38 | cssLoaderOptions.localIdentName = '[name]_[local]__[hash:base64:5]';
|
39 | }
|
40 |
|
41 | if (loader === 'css-loader') {
|
42 | Object.assign(cssLoaderOptions, options);
|
43 | }
|
44 |
|
45 | var use = [{
|
46 | loader: this.cssLoader,
|
47 | options: cssLoaderOptions
|
48 | }];
|
49 |
|
50 | if (loader !== 'postcss-loader' && this.postcssOptions !== false) {
|
51 | use.push({
|
52 | loader: 'postcss-loader',
|
53 | options: Object.assign({}, this.postcssOptions,
|
54 | {sourceMap: this.sourceMap})
|
55 | });
|
56 | }
|
57 |
|
58 | if (loader && loader !== 'css-loader') {
|
59 | use.push({
|
60 | loader: loader,
|
61 | options: Object.assign({}, options,
|
62 | {sourceMap: this.sourceMap})
|
63 | });
|
64 | }
|
65 |
|
66 | return {
|
67 | test: test,
|
68 | use: this.extract ? ExtractTextPlugin.extract({
|
69 | use: use,
|
70 | fallback: this.fallbackLoader
|
71 | }) : use
|
72 | }
|
73 | };
|
74 |
|
75 | HandleCSSLoader.prototype.css = function css (options) {
|
76 | return this.getLoader(/\.css$/, 'css-loader', options)
|
77 | };
|
78 |
|
79 | HandleCSSLoader.prototype.sass = function sass (options) {
|
80 | if ( options === void 0 ) options = {};
|
81 |
|
82 | return this.getLoader(/\.sass$/, 'sass-loader', Object.assign({}, {indentedSyntax: true},
|
83 | options))
|
84 | };
|
85 |
|
86 | HandleCSSLoader.prototype.scss = function scss (options) {
|
87 | return this.getLoader(/\.scss$/, 'sass-loader', options)
|
88 | };
|
89 |
|
90 | HandleCSSLoader.prototype.less = function less (options) {
|
91 | return this.getLoader(/\.less$/, 'less-loader', options)
|
92 | };
|
93 |
|
94 | HandleCSSLoader.prototype.stylus = function stylus (options) {
|
95 | return this.getLoader(/\.stylus$/, 'stylue-loader', options)
|
96 | };
|
97 |
|
98 | HandleCSSLoader.prototype.styl = function styl (options) {
|
99 | return this.getLoader(/\.styl$/, 'stylue-loader', options)
|
100 | };
|
101 |
|
102 | module.exports = HandleCSSLoader;
|