import * as webpack from 'webpack' ; import * as path from 'path' ; import * as fs from 'fs' ; import CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ; import PostCompile = require ( 'post-compile-webpack-plugin' ) ; import 'zotero-plugin/make-dirs' ; import 'zotero-plugin/copy-assets' ; import 'zotero-plugin/rdf' ; import 'zotero-plugin/version' ; const target_dir = 'build/content' ; const webpack_js = 'webpack.js' ; const config = { mode : 'development' , devtool : false , optimization : { flagIncludedChunks : true , occurrenceOrder : false , usedExports : true , minimize : false , concatenateModules : false , noEmitOnErrors : true , namedModules : true , namedChunks : true , runtimeChunk : { name : 'webpack' , } , } , resolve : { extensions : [ '.ts' , '.js' ] , } , node : { fs : 'empty' } , resolveLoader : { alias : { 'json-jsesc-loader' : 'zotero-plugin/loader/json' , 'wrap-loader' : 'zotero-plugin/loader/wrap' , } , } , module : { rules : [ { test : /\.json$/ , type : 'javascript/auto' , use : [ 'json-jsesc-loader' ] } , { test : /\.ts$/ , exclude : [ /node_modules/ ] , use : [ 'wrap-loader' , 'ts-loader' ] } , ] , } , plugins : [ new CircularDependencyPlugin ( { failOnError : true } ) , new PostCompile ( ( ) => { let js = fs . readFileSync ( `${ target_dir }/${ webpack_js }` , 'utf-8' ) ; const prefix = 'if (!Zotero.WebPackedDateFromLastModified) {\n\n' ; const postfix = '\n\n}\n' ; if ( ! js . startsWith ( prefix ) ) js = `${ prefix }${ js }${ postfix }` ; fs . writeFileSync ( `${ target_dir }/${ webpack_js }` , js ) ; } ) , ] , context : path . resolve ( __dirname , './content' ) , entry : { DateFromLastModified : './zotero-date-from-last-modified.ts' , } , output : { globalObject : 'Zotero' , path : path . resolve ( __dirname , `./${ target_dir }` ) , filename : '[name].js' , jsonpFunction : 'WebPackedDateFromLastModified' , devtoolLineToLine : true , pathinfo : true , library : 'Zotero.[name]' , libraryTarget : 'assign' , } , } ; export default config ;