2021-12-11 14:04:05 +01:00
|
|
|
import path from 'path'
|
2021-12-10 09:56:19 +01:00
|
|
|
import remarkGfm from 'remark-gfm'
|
2022-07-12 20:47:39 +02:00
|
|
|
import { designs, plugins } from '../../../config/software/index.mjs'
|
2022-02-05 17:45:23 +01:00
|
|
|
|
2022-01-24 12:34:29 +01:00
|
|
|
/*
|
|
|
|
* This mehthod will return the NextJS configuration
|
|
|
|
* Parameters:
|
|
|
|
*
|
|
|
|
* site: one of 'dev', 'org', or 'lab'
|
|
|
|
* remarkPlugins: Array of remark plugins to load
|
|
|
|
* srcPkgs: Array of folders in the monorepo/packages that should be aliased
|
|
|
|
* so they are loaded from source, rather than from a compiled bundle
|
|
|
|
*/
|
2022-11-13 14:10:28 -08:00
|
|
|
const config = (site, remarkPlugins = []) => ({
|
2021-12-10 09:56:19 +01:00
|
|
|
experimental: {
|
|
|
|
externalDir: true,
|
|
|
|
},
|
2023-01-10 20:17:23 +01:00
|
|
|
pageExtensions: ['js'],
|
2021-12-10 09:56:19 +01:00
|
|
|
webpack: (config, options) => {
|
2022-11-13 14:10:28 -08:00
|
|
|
// Fixes npm packages that depend on node modules
|
2021-12-10 09:56:19 +01:00
|
|
|
if (!options.isServer) {
|
|
|
|
config.resolve.fallback.fs = false
|
2021-12-11 14:04:05 +01:00
|
|
|
config.resolve.fallback.path = false
|
2021-12-10 09:56:19 +01:00
|
|
|
config.resolve.fallback.child_process = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// MDX support
|
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.md?$/,
|
|
|
|
use: [
|
|
|
|
options.defaultLoaders.babel,
|
|
|
|
{
|
|
|
|
loader: '@mdx-js/loader',
|
|
|
|
//providerImportSource: '@mdx-js/react',
|
|
|
|
options: {
|
2022-11-13 14:10:28 -08:00
|
|
|
remarkPlugins: [remarkGfm, ...remarkPlugins],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2021-12-10 09:56:19 +01:00
|
|
|
})
|
2021-12-11 14:04:05 +01:00
|
|
|
|
2022-02-05 17:45:23 +01:00
|
|
|
// YAML support
|
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.ya?ml$/,
|
2022-11-13 14:10:28 -08:00
|
|
|
use: 'yaml-loader',
|
2022-02-05 17:45:23 +01:00
|
|
|
})
|
|
|
|
|
2021-12-10 09:56:19 +01:00
|
|
|
// Fix for nextjs bug #17806
|
|
|
|
config.module.rules.push({
|
|
|
|
test: /index.mjs$/,
|
2022-11-13 14:10:28 -08:00
|
|
|
type: 'javascript/auto',
|
2021-12-10 09:56:19 +01:00
|
|
|
resolve: {
|
2022-11-13 14:10:28 -08:00
|
|
|
fullySpecified: false,
|
|
|
|
},
|
2021-12-10 09:56:19 +01:00
|
|
|
})
|
|
|
|
|
2022-06-17 12:02:09 +02:00
|
|
|
// Suppress warnings about importing version from package.json
|
|
|
|
// We'll deal with it in v3 of FreeSewing
|
2022-11-13 14:10:28 -08:00
|
|
|
config.ignoreWarnings = [/only default export is available soon/]
|
2022-06-17 12:02:09 +02:00
|
|
|
|
2021-12-11 14:04:05 +01:00
|
|
|
// Aliases
|
2022-06-17 12:02:09 +02:00
|
|
|
config.resolve.alias.shared = path.resolve('../shared/')
|
|
|
|
config.resolve.alias.site = path.resolve(`../${site}/`)
|
2021-12-18 09:54:53 +01:00
|
|
|
config.resolve.alias.markdown = path.resolve(`../../markdown/${site}/`)
|
2022-06-17 12:02:09 +02:00
|
|
|
config.resolve.alias.config = path.resolve('../../config/')
|
|
|
|
config.resolve.alias.designs = path.resolve('../../designs/')
|
|
|
|
config.resolve.alias.plugins = path.resolve('../../plugins/')
|
|
|
|
config.resolve.alias.pkgs = path.resolve('../../packages/')
|
2022-12-26 15:35:22 +01:00
|
|
|
config.resolve.alias.root = path.resolve('../../')
|
2022-06-17 12:02:09 +02:00
|
|
|
|
|
|
|
// Load designs from source, rather than compiled package
|
|
|
|
for (const design in designs) {
|
2022-12-24 22:58:29 +01:00
|
|
|
config.resolve.alias[`@freesewing/${design}`] = path.resolve(
|
2022-11-13 14:10:28 -08:00
|
|
|
`../../designs/${design}/src/index.mjs`
|
|
|
|
)
|
2022-06-17 12:02:09 +02:00
|
|
|
}
|
|
|
|
// Load plugins from source, rather than compiled package
|
|
|
|
for (const plugin in plugins) {
|
2022-12-24 22:58:29 +01:00
|
|
|
config.resolve.alias[`@freesewing/${plugin}`] = path.resolve(
|
2022-11-13 14:10:28 -08:00
|
|
|
`../../plugins/${plugin}/src/index.mjs`
|
|
|
|
)
|
2022-06-17 12:02:09 +02:00
|
|
|
}
|
|
|
|
// Load these from source, rather than compiled package
|
2022-11-13 15:01:16 -08:00
|
|
|
for (const pkg of ['core', 'i18n', 'models', 'snapseries']) {
|
2022-12-24 22:58:29 +01:00
|
|
|
config.resolve.alias[`@freesewing/${pkg}`] = path.resolve(
|
2022-11-13 14:10:28 -08:00
|
|
|
`../../packages/${pkg}/src/index.mjs`
|
|
|
|
)
|
2022-02-05 17:45:23 +01:00
|
|
|
}
|
2021-12-11 14:04:05 +01:00
|
|
|
|
2021-12-10 09:56:19 +01:00
|
|
|
return config
|
2022-11-13 14:10:28 -08:00
|
|
|
},
|
2021-12-11 14:04:05 +01:00
|
|
|
})
|
2021-12-10 09:56:19 +01:00
|
|
|
|
|
|
|
export default config
|