-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcompiler.js
64 lines (57 loc) · 1.45 KB
/
compiler.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
57
58
59
60
61
62
63
64
// @ts-check
import webpack from 'webpack';
import { fileURLToPath } from 'node:url';
import { resolve, join, dirname } from 'node:path';
import { createFsFromVolume, Volume } from 'memfs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const FIXTURES_DIR = join(__dirname, '..', '..', '..', 'test', '😁-FIXTURES');
/**
* @param {object} fixture
* @param {import('../../packages/lit-css-loader/lit-css-loader').LitCSSOptions} [options={}]
*/
export const compiler = ({
input: path,
test = /\.css$/,
alias,
options = {},
}) => {
const compiler = webpack({
mode: 'development',
context: FIXTURES_DIR,
entry: `./${path}`,
output: {
path: resolve(__dirname),
filename: 'bundle.js',
},
externals: {
'lit': 'lit',
'@microsoft/fast-element': 'fast',
'snoot': 'snoot',
},
optimization: {
minimize: false,
},
...!!alias && { resolve: { alias } },
module: {
rules: [
{
test,
loader: 'lit-css-loader',
options,
},
],
},
});
compiler.outputFileSystem = createFsFromVolume(new Volume());
compiler.outputFileSystem.join = (...args) => join(...args);
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err)
return reject(err);
else if (stats.hasErrors())
return reject(stats.toJson().errors);
else
return resolve(stats);
});
});
};