Browse Source
* it works * fixes * fixes * more fixes * rm copy-webpack-plugin * fixes * fixpull/1/head
3 changed files with 58 additions and 8 deletions
@ -1,15 +1,61 @@
|
||||
const webpack = require('webpack'); |
||||
const path = require('path'); |
||||
const fs = require('fs'); |
||||
|
||||
var base = require('./webpack.base.conf'); |
||||
|
||||
const nodeVersion = 'node-' + /[0-9]+/.exec(process.versions.node)[0]; |
||||
const PLATFORM = `${process.platform}-${process.arch}-${nodeVersion}`; |
||||
|
||||
const DEASYNC_NODE_MODULES_PATH = path.resolve( |
||||
'node_modules', |
||||
'deasync', |
||||
'bin', |
||||
PLATFORM |
||||
); |
||||
|
||||
const DEASYNC_DIST_PATH = path.resolve('dist', 'bin', PLATFORM); |
||||
|
||||
if(!fs.existsSync(DEASYNC_NODE_MODULES_PATH)) { |
||||
throw new Error(`deasync doesn't support this platform: ${PLATFORM}`); |
||||
} |
||||
|
||||
base.mode = 'production'; |
||||
|
||||
base.module.rules.push({ |
||||
base.externals = base.externals ? base.externals : []; |
||||
base.externals.push( |
||||
function (context, request, callback) { |
||||
if(request.indexOf('bindings') === 0) { |
||||
callback(null, `() => require('./deasync.node')`) |
||||
} else { |
||||
callback(); |
||||
} |
||||
} |
||||
); |
||||
|
||||
const prodRules = [ |
||||
{ |
||||
test: /\.node$/, |
||||
use: [ |
||||
{ loader: './build/node-loader' }, |
||||
{ loader: 'file-loader', options: { name: '[name].[ext]' } }, |
||||
{ loader: 'file-loader', options: { name: '[name].[ext]' } } |
||||
] |
||||
}); |
||||
} |
||||
]; |
||||
|
||||
let contextPathMapping = {}; |
||||
contextPathMapping[path.resolve(DEASYNC_DIST_PATH, 'deasync')] = './deasync.node'; |
||||
|
||||
const prodPlugins = [ |
||||
new webpack.ContextReplacementPlugin( |
||||
/deasync/, |
||||
DEASYNC_NODE_MODULES_PATH, |
||||
contextPathMapping |
||||
) |
||||
]; |
||||
|
||||
base.module.rules = [...base.module.rules, ...prodRules]; |
||||
base.plugins = [...base.plugins, ...prodPlugins]; |
||||
|
||||
module.exports = base; |
||||
|
||||
|
Loading…
Reference in new issue