export function buildBabelLoader({ mode }: TBuildOptions) {
const isDev = mode === 'development'
const isProd = mode === 'production'
const plugins = []
if (isProd) {
plugins.push([
removeDataTestIdBabelPlugin,
{
props: ['data-testid']
}
])
}
plugins.push(['babel-plugin-styled-components'])
return {
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-typescript',
[
'@babel/preset-react',
{
runtime: isDev ? 'automatic' : 'classic'
}
]
],
plugins: plugins.length ? plugins : undefined
}
}
}
}
export function buildPlugins(options: TBuildOptions): Configuration['plugins'] {
const { mode, paths, platform } = options
const isDev = mode === 'development'
const isProd = mode === 'production'
const plugins: Configuration['plugins'] = [
new HtmlWebpackPlugin({
template: paths.html,
favicon: path.resolve(paths.public, 'favicon.ico')
}),
new DefinePlugin({
__PLATFORM__: JSON.stringify(platform),
__ENV__: JSON.stringify(mode)
}),
new ForkTsCheckerWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: path.resolve(paths.base, '_redirects'),
to: path.resolve(paths.output)
}
]
})
]
if (isDev) {
plugins.push(new ReactRefreshWebpackPlugin())
plugins.push(new ESLintPlugin())
}
if (isProd) {
plugins.push(
new CopyPlugin({
patterns: [
{
from: path.resolve(paths.public, 'locales'),
to: path.resolve(paths.output, 'locales')
}
]
})
)
plugins.push(new TerserPlugin())
}
return plugins
}
export function buildDevServer(options: TBuildOptions): DevServerConfiguration {
const { mode, port } = options
const isDev = mode === 'development'
const devServer = {
port: port ?? 3000,
open: true,
historyApiFallback: true,
hot: true
}
return isDev ? devServer : undefined
}
export function createMapAndRoute(arrayOfCoordinates) {
ymaps.ready(() => init(arrayOfCoordinates))
}
async function init(arr) {
const curentCoordinate = await currentGeoPositionRequest()
myMap = new ymaps.Map('YMapsID', {
center: [`${curentCoordinate.latitude}`, `${curentCoordinate.longitude}`],
zoom: 9,
controls: [],
})
const abc = [
[55.354864, 37.617698],
[59.138955, 30.315644],
]
console.log(abc, arr) // здесь выводится
const first = abc[0]
const second = arr[0]
console.log(first, second)
}