1 | 'use strict';
|
2 |
|
3 |
|
4 | var path = require('path');
|
5 | var arrify = require('arrify');
|
6 | var assign = require('object-assign');
|
7 | var formatter = require('stylelint').formatters.string;
|
8 |
|
9 |
|
10 | var runCompilation = require('./lib/run-compilation');
|
11 |
|
12 | function apply(options, compiler) {
|
13 | options = options || {};
|
14 | var context = options.context || compiler.context;
|
15 |
|
16 | options = assign({
|
17 | configFile: '.stylelintrc',
|
18 | formatter: formatter,
|
19 | quiet: false
|
20 | }, options, {
|
21 |
|
22 |
|
23 | files: arrify(options.files || '**/*.s?(c|a)ss').map(function (file) {
|
24 | return path.join(context, '/', file);
|
25 | }),
|
26 | context: context
|
27 | });
|
28 |
|
29 | var runner = runCompilation.bind(this, options);
|
30 |
|
31 | compiler.plugin('run', runner);
|
32 | compiler.plugin('watch-run', function onWatchRun(watcher, callback) {
|
33 | runner(watcher.compiler, callback);
|
34 | });
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | module.exports = function stylelintWebpackPlugin(options) {
|
44 | return {
|
45 | apply: apply.bind(this, options)
|
46 | };
|
47 | };
|