Vue-cli 3.x can't find the js file after packing?

There is a rem.js under

src/assets/js

but I executed npm run build and sent a warning

clipboard.png

this is the main.js code:

//rem
import rem from "./assets/js/rem.js"
Vue.use(rem);

this is the rem.js code:

fnResize()
window.onresize = function () {
    fnResize()
}
function fnResize() {
    var deviceWidth = document.documentElement.clientWidth || window.innerWidth
    document.documentElement.style.fontSize = (deviceWidth / 3.75) + "px"
}

this is the vue.config.js code:

module.exports = {
    lintOnSave: false,
    baseUrl:"./",
    devServer: {
        port: 9001
    }
}

I feel fine. There are warnings all the time when packing.

May.06,2022

Brother, it's already obvious that you didn't put it export default in rem.js
like this

export default function(){
    fnResize()
    window.onresize = function () {
        fnResize()
    }
    function fnResize() {
        var deviceWidth = document.documentElement.clientWidth || window.innerWidth
        document.documentElement.style.fontSize = (deviceWidth / 3.75) + 'px'
    }
}

should be the code that is not exported by export in your rem.js, so when you use import, you prompt that export cannot be found


write this directly in main.js:

import './assets/js/rem.js'
Menu