-
Notifications
You must be signed in to change notification settings - Fork 0
/
greenwood.config.js
44 lines (38 loc) · 1.42 KB
/
greenwood.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import fs from 'fs';
import { greenwoodThemeStarterPresentation } from './index.js';
import path from 'path';
import { ResourceInterface } from '@greenwood/cli/src/lib/resource-interface.js';
import { greenwoodPluginImportRaw } from '@greenwood/plugin-import-raw';
const packageName = JSON.parse(fs.readFileSync(path.join(process.cwd(), './package.json'), 'utf-8')).name;
class MyThemePackDevelopmentResource extends ResourceInterface {
constructor(compilation, options) {
super(compilation, options);
this.extensions = ['*'];
}
async shouldResolve(url) {
// eslint-disable-next-line no-underscore-dangle
return process.env.__GWD_COMMAND__ === 'develop' && url.pathname.indexOf(`/node_modules/${packageName}/`) >= 0;
}
async resolve(url) {
const { pathname, searchParams } = url;
const params = searchParams.size > 0
? `?${searchParams.toString()}`
: '';
const { userWorkspace } = this.compilation.context;
const workspaceUrl = pathname.split(`/node_modules/${packageName}/dist/`)[1];
return new Request(new URL(`./${workspaceUrl}${params}`, userWorkspace));
}
}
export default {
plugins: [
greenwoodPluginImportRaw(),
greenwoodThemeStarterPresentation({
__isDevelopment: true
}),
{
type: 'resource',
name: `${packageName}:resource`,
provider: (compilation, options) => new MyThemePackDevelopmentResource(compilation, options)
}
]
};