This repository has been archived by the owner on Apr 28, 2022. It is now read-only.
/
webpack.config.js
62 lines (58 loc) · 1.88 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJS = require("uglify-es");
const BUILD_DIR = path.resolve(__dirname, 'dist/options');
const APP_DIR = path.resolve(__dirname, 'options.dev');
function minifyFilesBeforeCopy(content, $path) {
const result = UglifyJS.minify(content.toString());
if (result.error) {
console.error($path);
throw result.error;
}
return result.code;
}
const config = {
entry: {
options: APP_DIR + '/app.jsx',
vendor: ['react', 'react-dom', 'react-tag-autocomplete', 'react-toggle-button'],
},
output: {
path: BUILD_DIR,
filename: '[name].js'
},
module: {
loaders: [{
test: /\.jsx$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}, {
test: /\.css$/,
loader: 'style-loader!css-loader'
}]
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
new webpack.optimize.UglifyJsPlugin(),
new HtmlWebpackPlugin({ template: path.join(APP_DIR, 'index.html') }),
new ExtractTextPlugin('[name].css'),
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.bundle.js' }),
new CopyWebpackPlugin([
{ from: path.resolve('options.dev/analytics.js'), to: 'analytics.js'},
{ from: 'manifest.json', to: '..' },
{ from: 'icon*.png', to: '..' },
{ from: 'inject.js', to: '..', transform: minifyFilesBeforeCopy },
{ from: 'utils.js', to: '..', transform: minifyFilesBeforeCopy },
{ from: 'contentscript.js', to: '..', transform: minifyFilesBeforeCopy },
{ from: 'background.js', to: '..', transform: minifyFilesBeforeCopy },
]),
],
};
module.exports = config;