最近在使用react時發現路徑用../../很不方便,特別是修改項目結構時,加減../都能改到吐血,php
全部在網上找了半天webpack的配置,特此記錄下css
module.exports = (webpackConfig) => { const config = Object.create(webpackConfig); config.resolve = { extensions: ['.js', '.jsx', '.json', '.scss', '.css'], alias: { '@': `${__dirname}/src/`, 'static': `${__dirname}/src/static/`, 'utils': `${__dirname}/src/utils/`, 'config': `${__dirname}/src/config/`, 'views': `${__dirname}/src/views/`, 'services': `${__dirname}/src/services/`, 'components': `${__dirname}/src/components/`, 'models': `${__dirname}/src/models/` } }; return config; };
調用react
import {arrayNullToString} from 'utils/help/ArrayHelp'
不用再../了!webpack