1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-22 16:29:09 +01:00

switch to webpack

This commit is contained in:
Kyle Spearrin 2018-05-14 23:16:59 -04:00
parent 55ebf3ac64
commit ec049edfdf
9 changed files with 4319 additions and 58 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
node_modules
build
dist

4236
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,20 +15,35 @@
"url": "https://github.com/bitwarden/cli"
},
"license": "GPL-3.0",
"scripts": {},
"scripts": {
"clean": "rimraf dist/**/*",
"build": "webpack --config webpack.config.js",
"build:watch": "webpack --config webpack.config.js --watch",
"build:prod": "cross-env NODE_ENV=production webpack --config webpack.config.js",
"build:prod:watch": "cross-env NODE_ENV=production webpack --config webpack.config.js --watch",
"lint": "tslint src/**/*.ts spec/**/*.ts || true",
"lint:fix": "tslint src/**/*.ts spec/**/*.ts --fix"
},
"bin": {
"bw": "./src/bw.js"
"bw": "./bw.js"
},
"devDependencies": {
"@types/commander": "^2.12.2",
"@types/node": "^10.0.8"
"@types/node": "^10.0.8",
"clean-webpack-plugin": "^0.1.17",
"copy-webpack-plugin": "^4.2.0",
"cross-env": "^5.1.4",
"ts-loader": "^3.5.0",
"tslint": "^5.9.1",
"tslint-loader": "^3.5.3",
"ts-node": "^6.0.3",
"typescript": "^2.7.1",
"webpack": "^3.10.0"
},
"dependencies": {
"commander": "^2.15.1",
"node-fetch": "2.1.2",
"node-localstorage": "1.3.1",
"tsconfig-paths": "3.3.2",
"ts-node": "6.0.3",
"typescript": "^2.7.1"
"node-forge": "0.7.1",
"node-localstorage": "1.3.1"
}
}

View File

@ -1,6 +0,0 @@
#!/usr/bin/env node
require('tsconfig-paths').register();
require('ts-node').register();
const main = require('./main.ts');
new main.Main().run();

View File

@ -57,7 +57,7 @@ export class Main {
program: Program;
constructor() {
this.i18nService = new I18nService('en', '../locales');
this.i18nService = new I18nService('en', './locales');
this.platformUtilsService = new NodePlatformUtilsService();
this.cryptoFunctionService = new NodeCryptoFunctionService();
this.storageService = new NodeStorageService('Bitwarden CLI');
@ -89,6 +89,11 @@ export class Main {
this.program = new Program(this);
}
async run() {
await this.init();
this.program.run();
}
private async init() {
this.containerService.attachToWindow(global);
await this.environmentService.setUrlsFromStorage();
@ -96,13 +101,7 @@ export class Main {
await this.i18nService.init(locale);
await this.authService.init();
}
async run() {
await this.init();
this.program.run();
}
}
if (process.env.NODE_ENV === 'debug') {
new Main().run();
}
const main = new Main();
main.run();

View File

@ -1,13 +1,13 @@
import * as program from 'commander';
import { Main } from './bw';
import { DeleteCommand } from './commands/delete.command';
import { GetCommand } from './commands/get.command';
import { ListCommand } from './commands/list.command';
import { LoginCommand } from './commands/login.command';
import { SyncCommand } from './commands/sync.command';
import { Main } from './main';
import { Response } from './models/response';
import { CreateCommand } from './commands/create.command';
import { EncodeCommand } from './commands/encode.command';

View File

@ -13,7 +13,7 @@ export class I18nService extends BaseI18nService {
});
this.supportedTranslationLocales = [
'en'
'en',
];
}
}

View File

@ -2,8 +2,8 @@
"compilerOptions": {
"pretty": true,
"moduleResolution": "node",
"target": "ES6",
"module": "commonjs",
"target": "ES2016",
"module": "es6",
"noImplicitAny": true,
"allowJs": true,
"sourceMap": true,
@ -24,8 +24,7 @@
"jslib/dist",
"jslib/spec",
"jslib/src/electron",
"jslib/src/angular/components/modal.component.ts",
"jslib/src/angular/dummy.module.ts",
"jslib/src/angular",
"build"
]
}

74
webpack.config.js Normal file
View File

@ -0,0 +1,74 @@
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
if (process.env.NODE_ENV == null) {
process.env.NODE_ENV = 'development';
}
const ENV = process.env.ENV = process.env.NODE_ENV;
const isVendorModule = (module) => {
if (!module.context) {
return false;
}
return module.context.indexOf('node_modules') !== -1;
};
const moduleRules = [
{
test: /\.ts$/,
enforce: 'pre',
loader: 'tslint-loader',
},
{
test: /\.ts$/,
loaders: ['ts-loader'],
exclude: path.resolve(__dirname, 'node_modules'),
},
];
const plugins = [
new CleanWebpackPlugin([
path.resolve(__dirname, 'build/*'),
]),
new CopyWebpackPlugin([
'./package.json',
{ from: './src/locales', to: 'locales' },
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(ENV),
'process.env.DEBUG': JSON.stringify(process.env.DEBUG),
}),
new webpack.BannerPlugin({
banner: '#!/usr/bin/env node',
raw: true
}),
];
const config = {
target: 'node',
node: {
__dirname: false,
__filename: false,
},
entry: {
'bw': './src/bw.ts',
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
jslib: path.join(__dirname, 'jslib/src'),
},
symlinks: false,
modules: [path.resolve('node_modules')],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
},
module: { rules: moduleRules },
plugins: plugins,
};
module.exports = config;