1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-21 11:35:34 +01:00

Setup Webpack & TypeScript (#316)

* TypeScript and WebPack.

* Minor cleanup.

* Add background.js as entry point to webpack.

* Use downloaded fonts for better performance.
Remove google-fonts-webpack-plugin.

* Add the remaining entry points and setup notification bar.

* Update readme for webpack.

* Convert CipherItems to TypeScript to demonstrate how a component looks in TS.

* Fix edge requirering a custom angular version.

* Rewrite gulp tasks for packaging releases.

* Re-add the webpack gulp plugin.

* Remove unessesary line in analytics.
This commit is contained in:
Oscar Hinton 2017-10-29 03:14:14 +01:00 committed by Kyle Spearrin
parent e57f3fe5f0
commit 59754cd530
36 changed files with 574 additions and 34585 deletions

16
.editorconfig Normal file
View File

@ -0,0 +1,16 @@
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,ts,less}]
charset = utf-8
indent_style = space
indent_size = 4

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ webfonts/
*.crx
*.pem
*.zip
releases/

View File

@ -30,16 +30,17 @@ Then run the following commands:
- `npm install`
- `gulp build`
- `npm run dev:watch`
You can now load the extension into your browser through the browser's extension tools page:
- Chrome/Opera:
1. Type `chrome://extensions` in your address bar to bring up the extensions page.
2. Enable developer mode (checkbox)
3. Click the "Load unpacked extension" button, navigate to the `src` folder of your local extension instance, and click "Ok".
3. Click the "Load unpacked extension" button, navigate to the `dist` folder of your local extension instance, and click "Ok".
- Firefox
1. Type `about:debugging` in your address bar to bring up the add-ons page.
2. Click the `Load Temporary Add-on` button, navigate to the `src/manifest.json` file, and "Open".
2. Click the `Load Temporary Add-on` button, navigate to the `dist/manifest.json` file, and "Open".
# Contribute

View File

