1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-30 20:28:09 +00:00
trezor-wallet/webpack/local.babel.js

177 lines
5.3 KiB
JavaScript
Raw Normal View History

2018-08-10 15:18:22 +00:00
import webpack from 'webpack';
2018-09-05 13:52:03 +00:00
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import GitRevisionPlugin from 'git-revision-webpack-plugin';
2018-08-10 15:18:22 +00:00
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
2018-10-09 13:20:57 +00:00
import MiniCssExtractPlugin from '../../trezor-connect/node_modules/mini-css-extract-plugin'; // eslint-disable-line
2018-09-05 13:52:03 +00:00
2018-08-08 09:41:08 +00:00
import {
TREZOR_CONNECT_ROOT,
TREZOR_CONNECT_HTML,
TREZOR_CONNECT_FILES,
2019-03-04 12:33:02 +00:00
TREZOR_CONNECT,
TREZOR_IFRAME,
TREZOR_POPUP,
TREZOR_WEBUSB,
2018-08-08 09:41:08 +00:00
SRC,
BUILD,
PUBLIC,
2019-02-15 19:56:15 +00:00
TRANSLATIONS,
2018-08-10 15:18:22 +00:00
PORT,
2018-08-08 09:41:08 +00:00
} from './constants';
const gitRevisionPlugin = new GitRevisionPlugin();
2018-08-08 09:41:08 +00:00
module.exports = {
watch: true,
mode: 'development',
devtool: 'inline-source-map',
entry: {
2018-08-27 15:15:22 +00:00
index: [`${SRC}/index.js`],
2018-08-08 09:41:08 +00:00
'trezor-connect-npm': `${TREZOR_CONNECT}.js`,
// 'extension-permissions': `${TREZOR_CONNECT_ROOT}src/js/extensionPermissions.js`,
2018-08-10 15:18:22 +00:00
iframe: TREZOR_IFRAME,
popup: TREZOR_POPUP,
webusb: TREZOR_WEBUSB,
2018-08-08 09:41:08 +00:00
},
output: {
filename: '[name].[hash].js',
path: BUILD,
globalObject: 'this', // fix for HMR inside WebWorker from 'hd-wallet'
},
devServer: {
2019-03-04 12:33:02 +00:00
contentBase: [SRC, PUBLIC],
2018-08-08 09:41:08 +00:00
hot: true,
https: false,
port: PORT,
stats: 'minimal',
inline: true,
},
module: {
rules: [
{
2018-09-05 13:52:03 +00:00
test: /\.js?$/,
2018-12-19 16:46:45 +00:00
exclude: [/node_modules/, /blockchain-link\/build\/workers/],
2018-09-13 07:27:09 +00:00
use: ['babel-loader'],
},
{
test: /\.less$/,
2018-09-05 13:52:03 +00:00
use: [
{
2018-09-13 07:27:09 +00:00
loader: MiniCssExtractPlugin.loader,
options: { publicPath: '../' },
2018-09-05 13:52:03 +00:00
},
2018-09-13 07:27:09 +00:00
`${TREZOR_CONNECT_ROOT}/node_modules/css-loader`,
`${TREZOR_CONNECT_ROOT}/node_modules/less-loader`,
2018-09-05 13:52:03 +00:00
],
2018-08-08 09:41:08 +00:00
},
{
test: /\.(png|gif|jpg)$/,
loader: 'file-loader?name=./images/[name].[ext]',
2019-02-05 14:06:59 +00:00
options: {
2018-08-08 09:41:08 +00:00
outputPath: './images',
name: '[name].[ext]',
2018-08-10 15:18:22 +00:00
},
2018-08-08 09:41:08 +00:00
},
{
test: /\.(ttf|eot|svg|woff|woff2)$/,
loader: 'file-loader',
2019-02-05 14:06:59 +00:00
options: {
2018-08-08 09:41:08 +00:00
outputPath: './fonts',
name: '[name].[ext]',
},
},
{
type: 'javascript/auto',
test: /\.json/,
2019-02-15 19:56:15 +00:00
exclude: [/(node_modules)/, TRANSLATIONS],
2018-08-08 09:41:08 +00:00
loader: 'file-loader',
2019-02-05 14:06:59 +00:00
options: {
2018-08-08 09:41:08 +00:00
outputPath: './data',
name: '[name].[ext]',
},
},
{
type: 'javascript/auto',
test: /\.wasm$/,
loader: 'file-loader',
2019-02-05 14:06:59 +00:00
options: {
2018-08-08 09:41:08 +00:00
name: 'js/[name].[ext]',
},
},
],
},
resolve: {
2019-03-04 12:33:02 +00:00
modules: [SRC, 'node_modules', `${TREZOR_CONNECT_ROOT}/node_modules`],
2018-08-08 09:41:08 +00:00
alias: {
public: PUBLIC,
2018-08-10 15:18:22 +00:00
'trezor-connect': `${TREZOR_CONNECT}`,
},
2018-08-08 09:41:08 +00:00
},
performance: {
2018-08-10 15:18:22 +00:00
hints: false,
2018-08-08 09:41:08 +00:00
},
plugins: [
2018-09-13 07:27:09 +00:00
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
2018-08-08 09:41:08 +00:00
new HtmlWebpackPlugin({
chunks: ['index'],
template: `${SRC}index.html`,
filename: 'index.html',
2018-08-10 15:18:22 +00:00
inject: true,
favicon: `${SRC}images/favicon.ico`,
2018-08-08 09:41:08 +00:00
}),
new HtmlWebpackPlugin({
chunks: ['iframe'],
2018-08-10 15:18:22 +00:00
filename: 'iframe.html',
2018-08-08 09:41:08 +00:00
template: `${TREZOR_CONNECT_HTML}iframe.html`,
2018-08-10 15:18:22 +00:00
inject: false,
2018-08-08 09:41:08 +00:00
}),
new HtmlWebpackPlugin({
chunks: ['popup'],
filename: 'popup.html',
template: `${TREZOR_CONNECT_HTML}popup.html`,
2018-08-10 15:18:22 +00:00
inject: false,
2018-08-08 09:41:08 +00:00
}),
new HtmlWebpackPlugin({
chunks: ['webusb'],
2018-08-10 15:18:22 +00:00
filename: 'webusb.html',
2018-08-08 09:41:08 +00:00
template: `${TREZOR_CONNECT_HTML}webusb.html`,
2018-08-10 15:18:22 +00:00
inject: true,
2018-08-08 09:41:08 +00:00
}),
// new HtmlWebpackPlugin({
// chunks: ['extension-permissions'],
// filename: `extension-permissions.html`,
// template: `${TREZOR_CONNECT_HTML}extension-permissions.html`,
// inject: true
// }),
2019-03-04 12:33:02 +00:00
new CopyWebpackPlugin([{ from: TREZOR_CONNECT_FILES, to: 'data' }]),
2018-09-05 13:52:03 +00:00
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: false, // turn on to generate bundle pass 'static'
reportFilename: 'bundle-report.html',
}),
2018-08-08 09:41:08 +00:00
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
LOCAL: JSON.stringify(`http://localhost:${PORT}/`),
COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
2018-08-08 09:41:08 +00:00
}),
// ignore node lib from trezor-link
new webpack.IgnorePlugin(/\/iconv-loader$/),
],
// ignoring "fs" import in fastxpub
node: {
2018-08-10 15:18:22 +00:00
fs: 'empty',
path: 'empty',
2018-08-08 09:41:08 +00:00
},
2019-03-04 12:33:02 +00:00
};