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