-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(webpack): moved config to @code-gear/config library
- Loading branch information
Showing
11 changed files
with
109 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,4 @@ | ||
{ | ||
"extends": ["../../.eslintrc.js"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
"ignorePatterns": ["!**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
} | ||
], | ||
"compilerOptions": { | ||
"esModuleInterop": true | ||
"esModuleInterop": true, | ||
"resolveJsonModule": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,6 @@ | ||
const { composePlugins, withNx } = require('@nx/webpack') | ||
const path = require('path') | ||
const tsconfig = require('cg-config/src/tsconfig/paths/second-layer.json') | ||
const { buildWebpackConfig } = require('cg-config/src/webpack') | ||
|
||
module.exports = composePlugins( | ||
withNx({ | ||
skipTypeChecking: true | ||
}), | ||
(config) => { | ||
config.resolve.alias = { | ||
'@': path.resolve(__dirname, 'src'), | ||
...Object.fromEntries( | ||
Object.entries(tsconfig.compilerOptions.paths).map( | ||
([name, tsconfigPath]) => { | ||
return [name, path.resolve(__dirname, tsconfigPath[0])] | ||
} | ||
) | ||
) | ||
} | ||
|
||
// This solution actually don't work. | ||
|
||
// config.resolve.plugins.push( | ||
// new TsconfigPathsPlugin({ | ||
// configFile: 'libs/config/src/tsconfig/paths/second-layer.json', | ||
// baseUrl: '.' | ||
// }) | ||
// ) | ||
|
||
return config | ||
} | ||
) | ||
module.exports = buildWebpackConfig({ | ||
rootDir: __dirname, | ||
layer: 'second' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,36 @@ | ||
import { resolveTsconfigPaths } from './resolvers' | ||
import { composePlugins, withNx } from '@nx/webpack' | ||
import { Configuration } from 'webpack' | ||
import { WebpackConfigOptions, BuildWebpackConfigPayload } from './types' | ||
|
||
export const buildWebpackConfig = () | ||
/** | ||
* Combines your webpack config with nx modules and | ||
* custom tsconfig paths | ||
* @param rootDir {string} - root directory of current library | ||
* @param layer {BuildWebpackConfigPayload.layer} - nesting level of your library to include the | ||
* correct tsconfig paths depending on this | ||
*/ | ||
|
||
export const buildWebpackConfig = ({ | ||
rootDir, | ||
layer | ||
}: BuildWebpackConfigPayload) => { | ||
return composePlugins( | ||
withNx({ | ||
skipTypeChecking: true | ||
}), | ||
(config: Configuration) => { | ||
const options: WebpackConfigOptions = { | ||
layer, | ||
config, | ||
rootDir | ||
} | ||
|
||
config.resolve!.alias = { | ||
...resolveTsconfigPaths(options) | ||
} | ||
|
||
return config | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { buildWebpackConfig } from './build-webpack-config' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { resolveTsconfigPaths } from './tsconfig-paths' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { WebpackConfigOptions } from '../types' | ||
import { resolve } from 'path' | ||
import secondLayer from '../../tsconfig/paths/second-layer.json' | ||
import thirdLayer from '../../tsconfig/paths/third-layer.json' | ||
|
||
/** | ||
* adds tsconfig paths depending on the layer of your library | ||
* @param options {WebpackConfigOptions} - options from | ||
* buildWebpackConfig root function | ||
*/ | ||
|
||
export const resolveTsconfigPaths = ( | ||
options: WebpackConfigOptions | ||
): Record<string, string> => { | ||
const tsconfig = options.layer === 'second' ? secondLayer : thirdLayer | ||
|
||
// This solution actually don't work. | ||
|
||
// config.resolve.plugins.push( | ||
// new TsconfigPathsPlugin({ | ||
// configFile: 'libs/config/src/tsconfig/paths/second-layer.json', | ||
// baseUrl: '.' | ||
// }) | ||
// ) | ||
|
||
return { | ||
'@': resolve(options.rootDir, 'src'), | ||
...Object.fromEntries( | ||
Object.entries(tsconfig.compilerOptions.paths).map( | ||
([name, tsconfigPath]) => { | ||
return [name, resolve(options.rootDir, (tsconfigPath as [string])[0])] | ||
} | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Configuration } from 'webpack' | ||
|
||
export interface BuildWebpackConfigPayload { | ||
rootDir: string | ||
layer: 'second' | 'third' | ||
} | ||
|
||
export interface WebpackConfigOptions extends BuildWebpackConfigPayload { | ||
config: Configuration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters