import { resolve as _resolve } from 'path' ; import HtmlWebpackPlugin from 'html-webpack-plugin' ; import CopyPlugin from 'copy-webpack-plugin' ; import { DefinePlugin } from 'webpack' ; import { version } from './package.json' ; import gitHash from '../scripts/hash' ; import { release , arch } from 'os' ; import { version as node } from 'process' ; const MOCKS_PATH = 'cypress/mocks/' ; import { platform as PLATFORM } from 'process' ; import { readdirSync } from 'fs' ; function resolveMock ( moduleName ) { return _resolve ( __dirname , `${ MOCKS_PATH }${ moduleName }.js` ) ; } param { string } mockPath function webpackAliases ( mockPath ) { const mockNames = readdirSync ( mockPath ) . map ( ( file ) => file . replace ( '.js' , '' ) ) ; console . log ( 'Generating webpack alias for mocks' , mockNames ) ; return mockNames . reduce ( ( acc , name ) => { acc [ name ] = resolveMock ( name ) ; return acc ; } , { } ) ; } const baseConfig = { output : { path : _resolve ( __dirname , 'build-e2e' ) , filename : '[name].js' , } , externals : { path : '{}' , net : '{}' , tls : '{}' , fs : '{}' , } , node : { __dirname : false , } , devtool : 'source-map' , mode : 'development' , resolve : { extensions : [ '.ts' , '.tsx' , '.js' , '.json' , '.css' ] , alias : webpackAliases ( MOCKS_PATH ) , } , module : { rules : [ { test : /\.tsx?$/ , use : [ { loader : 'ts-loader' , options : { transpileOnly : true , configFile : _resolve ( './build-tsconfig.json' ) , } , } , ] , } , { enforce : 'pre' , test : /\.js$/ , loader : 'source-map-loader' } , { test : /\.css$/ , use : [ 'style-loader' , 'css-loader' ] , } , { test : /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/ , use : [ { loader : 'file-loader' , options : { name : '[name].[ext]' , outputPath : 'fonts/' , } , } , ] , } , { test : /\.(png|jpg|gif)$/i , use : [ { loader : 'url-loader' , options : { limit : 8192 , } , } , ] , } , ] , } , } ; export default [ Object . assign ( { target : 'web' , entry : { gui : '../src/gui/index.tsx' } , plugins : [ new HtmlWebpackPlugin ( { title : 'React-Explorer' , template : '../index.html' , } ) , new DefinePlugin ( { 'ENV.CY' : true , 'ENV.NODE_ENV' : JSON . stringify ( baseConfig . mode ) , 'ENV.VERSION' : JSON . stringify ( version ) , 'ENV.HASH' : JSON . stringify ( gitHash ) , 'ENV.BUILD_DATE' : JSON . stringify ( Date . now ( ) ) , __RELEASE__ : JSON . stringify ( release ( ) ) , __PLATFORM__ : JSON . stringify ( PLATFORM ) , __ARCH__ : JSON . stringify ( arch ( ) ) , __NODE__ : JSON . stringify ( node ) , } ) , new CopyPlugin ( { patterns : [ { from : '../img/icon-512x512.png' , to : 'icon.png' , } , ] , } ) , ] , } , baseConfig ) , ] ;