Skip to content

Commit bd9c835

Browse files
committed
feat: add webpack watch support for postcss files
1 parent 0249aad commit bd9c835

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const getBody = require('./lib/get-body');
77
const getPostcssSources = require('./lib/get-postcss-sources');
88
const processPostcss = require('./lib/process-postcss');
99
const fixTemplate = require('./lib/fix-template');
10+
const fullPaths = require('./lib/full-paths');
1011

1112
module.exports = function (source) {
1213
const cb = this.async();
@@ -21,6 +22,8 @@ module.exports = function (source) {
2122
const body = getBody(parsed);
2223
const sourcesFilePath = getPostcssSources(body);
2324

25+
fullPaths(sourcesFilePath, this.resourcePath).forEach(this.addDependency);
26+
2427
postcssrc()
2528
.then(config => processPostcss(sourcesFilePath, htmlFilePath, config))
2629
.then(postcssRes => cb(null, fixTemplate(postcssRes, source)))

src/lib/full-paths.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const fullPath = require('./full-path');
2+
3+
module.exports = (fps, rp) => fps.map(fp => fullPath(fp, rp));

test/units/full-paths.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {join} from 'path';
2+
import test from 'ava';
3+
import fullPaths from '../../src/lib/full-paths';
4+
5+
test('fullPaths()', t => {
6+
t.deepEqual(
7+
fullPaths(['test.postcss', 'test2.postcss'], 'my/dir/file.html'),
8+
[join('my', 'dir', 'test.postcss'), join('my', 'dir', 'test2.postcss')],
9+
'should return the full paths of a sources array based on the path of the resource file'
10+
);
11+
});

0 commit comments

Comments
 (0)