1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-28 03:08:30 +00:00

WEBPACK 4

This commit is contained in:
Szymon Lesisz 2018-05-17 22:08:34 +02:00
parent 9efe52b568
commit 166e51525b
12 changed files with 3123 additions and 987 deletions

View File

@ -15,31 +15,24 @@
}, },
"license": "LGPL-3.0+", "license": "LGPL-3.0+",
"scripts": { "scripts": {
"dev": "babel-node ./webpack/server.js --connect", "dev": "webpack-dev-server --config ./webpack/config.dev.babel.js --mode development",
"dev:library": "babel-node ./webpack/server.js --library", "build": "rm -rf build && webpack --config ./webpack/config.prod.babel.js --progress",
"dev:connect": "babel-node ./webpack/server.js --connect",
"build": "rm -rf build && webpack --config ./webpack/webpack.config.prod.babel.js",
"flow": "flow check src/js", "flow": "flow check src/js",
"test": "" "test": ""
}, },
"dependencies": { "dependencies": {
"babel-preset-react": "^6.24.1",
"bowser": "^1.9.2",
"color-hash": "^1.0.3", "color-hash": "^1.0.3",
"ethereumjs-tx": "^1.3.3", "ethereumjs-tx": "^1.3.3",
"ethereumjs-units": "^0.2.0", "ethereumjs-units": "^0.2.0",
"ethereumjs-util": "^5.1.4", "ethereumjs-util": "^5.1.4",
"hdkey": "^0.8.0", "hdkey": "^0.8.0",
"path-to-regexp": "^2.1.0",
"raf": "^3.4.0", "raf": "^3.4.0",
"raven-js": "^3.22.3", "raven-js": "^3.22.3",
"rc-tooltip": "^3.7.0", "rc-tooltip": "^3.7.0",
"react": "^16.2.0", "react": "^16.2.0",
"react-blockies": "^1.2.2",
"react-css-transition": "^0.7.4", "react-css-transition": "^0.7.4",
"react-dom": "^16.2.0", "react-dom": "^16.2.0",
"react-ellipsis-text": "^1.0.0", "react-hot-loader": "4.2.0",
"react-hot-loader": "^3.1.3",
"react-qr-svg": "^2.1.0", "react-qr-svg": "^2.1.0",
"react-redux": "^5.0.7", "react-redux": "^5.0.7",
"react-router-dom": "^4.2.2", "react-router-dom": "^4.2.2",
@ -47,7 +40,7 @@
"react-scale-text": "^1.2.2", "react-scale-text": "^1.2.2",
"react-select": "^1.2.1", "react-select": "^1.2.1",
"react-transition-group": "^2.2.1", "react-transition-group": "^2.2.1",
"redux": "^3.7.2", "redux": "4.0.0",
"redux-logger": "^3.0.6", "redux-logger": "^3.0.6",
"redux-raven-middleware": "^1.2.0", "redux-raven-middleware": "^1.2.0",
"redux-thunk": "^2.2.0", "redux-thunk": "^2.2.0",
@ -56,29 +49,32 @@
}, },
"devDependencies": { "devDependencies": {
"babel-cli": "^6.24.1", "babel-cli": "^6.24.1",
"babel-loader": "^7.1.0", "babel-loader": "7.1.4",
"babel-plugin-root-import": "^5.1.0",
"babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-flow-strip-types": "^6.22.0", "babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0", "babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0", "babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-webpack-alias": "^2.1.2", "babel-plugin-webpack-alias": "^2.1.2",
"babel-preset-env": "^1.6.0", "babel-preset-env": "^1.6.0",
"copy-webpack-plugin": "^4.4.1", "babel-preset-react": "^6.24.1",
"css-loader": "^0.28.9", "copy-webpack-plugin": "4.5.1",
"css-loader": "0.28.11",
"express": "^4.15.3", "express": "^4.15.3",
"extract-text-webpack-plugin": "^3.0.0", "file-loader": "1.1.11",
"file-loader": "^1.1.9", "flow-bin": "0.72.0",
"flow-bin": "^0.69.0",
"flow-typed": "^2.4.0", "flow-typed": "^2.4.0",
"html-webpack-plugin": "^2.29.0", "html-webpack-plugin": "^3.2.0",
"json-loader": "^0.5.7", "json-loader": "^0.5.7",
"less": "^3.0.1", "less": "^3.0.1",
"less-loader": "^4.0.5", "less-loader": "4.1.0",
"mini-css-extract-plugin": "^0.4.0",
"open": "^0.0.5", "open": "^0.0.5",
"style-loader": "^0.20.2", "style-loader": "0.21.0",
"webpack": "3.11.0", "webpack": "^4.8.3",
"webpack-dev-middleware": "2.0.5", "webpack-cli": "^2.1.3",
"webpack-hot-middleware": "2.21.0", "webpack-dev-middleware": "^3.1.3",
"webpack-dev-server": "^3.1.4",
"webpack-merge": "^4.1.1", "webpack-merge": "^4.1.1",
"whatwg-fetch": "^2.0.3", "whatwg-fetch": "^2.0.3",
"yargs": "11.0.0" "yargs": "11.0.0"

View File

@ -19,3 +19,8 @@ window.onbeforeunload = () => {
// workaround for web3 // workaround for web3
// yarn add web3@^0.19.0 // yarn add web3@^0.19.0
//if (module && module.hot)
if (typeof module !== undefined && module.hasOwnProperty('hot')) {
// $FlowIssue
module.hot.accept();
}

View File

@ -1,7 +1,6 @@
/* @flow */ /* @flow */
'use strict'; 'use strict';
import pathToRegexp from 'path-to-regexp';
import { DEVICE } from 'trezor-connect'; import { DEVICE } from 'trezor-connect';
import { LOCATION_CHANGE, push, replace } from 'react-router-redux'; import { LOCATION_CHANGE, push, replace } from 'react-router-redux';
import * as CONNECT from '../actions/constants/TrezorConnect'; import * as CONNECT from '../actions/constants/TrezorConnect';

View File

@ -0,0 +1,79 @@
import { SRC, BUILD, PORT } from './constants';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
module.exports = {
watch: true,
mode: 'development',
devtool: 'inline-source-map',
entry: {
'index': [ 'react-hot-loader/patch', `${SRC}js/index.js` ]
},
output: {
filename: '[name].[hash].js',
path: BUILD,
publicPath: '/',
},
devServer: {
contentBase: SRC,
hot: true,
https: false,
port: PORT,
stats: 'minimal',
inline: true,
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'less-loader',
]
},
{
test: /\.(png|gif|jpg)$/,
loader: 'file-loader?name=./images/[name].[ext]'
},
{
test: /\.(ttf|eot|svg|woff|woff2)$/,
loader: 'file-loader',
query: {
name: './fonts/[name].[hash].[ext]',
},
},
]
},
resolve: {
modules: [SRC, 'node_modules'],
},
performance: {
hints: false
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
new HtmlWebpackPlugin({
chunks: ['index'],
template: `${SRC}index.html`,
filename: 'index.html',
inject: true
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
]
}

View File

@ -0,0 +1,88 @@
import { SRC, BUILD, PORT } from './constants';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
module.exports = {
mode: 'production',
entry: {
'index': [ `${SRC}js/index.js` ]
},
output: {
filename: 'js/[name].[hash].js',
path: BUILD,
publicPath: './',
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
// options: { minimize: true }
},
{
loader: 'less-loader',
// options: { minimize: true }
}
]
},
{
test: /\.(png|gif|jpg)$/,
exclude: /(node_modules)/,
loader: 'file-loader',
query: {
publicPath: '../',
name: 'images/[name].[hash].[ext]'
}
},
{
test: /\.(ttf|eot|svg|woff|woff2)$/,
loader: 'file-loader',
query: {
publicPath: '../',
name: 'fonts/[name].[hash].[ext]',
},
},
]
},
resolve: {
modules: [SRC, 'node_modules'],
},
performance: {
hints: false
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/[name].[hash].css',
}),
new HtmlWebpackPlugin({
chunks: ['index'],
template: `${SRC}index.html`,
filename: 'index.html',
inject: true
}),
new CopyWebpackPlugin([
//{from: `${SRC}/app/robots.txt`},
{ from: `${SRC}images/favicon.ico`, to: `${BUILD}favicon.ico` },
{ from: `${SRC}images/favicon.png`, to: `${BUILD}favicon.png` },
{ from: `${SRC}data`, to: `${BUILD}data`, cache: false },
{ from: `${SRC}assets`, to: `${BUILD}assets`, cache: false },
]),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
]
}

