-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrollup-plugin-postcss.js
56 lines (43 loc) · 1.09 KB
/
rollup-plugin-postcss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
const path = require('path');
const webpack = require('webpack');
const MemoryFS = require('memory-fs');
const postcss = require.resolve('postcss');
module.exports = () => ({
name: 'rollup-plugin-postcss',
load(id) {
if (id !== postcss) {
return null;
}
const memfs = new MemoryFS();
const compiler = webpack({
entry: 'postcss',
output: {
path: __dirname,
filename: 'postcss.js',
library: 'postcss',
libraryTarget: 'commonjs2',
},
});
// Write files to memory, not disk
compiler.outputFileSystem = memfs;
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err || stats.hasErrors()) {
if (err) {
return reject(err);
}
const info = stats.toJson();
return reject(info.errors);
}
return resolve({
code: memfs.readFileSync(
path.join(__dirname, './postcss.js'),
'utf8'
),
// TODO: figure out source map
});
});
});
},
});