1+ import fs from "fs"
12import path from "path"
23import babel from "@rollup/plugin-babel"
34import { nodeResolve } from "@rollup/plugin-node-resolve"
4- import { terser } from "rollup- plugin-terser"
5+ import terser from "@ rollup/ plugin-terser"
56
6- const currentDir = process . cwd ( )
7+ const loadJSON = ( path ) =>
8+ JSON . parse ( fs . readFileSync ( new URL ( path , import . meta. url ) ) )
9+
10+ const dirname = path . resolve ( )
711const year = new Date ( ) . getFullYear ( )
812
913const banner = async ( ) => {
10- const { default : pkg } = await import ( "../package.json" )
14+ const pkg = loadJSON ( "../package.json" )
1115
1216 return `/*!
1317 * @license MIT (https://github.com/geotrev/omdomdom/blob/master/LICENSE)
@@ -21,7 +25,7 @@ const Formats = {
2125 ES : "es" ,
2226 UMD : "umd" ,
2327}
24- const input = path . resolve ( currentDir , "src/index.js" )
28+ const input = path . resolve ( dirname , "src/index.js" )
2529const basePlugins = [
2630 nodeResolve ( ) ,
2731 babel ( {
@@ -31,17 +35,7 @@ const basePlugins = [
3135 } ) ,
3236]
3337
34- const terserPlugin = terser ( {
35- output : {
36- comments : ( _ , comment ) => {
37- const { value, type } = comment
38-
39- if ( type === "comment2" ) {
40- return / @ p r e s e r v e | @ l i c e n s e | @ c c _ o n / i. test ( value )
41- }
42- } ,
43- } ,
44- } )
38+ const terserPlugin = terser ( )
4539
4640const baseOutput = ( format ) => ( {
4741 banner,
@@ -55,22 +49,22 @@ const outputs = [Formats.ES, Formats.CJS].reduce(
5549 ...configs ,
5650 {
5751 ...baseOutput ( format ) ,
58- file : path . resolve ( currentDir , `lib/omdomdom.${ format } .js` ) ,
52+ file : path . resolve ( dirname , `lib/omdomdom.${ format } .js` ) ,
5953 } ,
6054 {
6155 ...baseOutput ( format ) ,
62- file : path . resolve ( currentDir , `lib/omdomdom.${ format } .min.js` ) ,
56+ file : path . resolve ( dirname , `lib/omdomdom.${ format } .min.js` ) ,
6357 plugins : [ terserPlugin ] ,
6458 } ,
6559 ] ,
6660 [
6761 {
6862 ...baseOutput ( Formats . UMD ) ,
69- file : path . resolve ( currentDir , "dist/omdomdom.js" ) ,
63+ file : path . resolve ( dirname , "dist/omdomdom.js" ) ,
7064 } ,
7165 {
7266 ...baseOutput ( Formats . UMD ) ,
73- file : path . resolve ( currentDir , "dist/omdomdom.min.js" ) ,
67+ file : path . resolve ( dirname , "dist/omdomdom.min.js" ) ,
7468 plugins : [ terserPlugin ] ,
7569 } ,
7670 ]
0 commit comments