-
-
Notifications
You must be signed in to change notification settings - Fork 608
/
Copy pathgetCompiler.js
64 lines (58 loc) · 1.63 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
62
63
64
import path from 'path';
import webpack from 'webpack';
import { createFsFromVolume, Volume } from 'memfs';
export default (fixture, loaderOptions = {}, config = {}) => {
const fullConfig = {
mode: 'development',
devtool: config.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',
publicPath: '/webpack/public/path/',
},
module: {
rules: [
{
test: /\.css$/i,
use: [
{
loader: path.resolve(__dirname, '../../src'),
options: loaderOptions || {},
},
],
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'file-loader',
options: { name: '[name].[ext]' },
},
],
},
resolve: {
alias: {
aliasesImg: path.resolve(__dirname, '../fixtures/url'),
aliasesImport: path.resolve(__dirname, '../fixtures/import'),
aliasesComposes: path.resolve(
__dirname,
'../fixtures/modules/composes'
),
},
},
optimization: {
minimize: false,
},
plugins: [],
...config,
};
const compiler = webpack(fullConfig);
if (!config.outputFileSystem) {
const outputFileSystem = createFsFromVolume(new Volume());
// Todo remove when we drop webpack@4 support
outputFileSystem.join = path.join.bind(path);
compiler.outputFileSystem = outputFileSystem;
}
return compiler;
};