UNPKG

skypager-project-types-electron-app

Version:

skypager electron app project type

106 lines (85 loc) 3.61 kB
import { join } from 'path' export function compilerWillMount(webpackConfig) { webpackConfig.target = 'electron-renderer' webpackConfig.node = { __dirname: false, __filename: false, process: false, } webpackConfig.externals = [] return webpackConfig } export function configure(options = {}, context = {}) { const { project } = context options = Object.assign({ dllName: project.argv.dllName || 'electron-app-renderer', publicPath: project.argv.publicPath || (project.isProduction ? '' : '/'), app: options.entry || (project.argv.in ? [project.resolve(project.argv.in)] : [project.join('src/index')]), }, options) const { hot = project.argv.hot, publicPath = project.isDevelopment && project.argv.hot ? '/' : '', outputPath = project.join('app', 'renderer'), app, //templatePath = join(__dirname, 'templates', 'html-webpack-template.js'), //htmlFileName = 'index.html', dllPath = project.resolve(project.paths.bundles, `${options.dllName || 'electron-app-renderer'}.dll.json`), disableDllPlugin = project.argv.disableDllPlugin, //disableCopyPlugin = project.argv.disableCopyPlugin, disableHmr = (!project.argv.hot || project.argv.disableHmr), //disableHtmlPlugin = project.argv.disableHtmlPlugin, disableProvidePlugin = project.argv.disableProvidePlugin, disableRuntime = project.argv.disableRuntime, } = options const entryCfg = { app } if (hot) { app.unshift(HMROptions({publicPath})) options.hot = true } const instance = project.compiler('web', options) return instance.config .modules(project.join('src')) //.modules(project.join('..')) .entry(entryCfg) .sourcemap(project.get('argv.setDevtool', 'eval')) .loader('skypager-document', ['.md'], { include: [project.paths.source], exclude: [/node_modules/, project.paths.public, project.paths.output], loader: 'skypager-document', }) .output({ publicPath, path: outputPath, libraryTarget: 'umd'}) .plugin('webpack.DefinePlugin', { __ELECTRON_RENDERER__: JSON.stringify(true), __ELECTRON_MAIN__: JSON.stringify(false), __BROWSER__: JSON.stringify(true), __DEV__: JSON.stringify(!!project.isDevelopment) }) .when(() => !disableDllPlugin && project.existsSync(dllPath), (c) => c .plugin('webpack.DllReferencePlugin', { context: project.cwd, manifest: project.readJsonSync(dllPath), }) ) .when(() => !disableProvidePlugin, (c) => c .plugin('webpack.ProvidePlugin', { fetch: 'exports?self.fetch!isomorphic-fetch', React: 'react', autobind: 'autobind-decorator' }) ) .when(() => hot && !disableHmr, (cfg) => cfg.plugin('webpack.HotModuleReplacementPlugin')) .when((() => !disableRuntime), (cfg) => cfg.copy([ {from: join(__dirname, '..', 'src', 'runtime')}, ] )) } const HMROptions = (options = {}) => { const { publicPath } = options const webpackHotPath = `${publicPath}__webpack_hmr` const webpackHotMiddlewareEntry = { path: webpackHotPath, // The path which the middleware is serving the event stream on overlay: true, // Set to false to disable the DOM-based client-side overlay. noInfo: false, // Set to true to disable informational console logging. quiet: false, // Set to true to disable all console logging. } return `webpack-hot-middleware/client?${require('querystring').stringify(webpackHotMiddlewareEntry)}` }