Answer the question
In order to leave comments, you need to log in
How to set absolute path in typescript/webpack?
Good afternoon! Please help me understand why this config does not see the absolute path?
How do you properly set up absolute paths in a typeScript project? Without typeScript everything works ok.
I'm only setting up a project on react/redux/typescript.
import where error
webpack sees errorimport {SOME_URL} from 'src/constants';
Module not found: Error: Can't resolve 'src/constants'
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
mode: 'development',
context: path.resolve(__dirname, `./src`),
entry: ['@babel/polyfill', './index.tsx'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.[hash].js'
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
'src': path.resolve(__dirname, './src'),
}
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
include: [
path.resolve(__dirname, 'src'),
],
exclude: /node_modules/,
use: 'ts-loader',
},
{
test: /\.(js|jsx)$/,
include: [
path.resolve(__dirname, 'src'),
],
exclude: /node_modules/,
use: 'source-map-loader',
enforce: 'pre'
},
]
},
plugins: [
new HtmlWebpackPlugin({
template: '../public/index.html',
favicon: '../public/favicon.ico'
}),
],
devtool: 'inline-source-map',
devServer: {
host: 'localhost',
port: 8080,
open: true,
historyApiFallback: true,
hot: true,
inline: true
}
};
{
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"jsx": "react",
"module": "es6",
"moduleResolution": "node",
"experimentalDecorators": true,
"declaration": false,
"removeComments": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"strict": true,
"outDir": "build",
"lib": ["es6", "es7", "dom"],
"baseUrl": "app"
},
"exclude": ["build", "node_modules"]
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question