As from the vue-router documentation to lazy load components I am using syntax:
const Foo = () => import('./Foo.vue')
I have the error:
client?cd17:49 ./src/routes.js
Module build failed: SyntaxError: Unexpected token (5:19)
3 |
4 | //const User = () => System.import('./components/user/User.vue');
> 5 | const User = () => import('./components/user/User.vue')
| ^
6 | const UserStart = () => System.import('./components/user/UserStart.vue');
7 | const UserDetail = () => System.import('./components/user/UserDetail.vue');
8 | const UserEdit = () => System.import('./components/user/UserEdit.vue');
BabelLoaderError: SyntaxError: Unexpected token (5:19)
3 |
4 | //const User = () => System.import('./components/user/User.vue');
> 5 | const User = () => import('./components/user/User.vue')
| ^
6 | const UserStart = () => System.import('./components/user/UserStart.vue');
7 | const UserDetail = () => System.import('./components/user/UserDetail.vue');
8 | const UserEdit = () => System.import('./components/user/UserEdit.vue');
at transpile (/app/node_modules/babel-loader/lib/index.js:61:13)
at Object.module.exports (/app/node_modules/babel-loader/lib/index.js:163:20)
@ ./src/main.js 4:0-34
@ multi main
errors @ client?cd17:49
sock.onmessage @ client?cd17:83
EventTarget.dispatchEvent @ eventtarget.js?3e89:51
(anonymous) @ main.js?45b8:274
SockJS._transportMessage @ main.js?45b8:272
EventEmitter.emit @ emitter.js?927b:50
WebSocketTransport.ws.onmessage @ websocket.js?c17e:35
After that I have installed
npm install --save-dev babel-preset-stage-2
and
npm install --save-dev babel-plugin-transform-export-extensions
also configured .babelrc file to:
{
"presets": [
["es2015", { "modules": false }],
"stage-2"
],
"plugins": [
"transform-export-extensions"
]
}
Nothing helps, how can I use this const Foo = () => import('./Foo.vue')
syntax to load components lazily with webpack and vue-router?