2021-03-27 04:43:51 +03:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
2021-09-13 04:19:11 +03:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2021-03-27 04:43:51 +03:00
|
|
|
// const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
|
|
const urbitrc = require('./urbitrc');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
function copy(src,dest) {
|
|
|
|
return new Promise((res,rej) =>
|
|
|
|
fs.copy(src,dest, err => err ? rej(err) : res()));
|
|
|
|
}
|
|
|
|
|
|
|
|
class UrbitShipPlugin {
|
|
|
|
constructor(urbitrc) {
|
|
|
|
this.piers = urbitrc.URBIT_PIERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
apply(compiler) {
|
|
|
|
compiler.hooks.afterEmit.tapPromise(
|
|
|
|
'UrbitShipPlugin',
|
|
|
|
async (compilation) => {
|
|
|
|
const src = path.resolve(compiler.options.output.path, 'index.js');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let devServer = {
|
|
|
|
contentBase: path.join(__dirname, '../dist'),
|
|
|
|
hot: true,
|
|
|
|
port: 9000,
|
|
|
|
host: '0.0.0.0',
|
|
|
|
disableHostCheck: true,
|
|
|
|
historyApiFallback: true,
|
2021-09-13 04:19:11 +03:00
|
|
|
publicPath: '/apps/bitcoin/',
|
2021-03-27 04:43:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const router = _.mapKeys(urbitrc.FLEET || {}, (value, key) => `${key}.localhost:9000`);
|
|
|
|
|
|
|
|
if(urbitrc.URL) {
|
|
|
|
devServer = {
|
|
|
|
...devServer,
|
2021-09-13 04:19:11 +03:00
|
|
|
index: 'index.html',
|
|
|
|
proxy: [{
|
|
|
|
target: 'http://localhost:9000',
|
|
|
|
changeOrigin: true,
|
|
|
|
target: urbitrc.URL,
|
|
|
|
router,
|
|
|
|
context: path => {
|
|
|
|
if(path === '/apps/bitcoin/desk.js') {
|
|
|
|
return true;
|
2021-03-27 04:43:51 +03:00
|
|
|
}
|
2021-09-13 04:19:11 +03:00
|
|
|
return !path.startsWith('/apps/bitcoin')
|
2021-03-27 04:43:51 +03:00
|
|
|
}
|
2021-09-13 04:19:11 +03:00
|
|
|
}]
|
2021-03-27 04:43:51 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
node: { fs: 'empty' },
|
|
|
|
mode: 'development',
|
|
|
|
entry: {
|
|
|
|
app: './src/index.js'
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(j|t)sx?$/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: ['@babel/preset-env', ['@babel/preset-react', {
|
|
|
|
runtime: 'automatic',
|
|
|
|
development: 'true',
|
|
|
|
importSource: '@welldone-software/why-did-you-render',
|
|
|
|
}]],
|
|
|
|
plugins: [
|
|
|
|
'@babel/transform-runtime',
|
|
|
|
'@babel/plugin-proposal-object-rest-spread',
|
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
'react-hot-loader/babel'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
exclude: /node_modules/
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/i,
|
|
|
|
use: [
|
|
|
|
// Creates `style` nodes from JS strings
|
|
|
|
'style-loader',
|
|
|
|
// Translates CSS into CommonJS
|
|
|
|
'css-loader',
|
|
|
|
// Compiles Sass to CSS
|
|
|
|
'sass-loader'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.js', '.ts', '.tsx']
|
|
|
|
},
|
|
|
|
devtool: 'inline-source-map',
|
|
|
|
devServer: devServer,
|
|
|
|
plugins: [
|
2021-09-13 04:19:11 +03:00
|
|
|
new UrbitShipPlugin(urbitrc),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
title: 'Bitcoin Wallet',
|
|
|
|
template: './public/index.html'
|
|
|
|
})
|
|
|
|
|
2021-03-27 04:43:51 +03:00
|
|
|
],
|
|
|
|
watch: true,
|
|
|
|
watchOptions: {
|
|
|
|
poll: true,
|
|
|
|
ignored: '/node_modules/'
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: 'index.js',
|
|
|
|
chunkFilename: 'index.js',
|
|
|
|
path: path.resolve(__dirname, '../dist'),
|
2021-09-13 04:19:11 +03:00
|
|
|
publicPath: '/apps/bitcoin/',
|
2021-03-27 04:43:51 +03:00
|
|
|
globalObject: 'this'
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
minimize: false,
|
|
|
|
usedExports: true
|
|
|
|
}
|
|
|
|
};
|