-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
config.ts
45 lines (43 loc) · 1.41 KB
/
config.ts
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
import TsConfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import loadConfig from 'next/dist/next-server/server/config';
import { offsetFromRoot } from '@nrwl/workspace';
import * as path from 'path';
import * as withCSS from '@zeit/next-css';
import * as withLESS from '@zeit/next-less';
import * as withSASS from '@zeit/next-sass';
import * as withSTYLUS from '@zeit/next-stylus';
function createWebpackConfig(root: string) {
return function webpackConfig(config, { defaultLoaders }) {
const mainFields = ['es2015', 'module', 'main'];
const extensions = ['.ts', '.tsx', '.mjs', '.js', '.jsx'];
config.resolve.plugins = [
new TsConfigPathsPlugin({
configFile: path.resolve(root, 'tsconfig.json'),
extensions,
mainFields
})
];
config.module.rules.push({
test: /\.tsx/,
use: [defaultLoaders.babel]
});
return config;
};
}
export function prepareConfig(
workspaceRoot: string,
root: string,
outputPath: string,
phase: string
) {
const absoluteRoot = path.resolve(workspaceRoot, root);
const config = withSTYLUS(
withSASS(withLESS(withCSS(loadConfig(phase, root, null))))
);
config.distDir = `${offsetFromRoot(root)}${outputPath}`;
config.outdir = `${offsetFromRoot(root)}${outputPath}`;
const userWebpack = config.webpack;
config.webpack = (a, b) =>
createWebpackConfig(absoluteRoot)(userWebpack(a, b), b);
return config;
}