View File

@ -1,35 +0,0 @@
import express from 'express';
import webpack from 'webpack';
import open from 'open';
import { argv } from 'yargs';
import { SRC, PORT, INDEX, ABSOLUTE_BASE, TREZOR_CONNECT } from './constants';
//import config from './webpack.config.library';
const config = argv.connect ? require('./webpack.config.connect') : require('./webpack.config.dev');
const app = express();
const compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
contentBase: '/',
hot: true,
inline: true,
compress: true,
noInfo: false,
stats: { colors: true }
}));
app.use(require('webpack-hot-middleware')(compiler));
app.get('*', function(req, res) {
res.sendFile(SRC + req.params[0]);
});
app.listen(PORT, 'localhost', function(err) {
if (err) {
console.log(err);
return;
}
open(`http://localhost:${PORT}/`);
console.log(`Listening at http://localhost:${PORT}`);
console.log(`Serving ${INDEX}`);
});

View File

@ -1,130 +0,0 @@
import { SRC, BUILD, TREZOR_CONNECT, TREZOR_CONNECT_FILES, TREZOR_CONNECT_HTML } from './constants';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
const extractLess = new ExtractTextPlugin({
filename: 'css/[name].[contenthash].css',
//disable: process.env.NODE_ENV === 'development'
});
module.exports = {
entry: {
index: ['whatwg-fetch', `${SRC}js/index.js`]
},
output: {
filename: 'js/[name].[hash].js',
path: BUILD
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.less$/,
include: `${SRC}styles`,
loader: extractLess.extract({
use: [
{ loader: 'css-loader' },
{ loader: 'less-loader' }
],
fallback: 'style-loader'
})
},
{
test: /\.css$/,
loader: extractLess.extract({
use: [
{ loader: 'css-loader' }
],
fallback: 'style-loader'
})
},
{
test: /\.(png|gif|jpg)$/,
loader: 'file-loader',
query: {
publicPath: '../',
name: 'images/[name].[hash].[ext]',
}
},
{
test: /\.(ttf|eot|svg|woff|woff2)$/,
// loader: 'file-loader?publicPath=../&name=fonts/[name].[hash].[ext]',
loader: 'file-loader',
query: {
publicPath: '../',
name: 'fonts/[name].[hash].[ext]',
}
},
{
test: /\.(wasm)$/,
loader: 'file-loader',
query: {
name: 'js/[name].[hash].[ext]',
},
},
{
test: /\.json$/,
loader: 'json-loader'
},
]
},
resolve: {
modules: [SRC, 'node_modules'],
alias: {
'trezor-connect': `${TREZOR_CONNECT}`,
}
},
performance: {
hints: false
},
plugins: [
extractLess,
new HtmlWebpackPlugin({
template: `${SRC}index.html`,
inject: 'body',
}),
new CopyWebpackPlugin([
//{from: `${SRC}/app/robots.txt`},
//{ from: `${SRC}js/vendor`, to: `${BUILD}js/vendor` },
//{ from: `${SRC}config.json` },
//{ from: `${SRC}images/favicon.png`, to: `${BUILD}favicon.png` },
{ from: `${SRC}images/favicon.ico`, to: `${BUILD}favicon.ico` },
{ from: `${SRC}images/favicon.png`, to: `${BUILD}favicon.png` },
{ from: `${SRC}images/dashboard.png`, to: `${BUILD}images/dashboard.png` },
{ from: `${SRC}data`, to: `${BUILD}data`, cache: false },
]),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
// new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: false,
// }
// }),
new CopyWebpackPlugin([
{ from: `${TREZOR_CONNECT_FILES}config.json`, to: `${BUILD}/data/config.json` },
{ from: `${TREZOR_CONNECT_FILES}coins.json`, to: `${BUILD}/data/coins.json` },
{ from: `${TREZOR_CONNECT_FILES}releases-1.json`, to: `${BUILD}/data/releases-1.json` },
{ from: `${TREZOR_CONNECT_FILES}releases-2.json`, to: `${BUILD}/data/releases-2.json` },
{ from: `${TREZOR_CONNECT_FILES}latest.txt`, to: `${BUILD}/data/latest.txt` },
{ from: `${TREZOR_CONNECT_FILES}config_signed.bin`, to: `${BUILD}/data/config_signed.bin` },
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
PRODUCTION: JSON.stringify(false)
}),
new webpack.IgnorePlugin(/node-fetch/), // for trezor-link warning
],
// ignoring "fs" import in fastxpub
node: {
fs: "empty"
}
}

