Created
July 14, 2017 15:34
-
-
Save kitsonk/c095770c0f2d75367d26b7846d729861 to your computer and use it in GitHub Desktop.
Making Page Bundles for Electron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as webpack from 'webpack'; | |
import { resolve } from 'path'; | |
import { existsSync } from 'fs'; | |
const NormalModuleReplacementPlugin: any = require('webpack/lib/NormalModuleReplacementPlugin'); | |
export = function webpackConfig(): webpack.Configuration { | |
return { | |
entry: { | |
index: './lib/pages/index.js', | |
runner: './lib/pages/runner.js' | |
}, | |
externals: [ (context: any, request: string, callback: (context?: any, response?: string) => any) => { | |
if (request === 'electron') { | |
return callback(null, `require('electron')`); | |
} | |
return callback(); | |
} ], | |
output: { | |
path: resolve(__dirname, '../lib'), | |
filename: 'page.[name].js' | |
}, | |
plugins: [ | |
new NormalModuleReplacementPlugin(/\.m.css$/, (result: any) => { | |
const requestFileName = resolve(result.context, result.request); | |
const jsFileName = requestFileName + '.js'; | |
if (existsSync(jsFileName)) { | |
result.request = result.request.replace(/\.m\.css$/, '.m.css.js'); | |
} | |
}) | |
], | |
module: { | |
rules: [ | |
{ test: /\.js$/, loader: 'umd-compat-loader' }, | |
{ test: /\.css$/, loader: 'css-loader' } | |
] | |
}, | |
node: { | |
fs: 'empty' | |
}, | |
devtool: 'source-map' | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment