chore(extension): copy using Webpack (#674)

This commit is contained in:
Nathan Bierema 2020-11-16 17:53:51 -05:00 committed by GitHub
parent 01ae238e14
commit a28cd62bff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 749 additions and 438 deletions

View File

@ -1,6 +1,5 @@
import gulp from 'gulp'; import gulp from 'gulp';
import gutil from 'gulp-util'; import gutil from 'gulp-util';
import rename from 'gulp-rename';
import zip from 'gulp-zip'; import zip from 'gulp-zip';
import webpack from 'webpack'; import webpack from 'webpack';
import mocha from 'gulp-mocha'; import mocha from 'gulp-mocha';
@ -9,10 +8,6 @@ import devConfig from './webpack/dev.config';
import prodConfig from './webpack/prod.config'; import prodConfig from './webpack/prod.config';
import wrapConfig from './webpack/wrap.config'; import wrapConfig from './webpack/wrap.config';
function copy(dest) {
gulp.src('./src/assets/**/*').pipe(gulp.dest(dest));
}
/* /*
* dev tasks * dev tasks
*/ */
@ -27,15 +22,6 @@ gulp.task('webpack:dev', (callback) => {
callback(); callback();
}); });
gulp.task('copy:dev', (done) => {
gulp
.src('./src/browser/extension/manifest.json')
.pipe(rename('manifest.json'))
.pipe(gulp.dest('./dev'));
copy('./dev');
done();
});
/* /*
* build tasks * build tasks
*/ */
@ -57,15 +43,6 @@ gulp.task('webpack:build:extension', (callback) => {
.then(callback); .then(callback);
}); });
gulp.task('copy:build:extension', (done) => {
gulp
.src('./src/browser/extension/manifest.json')
.pipe(rename('manifest.json'))
.pipe(gulp.dest('./build/extension'));
copy('./build/extension');
done();
});
/* /*
* compress task * compress task
*/ */
@ -86,17 +63,6 @@ gulp.task('compress:firefox', (done) => {
done(); done();
}); });
/*
* watch tasks
*/
gulp.task('copy:watch', () => {
gulp.watch(
['./src/browser/extension/manifest.json', './src/assets/**/*'],
gulp.series('copy:dev')
);
});
gulp.task('test:chrome', () => { gulp.task('test:chrome', () => {
crdv.start(); crdv.start();
return gulp return gulp
@ -113,18 +79,15 @@ gulp.task('test:electron', () => {
.on('end', () => crdv.stop()); .on('end', () => crdv.stop());
}); });
gulp.task('default', gulp.parallel('webpack:dev', 'copy:dev', 'copy:watch')); gulp.task('default', gulp.parallel('webpack:dev'));
gulp.task( gulp.task('build:extension', gulp.parallel('webpack:build:extension'));
'build:extension',
gulp.parallel('webpack:build:extension', 'copy:build:extension')
);
gulp.task( gulp.task(
'copy:build:firefox', 'copy:build:firefox',
gulp.series('build:extension', (done) => { gulp.series('build:extension', (done) => {
gulp gulp
.src([ .src([
'./build/extension/**', './build/extension/**',
'!./build/extension/redux-devtools-extension.js', '!./build/extension/redux-devtools-extension.bundle.js',
]) ])
.pipe(gulp.dest('./build/firefox')) .pipe(gulp.dest('./build/firefox'))
.on('finish', function () { .on('finish', function () {
@ -132,7 +95,6 @@ gulp.task(
.src('./src/browser/firefox/manifest.json') .src('./src/browser/firefox/manifest.json')
.pipe(gulp.dest('./build/firefox')); .pipe(gulp.dest('./build/firefox'));
}); });
copy('./build/firefox');
done(); done();
}) })
); );

View File

@ -43,6 +43,7 @@
"babel-loader": "^8.1.0", "babel-loader": "^8.1.0",
"chromedriver": "^2.35.0", "chromedriver": "^2.35.0",
"co-mocha": "^1.1.3", "co-mocha": "^1.1.3",
"copy-webpack-plugin": "^6.3.1",
"cross-env": "^1.0.8", "cross-env": "^1.0.8",
"electron": "^2.0.2", "electron": "^2.0.2",
"enzyme": "^2.3.0", "enzyme": "^2.3.0",
@ -54,7 +55,6 @@
"gitbook-cli": "^2.3.0", "gitbook-cli": "^2.3.0",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-mocha": "^3.0.1", "gulp-mocha": "^3.0.1",
"gulp-rename": "^1.2.2",
"gulp-util": "^3.0.7", "gulp-util": "^3.0.7",
"gulp-zip": "^3.0.2", "gulp-zip": "^3.0.2",
"jsdom": "^9.8.3", "jsdom": "^9.8.3",
@ -68,7 +68,7 @@
"selenium-webdriver": "^3.0.1", "selenium-webdriver": "^3.0.1",
"sinon-chrome": "^1.1.2", "sinon-chrome": "^1.1.2",
"style-loader": "^0.18.2", "style-loader": "^0.18.2",
"webpack": "^4.27.1" "webpack": "^4.44.1"
}, },
"dependencies": { "dependencies": {
"jsan": "^3.1.13", "jsan": "^3.1.13",

View File

@ -1,6 +1,7 @@
import path from 'path'; import path from 'path';
import webpack from 'webpack'; import webpack from 'webpack';
import TerserPlugin from 'terser-webpack-plugin'; import TerserPlugin from 'terser-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin';
const extpath = path.join(__dirname, '../src/browser/extension/'); const extpath = path.join(__dirname, '../src/browser/extension/');
const mock = `${extpath}chromeAPIMock.js`; const mock = `${extpath}chromeAPIMock.js`;
@ -37,7 +38,22 @@ const baseConfig = (params) => ({
new webpack.optimize.ModuleConcatenationPlugin(), new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.OccurrenceOrderPlugin(),
]), ]),
].concat(
params.copy
? new CopyPlugin({
patterns: [
{
from: `${extpath}manifest.json`,
to: path.join(params.output.path, 'manifest.json'),
},
{
from: path.join(__dirname, '../src/assets/'),
to: params.output.path,
},
], ],
})
: []
),
optimization: { optimization: {
minimizer: [ minimizer: [
new TerserPlugin({ new TerserPlugin({

View File

@ -13,6 +13,7 @@ let config = baseConfig({
}, },
}, },
plugins: [new webpack.NoEmitOnErrorsPlugin()], plugins: [new webpack.NoEmitOnErrorsPlugin()],
copy: true,
}); });
config.watch = true; config.watch = true;

View File

@ -8,4 +8,5 @@ export default baseConfig({
NODE_ENV: '"production"', NODE_ENV: '"production"',
}, },
}, },
copy: true,
}); });

File diff suppressed because it is too large Load Diff