@@ -15,6 +15,25 @@ const buildJS = (config = {}) => {
15
15
bundle : true ,
16
16
write : true ,
17
17
outdir : "_site/script" ,
18
+ plugins : [
19
+ {
20
+ name : "css" ,
21
+ setup : ( plugin ) => {
22
+ console . log ( '==================>' )
23
+ plugin . onResolve ( { filter : / ^ .* \. c s s $ / } , ( { path, importer, resolveDir, kind} ) => {
24
+ return { path, namespace : 'css' , pluginData : { importer, resolveDir, kind} }
25
+ } )
26
+ plugin . onLoad ( { filter : / ^ .* \. c s s $ / , namespace : 'css' } , async ( ctx ) => {
27
+ const { default : stringToTemplateLiteral } = await import ( 'string-to-template-literal' )
28
+ let contents = await fs . readFile ( path . resolve ( ctx . pluginData . resolveDir , ctx . path ) , 'utf8' )
29
+
30
+ contents = `const c = new CSSStyleSheet(); c.replaceSync(${ stringToTemplateLiteral ( contents ) } ); export default c;`
31
+
32
+ return { contents, resolveDir : ctx . pluginData . resolveDir }
33
+ } )
34
+ }
35
+ }
36
+ ] ,
18
37
...config ,
19
38
} )
20
39
}
@@ -25,40 +44,16 @@ module.exports = (eleventyConfig) => {
25
44
26
45
const entryPoints = glob . sync ( "script/*.[tj]s" )
27
46
eleventyConfig . addWatchTarget ( "script/*.[tj]s" )
28
-
47
+
29
48
buildJS ( { entryPoints } )
30
49
31
50
eleventyConfig . on ( "beforeWatch" , ( changedFiles ) => {
32
51
// Run me before --watch or --serve re-runs
33
- if ( entryPoints . some ( ( watchPath ) => changedFiles . includes ( watchPath ) ) ) {
52
+ if ( changedFiles . some ( ( watchPath ) => watchPath . endsWith ( '.css' ) || entryPoints . includes ( watchPath ) ) ) {
34
53
buildJS ( { entryPoints } )
35
54
}
36
55
} )
37
56
38
- // eleventyConfig.addPlugin(js, {
39
- // entryPoints: glob.sync("script/*.[tj]s"),
40
- // outDir: "_site/script",
41
- // esbuild: {
42
- // plugins: [
43
- // {
44
- // name: "css",
45
- // setup: (plugin) => {
46
- // console.log('==================>')
47
- // plugin.onResolve({filter: /^.*\.css$/}, (ctx) => Object.assign(ctx, {namespace: 'css'}))
48
- // plugin.onLoad({filter: /^.*\.css$/, namespace: 'css'}, async (ctx) => {
49
- // let contents = await fs.readFileSync(path.resolve(ctx.resolveDir, ctx.filePath), 'utf8')
50
-
51
- // contents = `const c = new CSSStyleSheet(); c.replaceSync("${contents}"); export default c;`
52
-
53
- // return {contents, resolveDir: ctx.resolveDir}
54
- // })
55
- // }
56
- // }
57
- // ],
58
- // minify: false
59
- // }
60
- // })
61
-
62
57
eleventyConfig . addFilter ( "iso8601" , rss . dateToRfc3339 )
63
58
eleventyConfig . addFilter ( "date_to_rfc3339" , rss . dateToRfc3339 )
64
59
eleventyConfig . addFilter ( "date_to_rfc822" , rss . dateToRfc822 )
0 commit comments