Webpack4 dynamic import cannot get chunkname

webpack.base.config.js:

    entry: {
        app: "./src/index.js"
    },
    output: {
        path: config.build.assetsRoot,  // "/"
        publicPath: config.dev.assetsPublicPath,    // "static"
        filename: "[name].bundle.js",
        chunkFilename: "[name].chunk.js"
    },

router (using require.ensure ()) can get name): correctly

const routes = [
  {
    path: "/",
    component: r => {
      require.ensure([], () => r(require("./view/index/index.vue")), "index")
    }
  },
  {
    path: "/errorPage",
    component: r => {
      require.ensure([], () => r(require("./view/errorPage/errorPage.vue")), "errorPage")
    }
  },
  {
    path: "/page",
    component: r => {
      require.ensure([], () => r(require("./view/page/page.vue")), "page")
    }
  }
];

result (get name): correctly

clipboard.png

import:


name:

clipboard.png

some people say it has something to do with the babel setting, but it doesn"t work if I try:
.babelrc:

{
    "env": {
        "production": {
            "presets": [
                ["env", {
                    "targets": {
                        "browsers": ["last 2 version", "ie 10"]
                    },
                    "modules": false,
                    "debug": true
                }]
            ],
            "plugins": [
                "transform-runtime",
                "transform-object-rest-spread",
                "dynamic-import-webpack"
            ]
        },
        "development": {
            "presets": [
                ["env", {
                    "targets": {
                        "chrome": 60
                    },
                    "modules": false,
                    "debug": true
                }]
            ],
            "plugins": [
                "transform-object-rest-spread",
                "dynamic-import-webpack"
            ]
        }
    }
}

solve the problem with all the bigwigs

Mar.15,2021

install the plug-in babel-plugin-syntax-dynamic-import
.babelrc modify:

"plugins": [
  "syntax-dynamic-import"
]

reference link


correct solution, forgot to close the post. Like


after my vue-cli upgrades webpack4, the dynamic loading of the routing page is invalid, try the above method, compile, or are compiled into a js file, do you encounter this problem


because menus are background, routing is based on menu dynamic groups, so can chunk name be a variable and how to write it?


the project I built with vue cli3 is written as follows:

const MainLeft =() => import(/*webpackChunkName:"Fire-MainLeft"*/ '../components/Fire/MainLeft.vue');

const MainRight =() => import(/*webpackChunkName:"Fire-MainRight"*/ '../components/Fire/MainRight.vue');

const MainCenterTop =() => import(/*webpackChunkName:"Fire-MainCenterTop"*/ '../components/Fire/MainCenterTop.vue');

const MainCenterBottom =() =>

 import(/*webpackChunkName:"Fire-MainCenterBottom"*/ '../components/Fire/MainCenterBottom.vue');

export { MainLeft, MainRight, MainCenterTop, MainCenterBottom };
{

 path: '/Fire',

 name: 'Fire',

 title: '',

 components: {

 routerLeft: Fire.MainLeft,

 routerRight: Fire.MainRight,

 routerCenterTop: Fire.MainCenterTop,

 routerCenterBottom: Fire.MainCenterBottom,

 },

 }

but the package will not generate the corresponding js file, but it will still be packaged into app.js. In the same way, it is normal for me to test another demo project. I compared the dependent versions of the two projects, but I did not find the problem. I would like to ask how to solve it

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37b09-2b419.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37b09-2b419.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?