Добавление симлинков для импортов (#56)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -23,3 +23,5 @@
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
tsconfig.dev.json
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
const aliases = require('./scripts/create-symlinks/config.json');
|
||||
|
||||
// For a detailed explanation regarding each configuration property, visit:
|
||||
// https://jestjs.io/docs/en/configuration.html
|
||||
|
||||
@ -79,19 +81,10 @@ module.exports = {
|
||||
// ],
|
||||
|
||||
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
||||
moduleNameMapper: {
|
||||
'^_api(.*)$': '<rootDir>/src/core/api$1',
|
||||
'^_blocks(.*)$': '<rootDir>/src/core/blocks$1',
|
||||
'^_consts(.*)$': '<rootDir>/src/core/consts$1',
|
||||
'^_hooks(.*)$': '<rootDir>/src/core/hooks$1',
|
||||
'^_hoks(.*)$': '<rootDir>/src/core/hoks$1',
|
||||
'^_services(.*)$': '<rootDir>/src/core/services$1',
|
||||
'^_types(.*)$': '<rootDir>/src/core/types$1',
|
||||
'^_utils(.*)$': '<rootDir>/src/core/utils$1',
|
||||
'^_enums(.*)$': '<rootDir>/src/core/enums$1',
|
||||
'^_referers(.*)$': '<rootDir>/src/core/referers$1',
|
||||
'^_pages(.*)$': '<rootDir>/src/pages$1',
|
||||
},
|
||||
moduleNameMapper: Object.entries(aliases).reduce((acc, [key, aliasPath]) => ({
|
||||
...acc,
|
||||
[`^${key}(.*)$`]: `<rootDir>/${aliasPath}$1`,
|
||||
}), {}),
|
||||
|
||||
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
||||
// modulePathIgnorePatterns: [],
|
||||
|
||||
@ -22,8 +22,9 @@
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"symlinks": "node scripts/create-symlinks/index",
|
||||
"start": "webpack serve",
|
||||
"init": "npm run clean && npm i",
|
||||
"init": "npm run clean && npm i && npm run symlinks",
|
||||
"dev": "webpack serve --open false",
|
||||
"build": "webpack --mode=production",
|
||||
"eslint": "eslint -c .eslintrc.json src --fix",
|
||||
|
||||
14
scripts/create-symlinks/config.json
Normal file
14
scripts/create-symlinks/config.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"_api": "src/core/api",
|
||||
"_blocks": "src/core/blocks",
|
||||
"_consts": "src/core/consts",
|
||||
"_hooks": "src/core/hooks",
|
||||
"_hoks": "src/core/hoks",
|
||||
"_services": "src/core/services",
|
||||
"_types": "src/core/types",
|
||||
"_utils": "src/core/utils",
|
||||
"_infrastructure": "src/core/infrastructure",
|
||||
"_enums": "src/core/enums",
|
||||
"_referers": "src/core/referers",
|
||||
"_pages": "src/pages"
|
||||
}
|
||||
50
scripts/create-symlinks/index.js
Normal file
50
scripts/create-symlinks/index.js
Normal file
@ -0,0 +1,50 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const aliases = require('./config.json');
|
||||
const tsconfig = require('../../tsconfig.json');
|
||||
|
||||
const CURRENT_FOLDER = process.cwd();
|
||||
|
||||
function createTsConfigDev() {
|
||||
const tsConfigDev = {
|
||||
...tsconfig,
|
||||
compilerOptions: {
|
||||
...tsconfig.compilerOptions,
|
||||
paths: Object.entries(aliases).reduce((acc, [key, value]) => ({
|
||||
...acc,
|
||||
[`${key}/*`]: [`./${value}/*`],
|
||||
}), {}),
|
||||
}
|
||||
};
|
||||
fs.writeFileSync(path.resolve('tsconfig.dev.json'), JSON.stringify(tsConfigDev, null, 4));
|
||||
}
|
||||
|
||||
function createSymlinks() {
|
||||
if (!fs.existsSync('./node_modules')) {
|
||||
fs.mkdirSync('node_modules');
|
||||
}
|
||||
|
||||
try {
|
||||
for (const alias in aliases) {
|
||||
const folder = aliases[alias];
|
||||
const pathInPackage = path.resolve(CURRENT_FOLDER, folder);
|
||||
if (!fs.existsSync(folder)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const symlinkPath = path.resolve(`./node_modules/${alias}`);
|
||||
if (fs.existsSync(symlinkPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fs.symlinkSync(pathInPackage, symlinkPath);
|
||||
console.info(`${symlinkPath} --> ${pathInPackage}`);
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.info(`${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
createSymlinks();
|
||||
createTsConfigDev();
|
||||
@ -1,10 +1,9 @@
|
||||
const configurator = require("ts-prune/lib/configurator");
|
||||
const runner = require("ts-prune/lib/runner");
|
||||
const {ignore} = require('./ignore-files');
|
||||
|
||||
const error = [];
|
||||
|
||||
runner.run(configurator.getConfig(), (text) => {
|
||||
runner.run({ project: 'tsconfig.dev.json' }, (text) => {
|
||||
if (ignore.every(ign => !text.includes(ign))) {
|
||||
error.push(text);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import {makeApi} from '_utils/makeApi';
|
||||
import {http} from '../infrastructure/Http';
|
||||
import {http} from '_infrastructure/Http';
|
||||
|
||||
type User = {
|
||||
id: number;
|
||||
|
||||
@ -20,21 +20,8 @@
|
||||
"noEmit": false,
|
||||
"jsx": "react",
|
||||
"paths": {
|
||||
"_api/*": ["./src/core/api/*"],
|
||||
"_blocks/*": ["./src/core/blocks/*"],
|
||||
"_consts/*": ["./src/core/consts/*"],
|
||||
"_hooks/*": ["./src/core/hooks/*"],
|
||||
"_hoks/*": ["./src/core/hoks/*"],
|
||||
"_services/*": ["./src/core/services/*"],
|
||||
"_types/*": ["./src/core/types/*"],
|
||||
"_utils/*": ["./src/core/utils/*"],
|
||||
"_enums/*": ["./src/core/enums/*"],
|
||||
"_referers/*": ["./src/core/referers/*"],
|
||||
"_pages/*": ["./src/pages/*"],
|
||||
"*": ["*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx"
|
||||
]
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx"]
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const webpack = require('webpack');
|
||||
const aliases = require('./scripts/create-symlinks/config.json');
|
||||
|
||||
module.exports = {
|
||||
mode: 'development',
|
||||
@ -28,19 +29,10 @@ module.exports = {
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
alias: {
|
||||
_types: path.resolve(__dirname, 'src/core/types/'),
|
||||
_api: path.resolve(__dirname, 'src/core/api/'),
|
||||
_blocks: path.resolve(__dirname, 'src/core/blocks/'),
|
||||
_consts: path.resolve(__dirname, 'src/core/consts/'),
|
||||
_hooks: path.resolve(__dirname, 'src/core/hooks/'),
|
||||
_hoks: path.resolve(__dirname, 'src/core/hoks/'),
|
||||
_services: path.resolve(__dirname, 'src/core/services/'),
|
||||
_utils: path.resolve(__dirname, 'src/core/utils/'),
|
||||
_enums: path.resolve(__dirname, 'src/core/enums/'),
|
||||
_referers: path.resolve(__dirname, 'src/core/referers/'),
|
||||
_pages: path.resolve(__dirname, 'src/pages/'),
|
||||
}
|
||||
alias: Object.entries(aliases).reduce((acc, [key, aliasPath]) => ({
|
||||
...acc,
|
||||
[key]: path.resolve(__dirname, `${aliasPath}/`),
|
||||
}), {}),
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: {
|
||||
|
||||
Reference in New Issue
Block a user