|
|
@ -1,8 +1,10 @@ |
|
|
|
'use strict'; |
|
|
|
const fs = require('fs'); |
|
|
|
const glob = require('glob'); |
|
|
|
const nodeExternals = require('webpack-node-externals'); |
|
|
|
const path = require('path'); |
|
|
|
const webpack = require('webpack'); |
|
|
|
const CleanPlugin = require('clean-webpack-plugin'); |
|
|
|
const FileManagerPlugin = require('filemanager-webpack-plugin'); |
|
|
|
const HtmlInlineSourcePlugin = require('html-webpack-inline-source-plugin'); |
|
|
|
const HtmlPlugin = require('html-webpack-plugin'); |
|
|
|
const ImageminPlugin = require('imagemin-webpack-plugin').default; |
|
|
@ -14,16 +16,46 @@ module.exports = function(env, argv) { |
|
|
|
env = env || {}; |
|
|
|
env.production = !!env.production; |
|
|
|
env.optimizeImages = env.production || !!env.optimizeImages; |
|
|
|
env.copyClipboardyFallbacks = env.production || !!env.copyClipboardyFallbacks; |
|
|
|
|
|
|
|
if (!env.copyClipboardyFallbacks && !fs.existsSync(path.resolve(__dirname, 'fallbacks'))) { |
|
|
|
env.copyClipboardyFallbacks = true; |
|
|
|
} |
|
|
|
|
|
|
|
return [getExtensionConfig(env), getUIConfig(env)]; |
|
|
|
}; |
|
|
|
|
|
|
|
function getExtensionConfig(env) { |
|
|
|
const clean = ['dist']; |
|
|
|
if (env.copyClipboardyFallbacks) { |
|
|
|
clean.push('fallbacks'); |
|
|
|
} |
|
|
|
|
|
|
|
const plugins = [ |
|
|
|
// https://github.com/GoogleChromeLabs/size-plugin/issues/12
|
|
|
|
// new SizePlugin(),
|
|
|
|
new CleanPlugin(['dist'], { verbose: false }) |
|
|
|
new CleanPlugin(clean, { verbose: false }), |
|
|
|
new webpack.IgnorePlugin(/^spawn-sync$/) |
|
|
|
]; |
|
|
|
|
|
|
|
if (env.copyClipboardyFallbacks) { |
|
|
|
plugins.push( |
|
|
|
// @ts-ignore
|
|
|
|
new FileManagerPlugin({ |
|
|
|
onEnd: [ |
|
|
|
{ |
|
|
|
copy: [ |
|
|
|
{ |
|
|
|
source: path.resolve(__dirname, 'node_modules/clipboardy/fallbacks'), |
|
|
|
destination: 'fallbacks/' |
|
|
|
} |
|
|
|
] |
|
|
|
} |
|
|
|
] |
|
|
|
}) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// if (env.production) {
|
|
|
|
// plugins.push(new WebpackDeepScopeAnalysisPlugin());
|
|
|
|
// }
|
|
|
@ -33,6 +65,9 @@ function getExtensionConfig(env) { |
|
|
|
entry: './src/extension.ts', |
|
|
|
mode: env.production ? 'production' : 'development', |
|
|
|
target: 'node', |
|
|
|
node: { |
|
|
|
__dirname: false |
|
|
|
}, |
|
|
|
devtool: !env.production ? 'eval-source-map' : undefined, |
|
|
|
output: { |
|
|
|
libraryTarget: 'commonjs2', |
|
|
@ -40,10 +75,9 @@ function getExtensionConfig(env) { |
|
|
|
path: path.resolve(__dirname, 'dist'), |
|
|
|
devtoolModuleFilenameTemplate: 'file:///[absolute-resource-path]' |
|
|
|
}, |
|
|
|
resolve: { |
|
|
|
extensions: ['.tsx', '.ts', '.js'] |
|
|
|
externals: { |
|
|
|
vscode: 'commonjs vscode' |
|
|
|
}, |
|
|
|
externals: [nodeExternals()], |
|
|
|
module: { |
|
|
|
rules: [ |
|
|
|
{ |
|
|
@ -58,6 +92,9 @@ function getExtensionConfig(env) { |
|
|
|
} |
|
|
|
] |
|
|
|
}, |
|
|
|
resolve: { |
|
|
|
extensions: ['.ts', '.tsx', '.js', '.jsx'] |
|
|
|
}, |
|
|
|
plugins: plugins, |
|
|
|
stats: { |
|
|
|
all: false, |
|
|
@ -133,7 +170,7 @@ function getUIConfig(env) { |
|
|
|
sources: glob.sync('src/ui/images/settings/*.png'), |
|
|
|
destination: path.resolve(__dirname, 'images') |
|
|
|
}, |
|
|
|
cacheFolder: path.resolve(__dirname, '.image-cache'), |
|
|
|
cacheFolder: path.resolve(__dirname, '.cache-images'), |
|
|
|
gifsicle: null, |
|
|
|
jpegtran: null, |
|
|
|
optipng: null, |
|
|
@ -177,10 +214,6 @@ function getUIConfig(env) { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
resolve: { |
|
|
|
extensions: ['.tsx', '.ts', '.js'], |
|
|
|
modules: [path.resolve(__dirname, 'src/ui'), 'node_modules'] |
|
|
|
}, |
|
|
|
module: { |
|
|
|
rules: [ |
|
|
|
{ |
|
|
@ -230,6 +263,10 @@ function getUIConfig(env) { |
|
|
|
} |
|
|
|
] |
|
|
|
}, |
|
|
|
resolve: { |
|
|
|
extensions: ['.ts', '.tsx', '.js', '.jsx'], |
|
|
|
modules: [path.resolve(__dirname, 'src/ui'), 'node_modules'] |
|
|
|
}, |
|
|
|
plugins: plugins, |
|
|
|
stats: { |
|
|
|
all: false, |
|
|
|