forked from webpack-contrib/mini-css-extract-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetCompiler.js
61 lines (53 loc) · 1.5 KB
/
getCompiler.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
import path from 'path';
import webpack from 'webpack';
import { createFsFromVolume, Volume } from 'memfs';
import MiniCssExtractPlugin from '../../src';
export default (fixture, loaderOptions = {}, config = {}) => {
const { outputFileSystem, ...cnfg } = config;
const fullConfig = {
mode: 'development',
devtool: cnfg.devtool || false,
context: path.resolve(__dirname, '../fixtures'),
entry: path.resolve(__dirname, '../fixtures', fixture),
output: {
path: path.resolve(__dirname, '../outputs'),
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
},
module: {
rules: [
{
test: /\.css$/i,
rules: [
{
loader: MiniCssExtractPlugin.loader,
options: loaderOptions || {},
},
{
loader: 'css-loader',
},
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: '[name].css',
chunkFilename: '[id].css',
}),
],
...cnfg,
};
const compiler = webpack(fullConfig);
if (!outputFileSystem) {
const outputFS = createFsFromVolume(new Volume());
// Todo remove when we drop webpack@4 support
outputFS.join = path.join.bind(path);
compiler.outputFileSystem = outputFS;
} else {
compiler.outputFileSystem = outputFileSystem;
}
return compiler;
};