@ -1,9 +1,7 @@
var gulp = require('gulp'),
const gulp = require('gulp'),
gulpif = require('gulp-if'),
replace = require('gulp-replace'),
rimraf = require('rimraf'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
less = require('gulp-less'),
preprocess = require('gulp-preprocess'),
runSequence = require('run-sequence'),
jshint = require('gulp-jshint'),
merge = require('merge-stream'),
@ -12,21 +10,131 @@
googleWebFonts = require('gulp-google-webfonts'),
webpack = require('webpack-stream'),
jeditor = require("gulp-json-editor"),
gulpUtil = require('gulp-util'),
child = require('child_process'),
zip = require('gulp-zip'),
manifest = require('./src/manifest.json'),
xmlpoke = require('gulp-xmlpoke'),
embedTemplates = require('gulp-angular-embed-templates');
xmlpoke = require('gulp-xmlpoke');
var paths = {};
const paths = {};
paths.releases = './releases/';
paths.dist = './dist/';
paths.libDir = './src/lib/';
paths.npmDir = './node_modules/';
paths.popupDir = './src/popup/';
paths.lessDir = paths.popupDir + 'less/';
paths.cssDir = paths.popupDir + 'css/';
const sidebarActionManifestObj = {
"default_title": "bitwarden",
"default_panel": "popup/index.html?uilocation=sidebar",
"default_icon": "images/icon19.png"
};
function dist(browserName, manifest) {
return gulp.src(paths.dist + '**/*')
.pipe(gulpif('popup/index.html', replace('__BROWSER__', browserName)))
.pipe(gulpif('manifest.json', jeditor(manifest)))
.pipe(zip(`dist-${browserName}.zip`))
.pipe(gulp.dest(paths.releases));
}
gulp.task('dist:firefox', function (cb) {
return dist('firefox', function (manifest) {
manifest.applications = {
gecko: {
id: '{446900e4-71c2-419f-a6a7-df9c091e268b}',
strict_min_version: '42.0'
}
};
manifest['sidebar_action'] = sidebarActionManifestObj;
return manifest;
});
});
gulp.task('dist:opera', function (cb) {
return dist('opera', function (manifest) {
manifest['sidebar_action'] = sidebarActionManifestObj;
return manifest;
});
});
gulp.task('dist:chrome', function (cb) {
return dist('chrome', function (manifest) {
return manifest;
});
})
// Since Edge extensions require makeappx to be run we temporarily store it in a folder.
gulp.task('dist:edge', function (cb) {
const edgePath = paths.releases + 'Edge/';
const extensionPath = edgePath + 'Extension/';
copyDistEdge(paths.dist + '**/*', extensionPath)
.then(copyAssetsEdge('./store/windows/**/*', edgePath))
.then(function () {
// makeappx.exe must be in your system's path already
child.spawn('makeappx.exe', ['pack', '/h', 'SHA256', '/d', edgePath, '/p', paths.releases + 'bitwarden.appx']);
cb();
}, function () {
cb();
});
});
function copyDistEdge(source, dest) {
return new Promise(function (resolve, reject) {
gulp.src(source)
.on('error', reject)
.pipe(gulpif('popup/index.html', replace('__BROWSER__', 'edge')))
.pipe(gulpif('manifest.json', jeditor(function (manifest) {
manifest['-ms-preload'] = {
backgroundScript: 'edge/backgroundScriptsAPIBridge.js',
contentScript: 'edge/contentScriptsAPIBridge.js'
};
return manifest;
})))
.pipe(gulp.dest(dest))
.on('end', resolve);
});
}
function copyAssetsEdge(source, dest) {
return new Promise(function (resolve, reject) {
gulp.src(source)
.on('error', reject)
.pipe(gulpif('AppxManifest.xml', xmlpoke({
replacements: [{
xpath: '/p:Package/p:Identity/@Version',
value: manifest.version + '.0',
namespaces: {
'p': 'http://schemas.microsoft.com/appx/manifest/foundation/windows10'
}
}]
})))
.pipe(gulp.dest(dest))
.on('end', resolve);
});
}
gulp.task('build', function (cb) {
return runSequence(
'clean',
['browserify', 'webpack', 'lib', 'lint', 'webfonts'],
cb);
});
gulp.task('webfonts', function () {
return gulp.src('./webfonts.list')
.pipe(googleWebFonts({
fontsDir: 'webfonts',
cssFilename: 'webfonts.css'
}))
.pipe(gulp.dest(paths.cssDir));
});
// LEGACY CODE!
//
// Needed untill background.js is converted into a proper webpack compatible file.
gulp.task('lint', function () {
return gulp.src([
paths.popupDir + '**/*.js',
@ -38,97 +146,27 @@ gulp.task('lint', function () {
'./src/overlay/**/*.js',
'./src/background.js'
])
.pipe(jshint())
.pipe(jshint({
esversion: 6
}))
.pipe(jshint.reporter('default'));
});
gulp.task('build', function (cb) {
return runSequence(
'clean',
['browserify', 'webpack', 'lib', 'less', 'lint', 'webfonts'],
cb);
});
gulp.task('clean:css', function (cb) {
return rimraf(paths.cssDir, cb);
});
gulp.task('clean:lib', function (cb) {
return rimraf(paths.libDir, cb);
});
gulp.task('clean', ['clean:css', 'clean:lib']);
gulp.task('clean', ['clean:lib']);
gulp.task('lib', ['clean:lib'], function () {
var libs = [
{
src: [
paths.npmDir + 'bootstrap/dist/**/*',
'!' + paths.npmDir + 'bootstrap/dist/**/npm.js',
'!' + paths.npmDir + 'bootstrap/dist/**/css/*theme*',
'!' + paths.npmDir + 'bootstrap/**/*.min*'
],
dest: paths.libDir + 'bootstrap'
},
{
src: paths.npmDir + 'font-awesome/css/font-awesome.css',
dest: paths.libDir + 'font-awesome/css'
},
{
src: paths.npmDir + 'font-awesome/fonts/*',
dest: paths.libDir + 'font-awesome/fonts'
},
{
src: paths.npmDir + 'jquery/dist/jquery.js',
dest: paths.libDir + 'jquery'
},
{
src: paths.npmDir + 'angular/angular.js',
dest: paths.libDir + 'angular'
},
{
src: paths.npmDir + 'angular-animate/angular-animate.js',
dest: paths.libDir + 'angular-animate'
},
{
src: paths.npmDir + 'angular-ui-router/release/angular-ui-router.js',
dest: paths.libDir + 'angular-ui-router'
},
{
src: [paths.npmDir + 'angular-toastr/dist/angular-toastr.tpls.js',
paths.npmDir + 'angular-toastr/dist/angular-toastr.css'],
dest: paths.libDir + 'angular-toastr'
},
{
src: paths.npmDir + 'ngclipboard/dist/ngclipboard.js',
dest: paths.libDir + 'ngclipboard'
},
{
src: paths.npmDir + 'clipboard/dist/clipboard.js',
dest: paths.libDir + 'clipboard'
},
{
src: paths.npmDir + 'q/q.js',
dest: paths.libDir + 'q'
},
{
src: [paths.npmDir + 'sweetalert/dist/sweetalert.css', paths.npmDir + 'sweetalert/dist/sweetalert-dev.js',
paths.npmDir + 'angular-sweetalert/SweetAlert.js'],
dest: paths.libDir + 'sweetalert'
},
{
src: [paths.npmDir + 'angulartics-google-analytics/lib/angulartics*.js',
paths.npmDir + 'angulartics/src/angulartics.js'
],
dest: paths.libDir + 'angulartics'
},
{
src: paths.npmDir + 'ng-infinite-scroll/build/ng-infinite-scroll.js',
dest: paths.libDir + 'ng-infinite-scroll'
},
{
src: paths.npmDir + 'papaparse/papaparse.js',
dest: paths.libDir + 'papaparse'
}
];
@ -174,353 +212,3 @@ gulp.task('webpack:forge', function () {
}
})).pipe(gulp.dest(paths.libDir + 'forge'));
});
gulp.task('less', function () {
return gulp.src(paths.lessDir + 'popup.less')
.pipe(less())
.pipe(gulp.dest(paths.cssDir));
});
gulp.task('watch', function () {
gulp.watch(paths.lessDir + '*.less', ['less']);
});
gulp.task('dist:clean', function (cb) {
return rimraf(paths.dist + '**/*', cb);
});
gulp.task('dist:move', function () {
var moves = [
{
src: 'src/_locales/**/*',
dest: paths.dist + '_locales'
},
{
src: [
'src/content/**/*',
'!src/content/field.js',
'!src/content/overlay.js'
],
dest: paths.dist + 'content'
},
{
src: 'src/images/**/*',
dest: paths.dist + 'images'
},
{
src: 'src/notification/**/*',
dest: paths.dist + 'notification'
},
{
src: 'src/popup/index.html',
dest: paths.dist + 'popup'
},
{
src: 'src/popup/css/webfonts/**/*',
dest: paths.dist + 'popup/css/webfonts'
},
{
src: paths.libDir + 'font-awesome/fonts/**/*',
dest: paths.dist + 'popup/fonts'
},
{
src: 'src/services/**/*',
dest: paths.dist + 'services'
},
{
src: paths.libDir + 'forge/**/*',
dest: paths.dist + 'lib/forge'
},
{
src: paths.libDir + 'jquery/**/*',
dest: paths.dist + 'lib/jquery'
},
{
src: paths.libDir + 'tldjs/**/*',
dest: paths.dist + 'lib/tldjs'
},
{
src: paths.libDir + 'q/**/*',
dest: paths.dist + 'lib/q'
},
{
src: 'src/models/**/*',
dest: paths.dist + 'models'
},
{
src: 'src/scripts/analytics.js',
dest: paths.dist + 'scripts'
},
{
src: [
'src/background.*',
'src/manifest.json'
],
dest: paths.dist
}
];
var tasks = moves.map(function (move) {
return gulp.src(move.src).pipe(gulp.dest(move.dest));
});
return merge(tasks);
});
gulp.task('dist:css', function () {
distCss({});
});
gulp.task('dist:css:edge', function () {
distCss({ edge: true });
});
gulp.task('dist:css:firefox', function () {
distCss({ firefox: true });
});
function distCss(preprocessContext) {
return gulp
.src([
// libs
paths.libDir + '**/*.css',
'!' + paths.libDir + '**/*.min.css',
// app
paths.cssDir + 'popup.css',
paths.cssDir + 'webfonts.css'
])
.pipe(preprocess({ context: preprocessContext }))
.pipe(concat(paths.dist + 'popup/css/popup.css'))
.pipe(gulp.dest('.'));
}
gulp.task('dist:js', function () {
return distJs(false);
});
gulp.task('dist:js:edge', function () {
return distJs(true);
});
function distJs(edge) {
var appTask = gulp
.src([
// models/scripts
'./src/models/**/*.js',
'./src/scripts/*.js',
// app
paths.popupDir + 'app/app.js',
paths.popupDir + 'app/**/*Module.js',
paths.popupDir + 'app/**/*.js'
])
.pipe(embedTemplates({
basePath: './src/popup/',
minimize: { empty: true }
}))
.pipe(concat(paths.dist + 'popup/app.js'))
.pipe(gulp.dest('.'));
var libTask = gulp
.src([
paths.libDir + 'jquery/jquery.js',
paths.libDir + 'bootstrap/js/bootstrap.js',
edge ? './src/edge/angular.js' : (paths.libDir + 'angular/angular.js'),
paths.libDir + '**/*.js',
'!' + paths.libDir + 'q/**/*',
'!' + paths.libDir + 'tldjs/**/*',
'!' + paths.libDir + 'forge/**/*',
'!' + paths.libDir + '**/*.min.js'
])
.pipe(concat(paths.dist + 'popup/lib.js'))
.pipe(gulp.dest('.'));
return merge(appTask, libTask);
}
gulp.task('dist:preprocess', function () {
return gulp
.src([
paths.dist + 'popup/index.html'
], { base: '.' })
.pipe(preprocess({ context: {} }))
.pipe(gulp.dest('.'));
});
gulp.task('dist', ['build'], function (cb) {
return dist({}, cb);
});
gulp.task('dist:edge', ['build'], function (cb) {
return dist({ edge: true }, cb);
});
gulp.task('dist:firefox', ['build'], function (cb) {
return dist({ firefox: true }, cb);
});
function dist(o, cb) {
var distCss = o.edge ? 'dist:css:edge' : o.firefox ? 'dist:css:firefox' : 'dist:css';
var distJs = o.edge ? 'dist:js:edge' : 'dist:js';
return runSequence(
'dist:clean',
['dist:move', distCss, distJs],
'dist:preprocess',
cb);
}
var sidebarActionManifestObj = {
"default_title": "bitwarden",
"default_panel": "popup/index.html?uilocation=sidebar",
"default_icon": "images/icon19.png"
};
gulp.task('dist-firefox', ['dist:firefox'], function (cb) {
gulp.src(paths.dist + 'manifest.json')
.pipe(jeditor(function (manifest) {
manifest.applications = {
gecko: {
id: '{446900e4-71c2-419f-a6a7-df9c091e268b}',
strict_min_version: '42.0'
}
};
manifest['sidebar_action'] = sidebarActionManifestObj;
return manifest;
}))
.pipe(gulp.dest(paths.dist));
return zipDist('dist-firefox');
});
gulp.task('dist-opera', ['dist'], function (cb) {
gulp.src(paths.dist + 'manifest.json')
.pipe(jeditor(function (manifest) {
manifest['sidebar_action'] = sidebarActionManifestObj;
return manifest;
}))
.pipe(gulp.dest(paths.dist));
return zipDist('dist-opera');
});
gulp.task('dist-edge', ['dist:edge'], function (cb) {
// move dist to temp extension folder
new Promise(function (resolve, reject) {
gulp.src(paths.dist + '**/*')
.on('error', reject)
.pipe(gulp.dest('temp/Extension/'))
.on('end', resolve);
}).then(function () {
// move windows store files to temp folder
return new Promise(function (resolve, reject) {
gulp.src('store/windows/**/*')
.on('error', reject)
.pipe(gulp.dest('temp/'))
.on('end', resolve);
});
}).then(function () {
// delete dist folder
return new Promise(function (resolve, reject) {
rimraf(paths.dist, function () {
resolve();
})
});
}).then(function () {
// move temp back to dist
return new Promise(function (resolve, reject) {
gulp.src('temp/**/*')
.on('error', reject)
.pipe(gulp.dest(paths.dist))
.on('end', resolve);
});
}).then(function () {
// delete temp folder
return new Promise(function (resolve, reject) {
rimraf('temp', function () {
resolve();
})
});
}).then(function () {
// move src edge folder to dist
return new Promise(function (resolve, reject) {
gulp.src(['src/edge/**/*', '!src/edge/angular.js'])
.on('error', reject)
.pipe(gulp.dest(paths.dist + 'Extension/edge'))
.on('end', resolve);
});
}).then(function () {
// modify manifest with edge preload stuff
return new Promise(function (resolve, reject) {
gulp.src(paths.dist + 'Extension/manifest.json')
.pipe(jeditor(function (manifest) {
manifest['-ms-preload'] = {
backgroundScript: 'edge/backgroundScriptsAPIBridge.js',
contentScript: 'edge/contentScriptsAPIBridge.js'
};
return manifest;
}))
.on('error', reject)
.pipe(gulp.dest(paths.dist + 'Extension'))
.on('end', resolve);
});
}).then(function () {
// modify appxmanifest
return new Promise(function (resolve, reject) {
gulp.src(paths.dist + '/AppxManifest.xml')
.pipe(xmlpoke({
replacements: [{
xpath: '/p:Package/p:Identity/@Version',
value: manifest.version + '.0',
namespaces: {
'p': 'http://schemas.microsoft.com/appx/manifest/foundation/windows10'
}
}]
}))
.on('error', reject)
.pipe(gulp.dest(paths.dist))
.on('end', resolve);
});
}).then(function () {
// makeappx.exe must be in your system's path already
child.spawn('makeappx.exe', ['pack', '/h', 'SHA256', '/d', paths.dist, '/p', paths.dist + 'bitwarden.appx']);
cb();
}, function () {
cb();
});
});
gulp.task('dist-other', ['dist'], function (cb) {
return zipDist('dist-other');
});
function zipDist(fileName) {
return gulp.src(paths.dist + '**/*')
.pipe(zip(fileName + '.zip'))
.pipe(gulp.dest(paths.dist));
}
gulp.task('webfonts', function () {
return gulp.src('./webfonts.list')
.pipe(googleWebFonts({
fontsDir: 'webfonts',
cssFilename: 'webfonts.css'
}))
.pipe(gulp.dest(paths.cssDir));
});
function npmCommand(commands, cb) {
var npmLogger = (buffer) => {
buffer.toString()
.split(/\n/)
.forEach((message) => gulpUtil.log(message));
};
var npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
var npmChild = child.spawn(npmCommand, commands);
npmChild.stdout.on('data', npmLogger);
npmChild.stderr.on('data', npmLogger);
npmChild.stderr.on('close', cb);
return npmChild;
}
gulp.task('webext:firefox', function (cb) {
return npmCommand(['run', 'start:firefox'], cb);
});

View File

@ -2,7 +2,10 @@
"name": "bitwarden",
"version": "0.0.0",
"scripts": {
"start:firefox": "web-ext run --source-dir ./dist/"
"start:firefox": "web-ext run --source-dir ./dist/",
"dev": "webpack --config webpack.dev.js",
"dev:watch": "webpack --config webpack.dev.js --watch",
"prod": "webpack --config webpack.prod.js"
},
"devDependencies": {
"angular": "1.6.6",
@ -15,22 +18,28 @@
"bootstrap": "3.3.7",
"browserify": "14.4.0",
"child_process": "1.0.2",
"clean-webpack-plugin": "^0.1.17",
"clipboard": "1.7.1",
"copy-webpack-plugin": "^4.2.0",
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.1",
"file-loader": "^1.1.5",
"font-awesome": "4.7.0",
"gulp": "3.9.1",
"gulp-angular-embed-templates": "2.3.0",
"gulp-concat": "2.6.1",
"gulp-google-webfonts": "0.0.14",
"gulp-if": "^2.0.2",
"gulp-jshint": "2.0.4",
"gulp-json-editor": "2.2.1",
"gulp-less": "3.3.2",
"gulp-preprocess": "2.0.0",
"gulp-rename": "1.2.2",
"gulp-util": "3.0.8",
"gulp-replace": "^0.6.1",
"gulp-xmlpoke": "0.2.1",
"gulp-zip": "4.0.0",
"html-loader": "^0.5.1",
"html-webpack-plugin": "^2.30.1",
"jquery": "3.2.1",
"jshint": "2.9.5",
"less": "^3.0.0-alpha.3",
"less-loader": "^4.0.5",
"merge-stream": "1.0.1",
"ng-infinite-scroll": "1.3.0",
"ngclipboard": "1.1.1",
@ -38,11 +47,19 @@
"papaparse": "4.3.5",
"q": "1.5.0",
"rimraf": "2.6.1",
"run-sequence": "2.1.0",
"run-sequence": "^2.2.0",
"style-loader": "^0.19.0",
"sweetalert": "1.1.3",
"tldjs": "2.0.0",
"ts-loader": "^3.0.5",
"typescript": "^2.5.3",
"vinyl-source-stream": "1.1.0",
"web-ext": "2.0.0",
"webpack": "^3.8.1",
"webpack-merge": "^4.1.0",
"webpack-stream": "4.0.0"
},
"dependencies": {
"@types/angular": "^1.6.34"
}
}

