skypager-project-types-electron-app
Version:
skypager electron app project type
64 lines (51 loc) • 2.01 kB
JavaScript
import { join } from 'path'
export function compilerWillMount(webpackConfig) {
webpackConfig.target = 'electron-main'
webpackConfig.node = {
__dirname: false,
__filename: false,
process: false,
}
return webpackConfig
}
export function configure(options = {}, context = {}) {
const { project } = context
options = {
externalizeAll: true,
skipRuntime: project.argv.skipRuntime || project.argv.disableRuntime,
entryPattern: project.argv.entryPattern,
...options,
}
const {
outputPath = project.join('app', 'main'),
publicPath = project.isDevelopment && project.argv.hot ? '/' : '',
skipRuntime,
entryPattern
} = options
return project
.compiler('node', options)
.config
.target('node')
.sourcemap('source-map')
.output({path: outputPath, publicPath, libraryTarget: 'umd'})
.node({ __dirname: false, __filename: false, process: false })
.when(() => entryPattern, (c) => c .entry( project.query(entryPattern, true).keyBy(d => d.baseRelativePath.replace('src/', '')).value() ) )
.loader('skypager-document', ['.md'], {
include: [project.paths.source],
exclude: [/node_modules/, project.paths.public, project.paths.output],
loader: 'skypager-document',
})
.when(() => project.existsSync(project.resolve(project.paths.public, 'assets', 'assets.js')), (cfg) => cfg
.plugin('webpack.ProvidePlugin', {
'AssetsRegistry': project.join(project.paths.public, 'assets', 'assets.js'),
})
)
.when(!skipRuntime, (cfg) => cfg.copy([{from:join(__dirname, '..', 'src', 'runtime')}]))
//.when(!skipRuntime, (cfg) => cfg.copy(join(__dirname, '..', 'lib', 'runtime.js')))
.plugin('webpack.DefinePlugin', {
__BROWSER__: JSON.stringify(false),
__ELECTRON_RENDERER__: JSON.stringify(false),
__ELECTRON_MAIN__: JSON.stringify(true),
__DEV__: JSON.stringify(!!project.isDevelopment)
})
}