webpack4動態導入文件報錯,按照錯誤提示安裝了插件,但未果,最後查到一個可行方案,記錄以下:
1.經過懶加載的方式動態引入文件javascript
const router = new Router({ routes: [{ path: '/home', name: 'Home', component: () => import('./views/home/Home.vue') }] })
2.報錯以下所示vue
ERROR in ./src/router.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: D:\practice\vue-pro\webpack-vue-create\src\router.js: Support for the experimental syntax 'dynamicImport' isn't currently enabled (19:13):java
3.解決方案node
一:安裝插件babel-plugin-dynamic-import-webpack
npm install babel-plugin-dynamic-import-webpack --save-dev
二:在配置文件的module的rules下進行插件的配置,以下webpack
{ test: /\.js/, use: [{ loader: 'babel-loader', options: {//若是有這個設置則不用再添加.babelrc文件進行配置 "babelrc": false,// 不採用.babelrc的配置 "plugins": [ "dynamic-import-webpack" ] } }] }
如此,問題就解決了!web