View File

@ -18,15 +18,12 @@
<script type="text/javascript" src="services/settingsService.js"></script>
<script type="text/javascript" src="services/folderService.js"></script>
<script type="text/javascript" src="services/cipherService.js"></script>
<script type="text/javascript" src="services/lockService.js"></script>
<script type="text/javascript" src="services/syncService.js"></script>
<script type="text/javascript" src="services/autofillService.js"></script>
<script type="text/javascript" src="services/appIdService.js"></script>
<script type="text/javascript" src="services/passwordGenerationService.js"></script>
<script type="text/javascript" src="services/totpService.js"></script>
<script type="text/javascript" src="services/environmentService.js"></script>
<script type="text/javascript" src="background.js"></script>
<script type="text/javascript" src="scripts/analytics.js"></script>
</head>
<body>
</body>

View File

@ -1,3 +1,5 @@
import LockService from './services/lockService.js';
var bg_isBackground = true,
bg_utilsService,
bg_i18nService,
@ -28,28 +30,30 @@ var bg_isBackground = true,
bg_sidebarAction = (typeof opr !== 'undefined') && opr.sidebarAction ? opr.sidebarAction : chrome.sidebarAction;
// init services
bg_utilsService = new UtilsService();
bg_i18nService = new i18nService(bg_utilsService);
bg_constantsService = new ConstantsService(bg_i18nService);
bg_cryptoService = new CryptoService(bg_constantsService, bg_utilsService);
bg_tokenService = new TokenService(bg_utilsService);
bg_appIdService = new AppIdService(bg_utilsService);
bg_apiService = new ApiService(bg_tokenService, bg_appIdService, bg_utilsService, bg_constantsService, logout);
bg_environmentService = new EnvironmentService(bg_constantsService, bg_apiService);
bg_userService = new UserService(bg_tokenService, bg_apiService, bg_cryptoService, bg_utilsService);
bg_settingsService = new SettingsService(bg_userService, bg_utilsService);
bg_cipherService = new CipherService(bg_cryptoService, bg_userService, bg_apiService, bg_settingsService, bg_utilsService,
window.bg_utilsService = bg_utilsService = new UtilsService();
window.bg_i18nService = bg_i18nService = new i18nService(bg_utilsService);
window.bg_constantsService = bg_constantsService = new ConstantsService(bg_i18nService);
window.bg_cryptoService = bg_cryptoService = new CryptoService(bg_constantsService, bg_utilsService);
window.bg_tokenService = bg_tokenService = new TokenService(bg_utilsService);
window.bg_appIdService = bg_appIdService = new AppIdService(bg_utilsService);
window.bg_apiService = bg_apiService = new ApiService(bg_tokenService, bg_appIdService, bg_utilsService, bg_constantsService, logout);
window.bg_environmentService = bg_environmentService = new EnvironmentService(bg_constantsService, bg_apiService);
window.bg_userService = bg_userService = new UserService(bg_tokenService, bg_apiService, bg_cryptoService, bg_utilsService);
window.bg_settingsService = bg_settingsService = new SettingsService(bg_userService, bg_utilsService);
window.bg_cipherService = bg_cipherService = new CipherService(bg_cryptoService, bg_userService, bg_apiService, bg_settingsService, bg_utilsService,
bg_constantsService);
bg_folderService = new FolderService(bg_cryptoService, bg_userService, bg_apiService, bg_i18nService, bg_utilsService);
bg_lockService = new LockService(bg_constantsService, bg_cryptoService, bg_folderService, bg_cipherService, bg_utilsService,
window.bg_folderService = bg_folderService = new FolderService(bg_cryptoService, bg_userService, bg_apiService, bg_i18nService, bg_utilsService);
window.bg_lockService = bg_lockService = new LockService(bg_constantsService, bg_cryptoService, bg_folderService, bg_cipherService, bg_utilsService,
setIcon, refreshBadgeAndMenu);
bg_syncService = new SyncService(bg_cipherService, bg_folderService, bg_userService, bg_apiService, bg_settingsService,
window.bg_syncService = bg_syncService = new SyncService(bg_cipherService, bg_folderService, bg_userService, bg_apiService, bg_settingsService,
bg_cryptoService, logout);
bg_passwordGenerationService = new PasswordGenerationService(bg_constantsService, bg_utilsService, bg_cryptoService);
bg_totpService = new TotpService(bg_constantsService);
bg_autofillService = new AutofillService(bg_utilsService, bg_totpService, bg_tokenService, bg_cipherService,
window.bg_passwordGenerationService = bg_passwordGenerationService = new PasswordGenerationService(bg_constantsService, bg_utilsService, bg_cryptoService);
window.bg_totpService = bg_totpService = new TotpService(bg_constantsService);
window.bg_autofillService = bg_autofillService = new AutofillService(bg_utilsService, bg_totpService, bg_tokenService, bg_cipherService,
bg_constantsService);
require('./scripts/analytics.js');
if (chrome.commands) {
chrome.commands.onCommand.addListener(function (command) {
if (command === 'generate_password') {

33901
src/edge/angular.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
var CipherRequest = function (cipher) {
window.CipherRequest = function (cipher) {
this.type = cipher.type;
this.folderId = cipher.folderId;
this.organizationId = cipher.organizationId;
@ -69,11 +69,11 @@
}
};
var FolderRequest = function (folder) {
window.FolderRequest = function (folder) {
this.name = folder.name ? folder.name.encryptedString : null;
};
var TokenRequest = function (email, masterPasswordHash, provider, token, remember, device) {
window.TokenRequest = function (email, masterPasswordHash, provider, token, remember, device) {
this.email = email;
this.masterPasswordHash = masterPasswordHash;
this.token = token;
@ -85,7 +85,7 @@ var TokenRequest = function (email, masterPasswordHash, provider, token, remembe
}
};
TokenRequest.prototype.toIdentityToken = function () {
window.TokenRequest.prototype.toIdentityToken = function () {
var obj = {
grant_type: 'password',
username: this.email,
@ -110,7 +110,7 @@ TokenRequest.prototype.toIdentityToken = function () {
return obj;
};
var RegisterRequest = function (email, masterPasswordHash, masterPasswordHint, key) {
window.RegisterRequest = function (email, masterPasswordHash, masterPasswordHint, key) {
this.name = null;
this.email = email;
this.masterPasswordHash = masterPasswordHash;
@ -118,20 +118,20 @@ var RegisterRequest = function (email, masterPasswordHash, masterPasswordHint, k
this.key = key;
};
var PasswordHintRequest = function (email) {
window.PasswordHintRequest = function (email) {
this.email = email;
};
var TwoFactorEmailRequest = function (email, masterPasswordHash) {
window.TwoFactorEmailRequest = function (email, masterPasswordHash) {
this.email = email;
this.masterPasswordHash = masterPasswordHash;
};
var DeviceTokenRequest = function () {
window.DeviceTokenRequest = function () {
this.pushToken = null;
};
var DeviceRequest = function (appId, utilsService) {
window.DeviceRequest = function (appId, utilsService) {
this.type = utilsService.getDeviceType();
this.name = utilsService.getBrowser();
this.identifier = appId;

View File

@ -1,4 +1,4 @@
var CipherResponse = function (response) {
window.CipherResponse = function (response) {
this.id = response.Id;
this.organizationId = response.OrganizationId;
this.folderId = response.FolderId;
@ -17,13 +17,13 @@ var CipherResponse = function (response) {
}
};
var FolderResponse = function (response) {
window.FolderResponse = function (response) {
this.id = response.Id;
this.name = response.Name;
this.revisionDate = response.RevisionDate;
};
var ProfileResponse = function (response) {
window.ProfileResponse = function (response) {
this.id = response.Id;
this.name = response.Name;
this.email = response.Email;
@ -44,12 +44,12 @@ var ProfileResponse = function (response) {
}
};
var KeysResponse = function (response) {
window.KeysResponse = function (response) {
this.privateKey = response.PrivateKey;
this.publicKey = response.PublicKey;
};
var ProfileOrganizationResponse = function (response) {
window.ProfileOrganizationResponse = function (response) {
this.id = response.Id;
this.name = response.Name;
this.useGroups = response.UseGroups;
@ -63,7 +63,7 @@ var ProfileOrganizationResponse = function (response) {
this.type = response.Type;
};
var AttachmentResponse = function (response) {
window.AttachmentResponse = function (response) {
this.id = response.Id;
this.url = response.Url;
this.fileName = response.FileName;
@ -71,7 +71,7 @@ var AttachmentResponse = function (response) {
this.sizeName = response.SizeName;
};
var IdentityTokenResponse = function (response) {
window.IdentityTokenResponse = function (response) {
this.accessToken = response.access_token;
this.expiresIn = response.expires_in;
this.refreshToken = response.refresh_token;
@ -82,11 +82,11 @@ var IdentityTokenResponse = function (response) {
this.twoFactorToken = response.TwoFactorToken;
};
var ListResponse = function (data) {
window.ListResponse = function (data) {
this.data = data;
};
var ErrorResponse = function (response, identityResponse) {
window.ErrorResponse = function (response, identityResponse) {
var errorModel = null;
if (identityResponse && identityResponse === true && response.responseJSON && response.responseJSON.ErrorModel) {
errorModel = response.responseJSON.ErrorModel;
@ -105,7 +105,7 @@ var ErrorResponse = function (response, identityResponse) {
this.statusCode = response.status;
};
var DeviceResponse = function (response) {
window.DeviceResponse = function (response) {
this.id = response.Id;
this.name = response.Name;
this.identifier = response.Identifier;
@ -113,7 +113,7 @@ var DeviceResponse = function (response) {
this.creationDate = response.CreationDate;
};
var CipherHistoryResponse = function (response) {
window.CipherHistoryResponse = function (response) {
this.revised = [];
var revised = response.Revised;
@ -124,7 +124,7 @@ var CipherHistoryResponse = function (response) {
this.deleted = response.Deleted;
};
var DomainsResponse = function (response) {
window.DomainsResponse = function (response) {
var GlobalDomainResponse = function (response) {
this.type = response.Type;
this.domains = response.Domains;
@ -143,7 +143,7 @@ var DomainsResponse = function (response) {
}
};
var SyncResponse = function (response) {
window.SyncResponse = function (response) {
if (response.Profile) {
this.profile = new ProfileResponse(response.Profile);
}

View File

@ -3,7 +3,6 @@
<head>
<title></title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="bar.css" />
</head>
<body>
<table class="outter-table" cellpadding="0" cellspacing="0">
@ -37,7 +36,5 @@
</table>
<div id="template-alert"></div>
</div>
<script src="../lib/jquery/jquery.js"></script>
<script src="bar.js"></script>
</body>
</html>

View File

@ -1,4 +1,6 @@
$(function () {
require('./bar.less');
$(function () {
var content = document.getElementById('content'),
closeButton = $('#close-button');

1
src/popup/app/app.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare module '*.html';

View File

@ -1,4 +1,37 @@
angular
require('jquery');
require('bootstrap');
require('papaparse');
require('clipboard');
require('angular');
require('angular-animate');
require('angular-ui-router');
require('angular-toastr');
require('ngclipboard');
require('sweetalert');
require('angular-sweetalert');
require('angulartics');
require('angulartics-google-analytics');
require('ng-infinite-scroll');
require('../../scripts/analytics.js');
require('../../scripts/duo.js');
require('../../scripts/u2f.js');
require('../../models/api/requestModels.js');
require('../../models/api/responseModels.js');
require('../../models/dataModels.js');
require('../../models/domainModels.js');
require('../less/libs.less');
require('../less/popup.less');
import ComponentsModule from './components/components.module';
angular
.module('bit', [
'ui.router',
'ngAnimate',
@ -7,7 +40,7 @@
'angulartics.google.analytics',
'bit.directives',
'bit.components',
ComponentsModule,
'bit.services',
'bit.global',
@ -18,3 +51,60 @@
'bit.tools',
'bit.lock'
]);
require('./services/services.module');
require('./config');
require('./directives/directivesModule.js');
require('./directives/formDirective.js');
require('./directives/stopClickDirective.js');
require('./directives/stopPropDirective.js');
require('./directives/fallbackSrcDirective.js');
require('./components/iconComponent.js');
require('./components/actionButtonsComponent.js');
require('./services/backgroundService.js');
require('./services/authService.js');
require('./services/validationService.js');
require('./global/globalModule.js');
require('./global/mainController.js');
require('./global/tabsController.js');
require('./global/baseController.js');
require('./global/privateModeController.js');
require('./accounts/accountsModule.js');
require('./accounts/accountsLoginController.js');
require('./accounts/accountsLoginTwoFactorController.js');
require('./accounts/accountsTwoFactorMethodsController.js');
require('./accounts/accountsHintController.js');
require('./accounts/accountsRegisterController.js');
require('./current/currentModule.js');
require('./current/currentController.js');
require('./vault/vaultModule.js');
require('./vault/vaultController.js');
require('./vault/vaultViewFolderController.js');
require('./vault/vaultAddCipherController.js');
require('./vault/vaultEditCipherController.js');
require('./vault/vaultViewCipherController.js');
require('./vault/vaultAttachmentsController.js');
require('./settings/settingsModule.js');
require('./settings/settingsController.js');
require('./settings/settingsHelpController.js');
require('./settings/settingsAboutController.js');
require('./settings/settingsCreditsController.js');
require('./settings/settingsFeaturesController.js');
require('./settings/settingsSyncController.js');
require('./settings/settingsFoldersController.js');
require('./settings/settingsAddFolderController.js');
require('./settings/settingsEditFolderController.js');
require('./settings/settingsPremiumController.js');
require('./settings/settingsEnvironmentController.js');
require('./tools/toolsModule.js');
require('./tools/toolsController.js');
require('./tools/toolsPasswordGeneratorController.js');
require('./tools/toolsPasswordGeneratorHistoryController.js');
require('./tools/toolsExportController.js');
require('./lock/lockModule.js');
require('./lock/lockController.js');
// Bootstrap the angular application
angular.element(function() {
angular.bootstrap(document, ['bit']);
});

View File

@ -0,0 +1,30 @@
import * as template from './cipher-items.component.html';
class CipherItemsController implements ng.IController {
onSelected: Function;
onView: Function;
constructor(private i18nService: any) {
}
public view(cipher: any) {
return this.onView()(cipher);
}
public select(cipher: any) {
return this.onSelected()(cipher);
}
}
export const CipherItemsComponent = {
bindings: {
ciphers: '<',
selectionTitle: '<',
onView: '&',
onSelected: '&'
},
template: template,
controller: CipherItemsController
}

View File

@ -1,27 +0,0 @@
angular
.module('bit.components')
.component('cipherItems', {
bindings: {
ciphers: '<',
selectionTitle: '<',
onView: '&',
onSelected: '&'
},
templateUrl: 'app/components/views/cipherItems.html',
controller: function (i18nService) {
var ctrl = this;
ctrl.$onInit = function () {
ctrl.i18n = i18nService;
ctrl.view = function (cipher) {
ctrl.onView()(cipher);
};
ctrl.select = function (cipher) {
ctrl.onSelected()(cipher);
};
};
}
});

View File

@ -0,0 +1,7 @@
import * as angular from 'angular';
import { CipherItemsComponent } from './cipher-items.component';
export default angular
.module('bit.components', [])
.component('cipherItems', CipherItemsComponent)
.name;

View File

@ -0,0 +1,5 @@
import StateService from './state.service';
angular
.module('bit.services', ['toastr'])
.service('stateService', StateService);

View File

@ -1,2 +0,0 @@
angular
.module('bit.services', ['toastr']);

View File

@ -0,0 +1,36 @@
class StateService {
private state: any = {};
constructor (private utilsService: any, private constantsService: any) {
}
async init() {
const faviconsDisabled = await this.utilsService
.getObjFromStorage(this.constantsService.disableFaviconKey);
this.saveState('faviconEnabled', !faviconsDisabled);
}
saveState(key: string, data: any) {
this.state[key] = data;
}
getState(key: string): any {
if (key in this.state) {
return this.state[key];
}
return null;
}
removeState(key: string) {
delete this.state[key];
}
purgeState() {
this.state = {};
}
}
export default StateService;

View File

@ -1,35 +0,0 @@
angular
.module('bit.services')
.factory('stateService', function (utilsService, constantsService) {
var _service = {},
_state = {};
_service.init = function () {
utilsService.getObjFromStorage(constantsService.disableFaviconKey).then(function (disabledFavicons) {
_service.saveState('faviconEnabled', !disabledFavicons);
});
};
_service.saveState = function (key, data) {
_state[key] = data;
};
_service.getState = function (key) {
if (key in _state) {
return _state[key];
}
return null;
};
_service.removeState = function (key) {
delete _state[key];
};
_service.purgeState = function () {
_state = {};
};
return _service;
});

View File

@ -1,121 +1,13 @@
<!DOCTYPE html>
<html ng-app="bit" ng-csp>
<html ng-csp class="__BROWSER__">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>bitwarden</title>
<!-- @if true !>
<link rel="stylesheet" href="css/popup.css">
<!-- @endif -->
<!-- @exclude -->
<link rel="stylesheet" href="css/webfonts.css">
<link rel="stylesheet" href="../lib/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="../lib/angular-toastr/angular-toastr.css">
<link rel="stylesheet" href="../lib/sweetalert/sweetalert.css">
<link rel="stylesheet" href="css/popup.css">
<!-- @endexclude -->
</head>
<body ng-controller="mainController as main" class="{{main.animation}}"
ng-class="{sm: main.smBody, xs: main.xsBody }">
<div ui-view class="main-view"></div>
<!-- @if true !>
<script src="lib.js"></script>
<script src="app.js"></script>
<!-- @endif -->
<!-- @exclude -->
<script src="../lib/jquery/jquery.js"></script>
<script src="../lib/bootstrap/js/bootstrap.js"></script>
<script src="../lib/papaparse/papaparse.js"></script>
<script src="../lib/clipboard/clipboard.js"></script>
<script src="../lib/angular/angular.js"></script>
<script src="../lib/angular-animate/angular-animate.js"></script>
<script src="../lib/angular-ui-router/angular-ui-router.js"></script>
<script src="../lib/angular-toastr/angular-toastr.tpls.js"></script>
<script src="../lib/ngclipboard/ngclipboard.js"></script>
<script src="../lib/sweetalert/sweetalert-dev.js"></script>
<script src="../lib/sweetalert/SweetAlert.js"></script>
<script src="../lib/angulartics/angulartics.js"></script>
<script src="../lib/angulartics/angulartics-ga.js"></script>
<script src="../lib/ng-infinite-scroll/ng-infinite-scroll.js"></script>
<script src="../scripts/analytics.js"></script>
<script src="../scripts/duo.js"></script>
<script src="../scripts/u2f.js"></script>
<script src="../models/api/requestModels.js"></script>
<script src="../models/api/responseModels.js"></script>
<script src="../models/dataModels.js"></script>
<script src="../models/domainModels.js"></script>
<script src="app/app.js"></script>
<script src="app/config.js"></script>
<script src="app/directives/directivesModule.js"></script>
<script src="app/directives/formDirective.js"></script>
<script src="app/directives/stopClickDirective.js"></script>
<script src="app/directives/stopPropDirective.js"></script>
<script src="app/directives/fallbackSrcDirective.js"></script>
<script src="app/components/componentsModule.js"></script>
<script src="app/components/iconComponent.js"></script>
<script src="app/components/actionButtonsComponent.js"></script>
<script src="app/components/cipherItemsComponent.js"></script>
<script src="app/services/servicesModule.js"></script>
<script src="app/services/backgroundService.js"></script>
<script src="app/services/authService.js"></script>
<script src="app/services/validationService.js"></script>
<script src="app/services/stateService.js"></script>
<script src="app/global/globalModule.js"></script>
<script src="app/global/mainController.js"></script>
<script src="app/global/tabsController.js"></script>
<script src="app/global/baseController.js"></script>
<script src="app/global/privateModeController.js"></script>
<script src="app/accounts/accountsModule.js"></script>
<script src="app/accounts/accountsLoginController.js"></script>
<script src="app/accounts/accountsLoginTwoFactorController.js"></script>
<script src="app/accounts/accountsTwoFactorMethodsController.js"></script>
<script src="app/accounts/accountsHintController.js"></script>
<script src="app/accounts/accountsRegisterController.js"></script>
<script src="app/current/currentModule.js"></script>
<script src="app/current/currentController.js"></script>
<script src="app/vault/vaultModule.js"></script>
<script src="app/vault/vaultController.js"></script>
<script src="app/vault/vaultViewFolderController.js"></script>
<script src="app/vault/vaultAddCipherController.js"></script>
<script src="app/vault/vaultEditCipherController.js"></script>
<script src="app/vault/vaultViewCipherController.js"></script>
<script src="app/vault/vaultAttachmentsController.js"></script>
<script src="app/settings/settingsModule.js"></script>
<script src="app/settings/settingsController.js"></script>
<script src="app/settings/settingsHelpController.js"></script>
<script src="app/settings/settingsAboutController.js"></script>
<script src="app/settings/settingsCreditsController.js"></script>
<script src="app/settings/settingsFeaturesController.js"></script>
<script src="app/settings/settingsSyncController.js"></script>
<script src="app/settings/settingsFoldersController.js"></script>
<script src="app/settings/settingsAddFolderController.js"></script>
<script src="app/settings/settingsEditFolderController.js"></script>
<script src="app/settings/settingsPremiumController.js"></script>
<script src="app/settings/settingsEnvironmentController.js"></script>
<script src="app/tools/toolsModule.js"></script>
<script src="app/tools/toolsController.js"></script>
<script src="app/tools/toolsPasswordGeneratorController.js"></script>
<script src="app/tools/toolsPasswordGeneratorHistoryController.js"></script>
<script src="app/tools/toolsExportController.js"></script>
<script src="app/lock/lockModule.js"></script>
<script src="app/lock/lockController.js"></script>
<!-- @endexclude -->
</body>
</html>

4
src/popup/less/libs.less Normal file
View File

@ -0,0 +1,4 @@
@import "~font-awesome/less/font-awesome.less";
@import "~angular-toastr/src/toastr.less";
@import (inline) "~sweetalert/dist/sweetalert.css";

View File

@ -1,31 +1,29 @@
@import "../../../node_modules/bootstrap/less/bootstrap.less";
@import (less) "../../../node_modules/angular/angular-csp.css";
@import "~bootstrap/less/bootstrap.less";
@import (less) "~angular/angular-csp.css";
@import "variables.less";
@import "mixins.less";
@import "components.less";
@import "animations.less";
@import "plugins.less";
@import "pages.less";
@import (less) "../css/webfonts.css";
html {
-webkit-font-smoothing: antialiased;
}
body {
width: 320px !important;
height: 568px !important;
width: 375px !important;
height: 667px !important;
background-color: @background-color;
overflow: hidden;
}
/* @ifndef firefox */
/* @ifndef edge */
body {
width: 375px !important;
height: 667px !important;
html.firefox body,
html.edge body {
width: 320px !important;
height: 568px !important;
}
/* @endif */
/* @endif */
body.sm {
width: 375px !important;

View File

@ -1,6 +1,6 @@
@import (reference) "../../../node_modules/bootstrap/less/bootstrap.less";
@import (reference) "../../../node_modules/bootstrap/less/mixins.less";
@import (reference) "../../../node_modules/bootstrap/less/variables.less";
@import (reference) "~bootstrap/less/bootstrap.less";
@import (reference) "~bootstrap/less/mixins.less";
@import (reference) "~bootstrap/less/variables.less";
@font-family-sans-serif: "Open Sans", sans-serif;
@text-color: #000000;

View File

@ -1,4 +1,4 @@
(function () {
(function () {
var bgPage = chrome.extension.getBackgroundPage();
if (!bgPage) {
return;

View File

@ -1,4 +1,4 @@
function LockService(constantsService, cryptoService, folderService, cipherService, utilsService, setIcon, refreshBadgeAndMenu) {
export default function LockService(constantsService, cryptoService, folderService, cipherService, utilsService, setIcon, refreshBadgeAndMenu) {
this.lastLockCheck = null;
this.constantsService = constantsService;
this.cryptoService = cryptoService;

View File

@ -1,4 +1,4 @@
function TokenService(utilsService) {
function TokenService(utilsService) {
this.utilsService = utilsService;
initTokenService();

View File

@ -1,4 +1,4 @@
function UserService(tokenService, apiService, cryptoService, utilsService) {
function UserService(tokenService, apiService, cryptoService, utilsService) {
this.tokenService = tokenService;
this.apiService = apiService;
this.cryptoService = cryptoService;

13
tsconfig.json Normal file
View File

@ -0,0 +1,13 @@
{
"compilerOptions": {
"noImplicitAny": true,
"module": "es6",
"target": "ES2016",
"allowJs": true,
"sourceMap": true
},
"exclude": [
"node_modules",
"dist/**"
]
}

96
webpack.common.js Normal file
View File

@ -0,0 +1,96 @@
const path = require('path');
const webpack = require("webpack");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: {
'popup/app': './src/popup/app/app.js',
'background': './src/background.js',
'content/autofill': './src/content/autofill.js',
'content/autofiller': './src/content/autofiller.js',
'content/notificationBar': './src/content/notificationBar.js',
'notification/bar': './src/notification/bar.js',
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.(html)$/,
loader: 'html-loader'
},
{
test: /.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'popup/fonts/',
publicPath: '/'
}
}]
}
]
},
plugins: [
new CleanWebpackPlugin([
path.resolve(__dirname, 'dist')
]),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
'Q': 'q'
}),
new webpack.optimize.CommonsChunkPlugin({
name: "popup/vendor",
chunks: ['popup/app'],
minChunks: function (module) {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf("node_modules") !== -1;
}
}),
new HtmlWebpackPlugin({
template: './src/popup/index.html',
filename: 'popup/index.html',
chunks: ['popup/vendor', 'popup/app', 'fonts']
}),
new HtmlWebpackPlugin({
template: './src/background.html',
filename: 'background.html',
chunks: ['background']
}),
new HtmlWebpackPlugin({
template: './src/notification/bar.html',
filename: 'notification/bar.html',
chunks: ['notification/bar']
}),
new CopyWebpackPlugin([
// Temporarily copy the whole app folder, can be removed once
// the templates uses template rather than using templateUrl.
{ from: './src/popup/app', to: 'popup/app' },
'./src/manifest.json',
{ from: './src/_locales', to: '_locales' },
{ from: './src/edge', to: 'edge' },
{ from: './src/images', to: 'images' },
{ from: './src/lib', to: 'lib' },
{ from: './src/models', to: 'models' },
{ from: './src/overlay', to: 'overlay' },
{ from: './src/scripts', to: 'scripts' },
{ from: './src/services', to: 'services' },
'./src/background.js'
])
],
resolve: {
extensions: [ ".tsx", ".ts", ".js" ]
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
}
};

24
webpack.dev.js Normal file
View File

@ -0,0 +1,24 @@
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.less$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader",
},
{
loader: "less-loader",
}
]
}
]
}
});

35
webpack.prod.js Normal file
View File

@ -0,0 +1,35 @@
const merge = require('webpack-merge');
//const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const common = require('./webpack.common.js');
const extractLess = new ExtractTextPlugin({
filename: "popup/css/[name].css",
disable: false,
allChunks: true
});
module.exports = merge(common, {
devtool: 'source-map',
module: {
rules: [
{
test: /\.less$/,
use: extractLess.extract({
use: [
{
loader: "css-loader",
},
{
loader: "less-loader",
}
]
})
}
]
},
plugins: [
extractLess
//new UglifyJSPlugin()
]
});