View File

@ -1,37 +0,0 @@
import { TREZOR_CONNECT, TREZOR_IFRAME, TREZOR_POPUP, TREZOR_CONNECT_FILES, TREZOR_CONNECT_HTML } from './constants';
import path from 'path';
import webpack from 'webpack';
import webpackMerge from 'webpack-merge';
import baseConfig from './webpack.config.dev';
import HtmlWebpackPlugin from 'html-webpack-plugin';
module.exports = webpackMerge(baseConfig, {
entry: {
'trezor-connect2': `${TREZOR_CONNECT}.js`,
'iframe': ['babel-polyfill', `${TREZOR_IFRAME}`],
'popup': `${TREZOR_POPUP}`,
},
resolve: {
alias: {
'trezor-connect': `${TREZOR_CONNECT}`,
}
},
plugins: [
new HtmlWebpackPlugin({
chunks: ['iframe'],
filename: `iframe.html`,
template: `${TREZOR_CONNECT_HTML}iframe.html`,
inject: true
}),
new HtmlWebpackPlugin({
chunks: ['popup'],
filename: 'popup.html',
template: `${TREZOR_CONNECT_HTML}popup.html`,
inject: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development-connect'),
PRODUCTION: JSON.stringify(false)
})
]
} );

View File

@ -1,112 +0,0 @@
import { TREZOR_CONNECT_FILES, TREZOR_CONNECT_HTML, SRC, PORT } from './constants';
import path from 'path';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
const extractLess = new ExtractTextPlugin({
filename: './[name].[contenthash].css',
// disable: process.env.NODE_ENV === 'development'
});
module.exports = {
devtool: 'inline-source-map',
entry: {
//'index': [ `${SRC}js/index.js`, `webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true&__webpack_public_path=http://webpack:${PORT}`]
'index': [ `${SRC}js/index.js`, `webpack-hot-middleware/client?path=/__webpack_hmr`]
},
output: {
filename: '[name].[hash].js',
path: '/',
publicPath: '/',
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.less$/,
loader: extractLess.extract({
use: [
{ loader: 'css-loader' },
{ loader: 'less-loader' }
],
fallback: 'style-loader'
})
},
{
test: /\.css$/,
loader: extractLess.extract({
use: [
{ loader: 'css-loader' }
],
fallback: 'style-loader'
})
},
{
test: /\.(png|gif|jpg)$/,
loader: 'file-loader?name=./images/[name].[ext]'
},
{
test: /\.(wasm)$/,
loader: 'file-loader',
query: {
name: 'js/[name].[ext]',
},
},
{
test: /\.json($|\?)/,
loader: 'json-loader'
},
{
test: /\.(ttf|eot|svg|woff|woff2)$/,
loader: 'file-loader',
query: {
name: './fonts/[name].[hash].[ext]',
},
},
]
},
resolve: {
modules: [SRC, 'node_modules'],
},
performance: {
hints: false
},
plugins: [
extractLess,
new HtmlWebpackPlugin({
chunks: ['index'],
template: `${SRC}index.html`,
filename: 'index.html',
inject: true
}),
new CopyWebpackPlugin([
{ from: `${TREZOR_CONNECT_FILES}config.json`, to: './data/config.json' },
{ from: `${TREZOR_CONNECT_FILES}coins.json`, to: './data/coins.json' },
{ from: `${TREZOR_CONNECT_FILES}releases-1.json`, to: './data/releases-1.json' },
{ from: `${TREZOR_CONNECT_FILES}latest.txt`, to: './data/latest.txt' },
{ from: `${TREZOR_CONNECT_FILES}config_signed.bin`, to: './data/config_signed.bin' },
// { from: `${SRC}images/favicon.png` },
// { from: `${SRC}images` },
]),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
PRODUCTION: JSON.stringify(false)
}),
new webpack.IgnorePlugin(/node-fetch/), // for trezor-link warning
],
// ignoring "fs" import in fastxpub
node: {
fs: "empty"
}
}

