I have a specific file filled with essential global constants that I am attempting to bring into another JavaScript file. This way, I can utilize these constants within the code of the second file.
globalConstant.js
global.RoutesOffersPage = {
routes: [
{ url: '/fr',
title: "French Homepage"
},
{ url:'/fr/dothis',
title: "Very Cool"
}
]
}
global.RoutesActionPage = {
routes: [
{ url: '/fr/action',
title: 'Action Page'
}
]
}
export { global.RoutesOffersPage };
export { global.RoutesActionPage };
My goal is to access these global variables in my webpack configuration file (webpack.config.js).
webpack.config.js
import { global.RoutesOffersPage } from './globalConstant.js'
import { global.RoutesActionPage } from './globalConstant.js'
var templateOffersPage = ejs.compile(fs.readFileSync(__dirname + '/offersPageTemplate.ejs', 'utf-8'))
var paths = global.RoutesOffersPage.routes.map(r => r.url);
var paths2 = global.RoutesActionPage.routes.map(r => r.url);
//do stuff
However, during the build process, an error occurs:
SyntaxError: Unexpected token import
Typically, I know how to handle imports when dealing with functions, but in this instance, it's just constant 'global.constants'. I feel perplexed and unsure about how to proceed.