shrub/pkg/btc-wallet/config/webpack.dev.js

117 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-03-27 04:43:51 +03:00
const path = require('path');
const webpack = require('webpack');
// const HtmlWebpackPlugin = require('html-webpack-plugin');
// const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const urbitrc = require('./urbitrc');
const fs = require('fs-extra');
const _ = require('lodash');
2021-08-01 00:18:40 +03:00
function copy(src, dest) {
return new Promise((res, rej) =>
fs.copy(src, dest, (err) => (err ? rej(err) : res()))
);
2021-03-27 04:43:51 +03:00
}
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-08-01 00:18:40 +03:00
const router = _.mapKeys(
urbitrc.FLEET || {},
(value, key) => `${key}.localhost:9000`
);
2021-03-27 04:43:51 +03:00
2021-08-01 00:18:40 +03:00
if (urbitrc.URL) {
2021-03-27 04:43:51 +03:00
devServer = {
...devServer,
index: '',
proxy: {
2021-05-28 07:16:55 +03:00
'/~btc/js/bundle/index.*.js': {
2021-03-27 04:43:51 +03:00
target: 'http://localhost:9000',
pathRewrite: (req, path) => {
2021-08-01 00:18:40 +03:00
return '/index.js';
},
2021-03-27 04:43:51 +03:00
},
'**': {
changeOrigin: true,
target: urbitrc.URL,
router,
// ensure proxy doesn't timeout channels
2021-08-01 00:18:40 +03:00
proxyTimeout: 0,
},
},
2021-03-27 04:43:51 +03:00
};
}
module.exports = {
node: { fs: 'empty' },
mode: 'development',
entry: {
2021-08-01 00:18:40 +03:00
app: './src/index.tsx',
2021-03-27 04:43:51 +03:00
},
module: {
rules: [
{
test: /\.(j|t)sx?$/,
use: {
2021-08-01 00:18:40 +03:00
loader: 'ts-loader',
2021-03-27 04:43:51 +03:00
},
2021-08-01 00:18:40 +03:00
exclude: /node_modules/,
2021-03-27 04:43:51 +03:00
},
{
test: /\.css$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
'css-loader',
// Compiles Sass to CSS
2021-08-01 00:18:40 +03:00
'sass-loader',
],
},
],
2021-03-27 04:43:51 +03:00
},
resolve: {
2021-08-01 00:18:40 +03:00
extensions: ['.js', '.ts', '.tsx'],
2021-03-27 04:43:51 +03:00
},
devtool: 'inline-source-map',
devServer: devServer,
2021-08-01 00:18:40 +03:00
plugins: [new UrbitShipPlugin(urbitrc)],
2021-03-27 04:43:51 +03:00
watch: true,
watchOptions: {
poll: true,
2021-08-01 00:18:40 +03:00
ignored: '/node_modules/',
2021-03-27 04:43:51 +03:00
},
output: {
filename: 'index.js',
chunkFilename: 'index.js',
path: path.resolve(__dirname, '../dist'),
publicPath: '/',
2021-08-01 00:18:40 +03:00
globalObject: 'this',
2021-03-27 04:43:51 +03:00
},
optimization: {
minimize: false,
2021-08-01 00:18:40 +03:00
usedExports: true,
},
2021-03-27 04:43:51 +03:00
};