1
- import {
2
- defaultExternals ,
3
- defaultOutputConfig ,
4
- defaultPlugins ,
5
- defaultProdPlugins ,
6
- defaultServePlugins ,
7
- copy ,
8
- isLibrary ,
9
- isProd ,
10
- isServe ,
11
- workbox
12
- } from "@appnest/web-config" ;
13
- import { resolve , join } from "path" ;
1
+ import { copy , defaultExternals , defaultOutputConfig , defaultPlugins , defaultProdPlugins , defaultServePlugins , isLibrary , isProd , isServe , workbox } from "@appnest/web-config" ;
2
+ import { join , resolve } from "path" ;
14
3
import pkg from "./package.json" ;
15
4
16
5
const folders = {
@@ -31,85 +20,140 @@ const files = {
31
20
dist_service_worker : join ( folders . dist , "sw.js" )
32
21
} ;
33
22
34
- export default {
35
- input : {
36
- main : files . main
37
- } ,
38
- output : [
39
- defaultOutputConfig ( {
40
- format : "esm" ,
41
- dir : folders . dist
42
- } )
43
- ] ,
44
- plugins : [
45
- ...defaultPlugins ( {
46
- cleanConfig : {
47
- targets : [
48
- folders . dist
49
- ]
50
- } ,
51
- copyConfig : {
52
- resources : [
53
- [ folders . assets , folders . dist_assets ]
54
- ]
55
- } ,
56
- htmlTemplateConfig : {
57
- template : files . src_index ,
58
- target : files . dist_index ,
59
- include : / m a i n ( - .* ) ? \. j s $ /
60
- } ,
61
- importStylesConfig : {
62
- globals : [ "main.scss" ]
63
- }
64
- } ) ,
65
-
66
- // Serve
67
- ...( isServe ? [
68
- ...defaultServePlugins ( {
69
- serveConfig : {
70
- port : 1340 ,
71
- contentBase : folders . dist
72
- } ,
73
- livereloadConfig : {
74
- watch : folders . dist ,
75
- port : 35730
76
- }
23
+ export default [
24
+ {
25
+ // Module build
26
+ input : {
27
+ main : files . main
28
+ } ,
29
+ output : [
30
+ defaultOutputConfig ( {
31
+ format : "esm" ,
32
+ dir : folders . dist
77
33
} )
78
- ] : [ ] ) ,
79
-
80
- // Production
81
- ...( isProd ? [
82
- ...defaultProdPlugins ( {
83
- dist : folders . dist ,
84
- minifyLitHtmlConfig : {
85
- verbose : false ,
86
- // Exclude all files since we need the original formatting for the demo code blocks
87
- exclude : / .* /
34
+ ] ,
35
+ plugins : [
36
+ ...defaultPlugins ( {
37
+ cleanConfig : {
38
+ targets : [
39
+ folders . dist
40
+ ]
41
+ } ,
42
+ copyConfig : {
43
+ resources : [
44
+ [ folders . assets , folders . dist_assets ]
45
+ ]
46
+ } ,
47
+ htmlTemplateConfig : {
48
+ template : files . src_index ,
49
+ scriptType : "module" ,
50
+ target : files . dist_index ,
51
+ include : / m a i n ( - .* ) ? \. j s $ / ,
52
+ polyfillConfig : {
53
+ features : [ "systemjs" , "web-components" ]
54
+ }
55
+ } ,
56
+ importStylesConfig : {
57
+ globals : [ "main.scss" ]
88
58
}
89
59
} ) ,
90
- copy ( {
91
- resources : [
92
- [ files . src_robots , files . dist_robots ] ,
93
- [ files . src_sw_extension , files . dist_sw_extension ] ,
94
- ]
95
- } ) ,
96
- workbox ( {
97
- mode : "generateSW" ,
98
- workboxConfig : {
99
- globDirectory : folders . dist ,
100
- swDest : files . dist_service_worker ,
101
- globPatterns : [ `**/*.{js,png,html,css}` ] ,
102
- importScripts : [ `sw-extension.js` ]
103
- }
104
- } )
105
- ] : [ ] ) ,
106
- ] ,
107
- external : [
108
- ...( isLibrary ? [
109
- ...defaultExternals ( pkg )
110
- ] : [ ] )
111
- ] ,
112
- treeshake : isProd ,
113
- context : "window"
114
- }
60
+
61
+ // Serve
62
+ ...( isServe ? [
63
+ ...defaultServePlugins ( {
64
+ serveConfig : {
65
+ port : 1340 ,
66
+ contentBase : folders . dist
67
+ } ,
68
+ livereloadConfig : {
69
+ watch : folders . dist ,
70
+ port : 35730
71
+ }
72
+ } )
73
+ ] : [ ] ) ,
74
+
75
+ // Production
76
+ ...( isProd ? [
77
+ ...defaultProdPlugins ( {
78
+ dist : folders . dist ,
79
+ minifyLitHtmlConfig : {
80
+ verbose : false ,
81
+ // Exclude all files since we need the original formatting for the demo code blocks
82
+ exclude : / .* /
83
+ } ,
84
+ compressConfig : {
85
+ // Exclude everything since firebase compresses the files for us
86
+ exclude : / .* /
87
+ }
88
+ } ) ,
89
+ copy ( {
90
+ resources : [
91
+ [ files . src_robots , files . dist_robots ] ,
92
+ [ files . src_sw_extension , files . dist_sw_extension ]
93
+ ]
94
+ } ) ,
95
+ workbox ( {
96
+ mode : "generateSW" ,
97
+ workboxConfig : {
98
+ globDirectory : folders . dist ,
99
+ swDest : files . dist_service_worker ,
100
+ globPatterns : [ `**/*.{js,png,html,css}` ] ,
101
+ importScripts : [ `sw-extension.js` ]
102
+ }
103
+ } )
104
+ ] : [ ] )
105
+ ] ,
106
+ external : [
107
+ ...( isLibrary ? [
108
+ ...defaultExternals ( pkg )
109
+ ] : [ ] )
110
+ ] ,
111
+ treeshake : isProd ,
112
+ context : "window"
113
+ }
114
+ // !isServe && isProd ? {
115
+ // // CJS build
116
+ // input: {
117
+ // main: files.main
118
+ // },
119
+ // output: [
120
+ // defaultOutputConfig({
121
+ // format: "cjs",
122
+ // dir: folders.dist,
123
+ // entryFileNames: "[name]-legacy-[hash].js",
124
+ // chunkFileNames: "[name]-legacy-[hash].js",
125
+ // })
126
+ // ],
127
+ // plugins: [
128
+ // ...defaultPlugins({
129
+ // htmlTemplateConfig: {
130
+ // template: files.dist_index,
131
+ // target: files.dist_index,
132
+ // scriptType: "text/javascript",
133
+ // transformScript: ({filename, scriptType}) => `<script nomodule type="${scriptType}" src="${filename}"></script>`,
134
+ // include: /main(-.*)?\.js$/
135
+ // },
136
+ // importStylesConfig: {
137
+ // globals: ["main.scss"]
138
+ // }
139
+ // }),
140
+ // ...defaultProdPlugins({
141
+ // dist: folders.dist,
142
+ // minifyLitHtmlConfig: {
143
+ // verbose: false,
144
+ // // Exclude all files since we need the original formatting for the demo code blocks
145
+ // exclude: /.*/
146
+ // }
147
+ // }),
148
+ // copy({
149
+ // resources: [
150
+ // [files.src_robots, files.dist_robots],
151
+ // [files.src_sw_extension, files.dist_sw_extension]
152
+ // ]
153
+ // })
154
+ // ],
155
+ // treeshake: isProd,
156
+ // context: "window"
157
+ // } : undefined
158
+ ] ;
115
159
0 commit comments