Webpack @ import cannot use the alias alias

I used the project created by vue-cli 2.x, and then in the .vue file

<style>
@import "@/assets/icon/iconfont.css";
</style>

will report an error: Module build failed: Error: Failed to find"~ @ / assets/icon/iconfont.css"

even if I add ~ , I will still report an error: Module build failed: Error: Failed to find"@ / assets/icon/iconfont.css"

does any boss know how to solve it? Thank you very much!

Jun.23,2022

@ import'~ @ / assets/icon/iconfont.css';

add [~] before the alias

resolve: {
    alias: {
        '@': path.resolve(__dirname, 'src'),
        'static': path.resolve(__dirname, 'src/static'),
        'assets': path.resolve(__dirname, 'src/assets'),
        'components': path.resolve(__dirname, 'src/components')
    }
}

CSS loader interprets the url of a non-root path as a relative path, and prefixes it as a module path

.

Source: https://www.jianshu.com/p/c3a...


webpack.resolve.alias configure

Menu