I have this code
import('./myfile.js')
.then(m=>console.log(m.default))
.catch(err=>console.error(err))
webpack bundles "myfile.js", but I want to copy this file to 'dist' and import it dynamically, i.e. I want to avoid compiling this import()
statement.
note that this code is a part of a function and the file 'myfile.js' is provided by a function argument, so I cannot add the path to the webpack's externals array.
I tried the following approaches:
- using webpac's magic comments
/* webpackIgnore: true, webpackMode: "lazy" */
- provide a variable path
let file = 'myfile.js'
import('./' + file)
- provide the path as a function call
let getPath = path=>path
import(getPath('./myfile.js'))
- put the import statement inside a function
function load(path){
return import('./' + path)
}
load('myfile.js')