-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathgetCompiler.js
More file actions
47 lines (43 loc) · 1.14 KB
/
getCompiler.js
File metadata and controls
47 lines (43 loc) · 1.14 KB
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
import path from "node:path";
import { Volume, createFsFromVolume } from "memfs";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import webpack from "webpack";
/**
* @param {import("webpack").Configuration} config Webpack configuration
* @returns {import("webpack").Compiler} Webpack compiler
*/
export default function getCompiler(config = {}) {
const compiler = webpack({
mode: "development",
devtool: config.devtool || false,
context: path.resolve(__dirname, "../fixtures"),
optimization: {
minimize: false,
},
output: {
pathinfo: false,
path: path.resolve(__dirname, "../outputs"),
filename: "[name].js",
chunkFilename: "[id].[name].js",
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].[name].css",
}),
],
module: {
rules: [
{
test: /.s?css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
],
},
...config,
});
if (!config.outputFileSystem) {
compiler.outputFileSystem = createFsFromVolume(new Volume());
}
return compiler;
}