1+ import fs from 'fs' ;
12import path from 'path' ;
23import { fileURLToPath } from 'url' ;
34import CopyWebpackPlugin from 'copy-webpack-plugin' ;
45
56const __filename = fileURLToPath ( import . meta. url ) ;
67const __dirname = path . dirname ( __filename ) ;
8+ const pkg = JSON . parse ( fs . readFileSync ( new URL ( './package.json' , import . meta. url ) , 'utf-8' ) ) ;
9+ const PACKAGE_VERSION = process . env . npm_package_version || pkg . version ;
710
8- const entries = {
11+ const rawEntries = {
912 background : './extension/background.js' ,
1013 'content/app' : './extension/content/app.js' ,
1114 'content/main' : './extension/content/main.js' ,
@@ -16,6 +19,16 @@ const entries = {
1619 'options/options' : './extension/options/options.js'
1720} ;
1821
22+ const moduleEntries = new Set ( [ 'content/app' ] ) ;
23+ const entries = Object . fromEntries (
24+ Object . entries ( rawEntries ) . map ( ( [ name , entryPath ] ) => {
25+ if ( moduleEntries . has ( name ) ) {
26+ return [ name , { import : entryPath , library : { type : 'module' } } ] ;
27+ }
28+ return [ name , entryPath ] ;
29+ } )
30+ ) ;
31+
1932export default ( env , argv ) => {
2033 const mode = argv . mode || 'production' ;
2134 return {
@@ -46,7 +59,15 @@ export default (env, argv) => {
4659 plugins : [
4760 new CopyWebpackPlugin ( {
4861 patterns : [
49- { from : 'extension/manifest.json' , to : '.' } ,
62+ {
63+ from : 'extension/manifest.json' ,
64+ to : '.' ,
65+ transform ( content ) {
66+ const manifest = JSON . parse ( content . toString ( 'utf-8' ) ) ;
67+ manifest . version = PACKAGE_VERSION ;
68+ return JSON . stringify ( manifest , null , 2 ) . concat ( '\n' ) ;
69+ }
70+ } ,
5071 { from : 'extension/assets' , to : 'assets' } ,
5172 { from : 'extension/content/controller.css' , to : 'content/controller.css' } ,
5273 { from : 'extension/popup/index.html' , to : 'popup/index.html' } ,
@@ -59,6 +80,9 @@ export default (env, argv) => {
5980 resolve : {
6081 extensions : [ '.js' ]
6182 } ,
83+ experiments : {
84+ outputModule : true
85+ } ,
6286 devtool : mode === 'production' ? false : 'source-map' ,
6387 watch : Boolean ( argv . watch )
6488 } ;
0 commit comments