Browse Source

Fix deasync production build failure (#777)

* it works

* fixes

* fixes

* more fixes

* rm copy-webpack-plugin

* fixes

* fix
pull/1/head
rozetko 5 years ago committed by Alexey Velikiy
parent
commit
4e344cba38
  1. 2
      server/build/node-loader.js
  2. 4
      server/build/webpack.614.prod.conf.js
  3. 60
      server/build/webpack.prod.conf.js

2
server/build/node-loader.js

@ -10,4 +10,4 @@ module.exports = function nodeLoader(m, q) {
throw new Error('dlopen: Cannot open ' + modulePath + ': ' + e); throw new Error('dlopen: Cannot open ' + modulePath + ': ' + e);
} }
`); `);
} }

4
server/build/webpack.614.prod.conf.js

@ -18,6 +18,10 @@ module.exports = {
test: /\.js$/, test: /\.js$/,
use: [ use: [
{ loader: 'babel-loader' } { loader: 'babel-loader' }
],
test: /\.node$/,
use: [
{ loader: './build/node-loader' }
] ]
} }
] ]

60
server/build/webpack.prod.conf.js

@ -1,15 +1,61 @@
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
var base = require('./webpack.base.conf'); 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.mode = 'production';
base.module.rules.push({ base.externals = base.externals ? base.externals : [];
test: /\.node$/, base.externals.push(
use: [ function (context, request, callback) {
{ loader: './build/node-loader' }, if(request.indexOf('bindings') === 0) {
{ loader: 'file-loader', options: { name: '[name].[ext]' } }, callback(null, `() => require('./deasync.node')`)
] } else {
}); callback();
}
}
);
const prodRules = [
{
test: /\.node$/,
use: [
{ loader: './build/node-loader' },
{ 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; module.exports = base;

Loading…
Cancel
Save