View File

@ -1,22 +0,0 @@
import { TREZOR_LIBRARY } from './constants';
import path from 'path';
import webpack from 'webpack';
import webpackMerge from 'webpack-merge';
import baseConfig from './webpack.config.dev';
module.exports = webpackMerge(baseConfig, {
entry: {
'trezor-library': `${TREZOR_LIBRARY}.js`
},
resolve: {
alias: {
'trezor-connect': `${TREZOR_LIBRARY}`,
}
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development-library'),
PRODUCTION: JSON.stringify(false)
})
]
} );

View File

@ -1,127 +0,0 @@
import { SRC, BUILD } from './constants';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
const extractLess = new ExtractTextPlugin({
filename: 'css/[name].[contenthash].css',
// disable: process.env.NODE_ENV === 'development'
});
module.exports = {
entry: {
index: ['whatwg-fetch', `${SRC}js/index.js`]
},
output: {
filename: 'js/[name].[hash].js',
path: BUILD
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.less$/,
include: `${SRC}styles`,
loader: extractLess.extract({
use: [
{
loader: 'css-loader',
options: { minimize: true }
},
{
loader: 'less-loader',
options: { minimize: true }
}
],
fallback: 'style-loader'
})
},
{
test: /\.css$/,
loader: extractLess.extract({
use: [
{
loader: 'css-loader',
options: { minimize: true }
}
],
fallback: 'style-loader'
})
},
{
test: /\.(png|gif|jpg)$/,
loader: 'file-loader',
query: {
publicPath: '../',
name: 'images/[name].[hash].[ext]',
}
},
{
test: /\.(ttf|eot|svg|woff|woff2)$/,
// loader: 'file-loader?publicPath=../&name=fonts/[name].[hash].[ext]',
loader: 'file-loader',
query: {
publicPath: '../',
name: 'fonts/[name].[hash].[ext]',
}
},
{
test: /\.(wasm)$/,
loader: 'file-loader',
query: {
name: 'js/[name].[hash].[ext]',
},
},
{
test: /\.json$/,
loader: 'json-loader'
},
]
},
resolve: {
modules: [SRC, 'node_modules']
},
performance: {
hints: false
},
plugins: [
extractLess,
new HtmlWebpackPlugin({
template: `${SRC}index.html`,
inject: 'body',
}),
new CopyWebpackPlugin([
//{from: `${SRC}/app/robots.txt`},
//{ from: `${SRC}js/vendor`, to: `${BUILD}js/vendor` },
//{ from: `${SRC}config.json` },
{ from: `${SRC}images/favicon.ico`, to: `${BUILD}favicon.ico` },
{ from: `${SRC}images/favicon.png`, to: `${BUILD}favicon.png` },
{ from: `${SRC}images/dashboard.png`, to: `${BUILD}images/dashboard.png` },
{ from: `${SRC}data`, to: `${BUILD}data`, cache: false },
]),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
}
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
PRODUCTION: JSON.stringify(false)
}),
new webpack.IgnorePlugin(/node-fetch/), // for trezor-link warning
],
// ignoring "fs" import in fastxpub
node: {
fs: "empty"
}
}

3430
yarn.lock

File diff suppressed because it is too large Load Diff