-
Notifications
You must be signed in to change notification settings - Fork 686
/
webpack.config.js
91 lines (81 loc) · 2.53 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var path = require("path");
var fs = require('fs-extra');
var webpack = require("webpack");
var Clean = require("clean-webpack-plugin");
var BuildPaths = require("./lib/build-paths");
var BuildExtension = require("./lib/build-extension-webpack-plugin");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var manifest = fs.readJSONSync(path.join(BuildPaths.SRC_ROOT, 'manifest.json'));
var version = manifest.version;
var entries = {
viewer: ["./extension/src/viewer.js"],
"viewer-alert": ["./extension/styles/viewer-alert.scss"],
options: ["./extension/src/options.js"],
backend: ["./extension/src/backend.js"],
omnibox: ["./extension/src/omnibox.js"],
"omnibox-page": ["./extension/src/omnibox-page.js"]
};
function findThemes(darkness) {
return fs.readdirSync(path.join('extension', 'themes', darkness)).
filter(function(filename) {
return /\.js$/.test(filename);
}).
map(function(theme) {
return theme.replace(/\.js$/, '');
});
}
function includeThemes(darkness, list) {
list.forEach(function(filename) {
entries[filename] = ["./extension/themes/" + darkness + "/" + filename + ".js"];
});
}
var lightThemes = findThemes('light');
var darkThemes = findThemes('dark');
var themes = {light: lightThemes, dark: darkThemes};
includeThemes('light', lightThemes);
includeThemes('dark', darkThemes);
console.log("Entries list:");
console.log(entries);
console.log("\n");
var manifest = {
debug: false,
context: __dirname,
entry: entries,
themes: themes,
output: {
path: path.join(__dirname, "build/json_viewer/assets"),
filename: "[name].js"
},
module: {
loaders: [
{test: /\.(css|scss)$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader")}
]
},
resolve: {
extensions: ['', '.js', '.css', '.scss'],
root: path.resolve(__dirname, './extension'),
},
externals: [
{
"chrome-framework": "chrome"
}
],
plugins: [
new Clean(["build"]),
new ExtractTextPlugin("[name].css", {allChunks: true}),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
VERSION: JSON.stringify(version),
THEMES: JSON.stringify(themes)
}
}),
new BuildExtension()
]
};
if (process.env.NODE_ENV === 'production') {
manifest.plugins.push(new webpack.optimize.UglifyJsPlugin({sourceMap: false}));
manifest.plugins.push(new webpack.optimize.DedupePlugin());
manifest.plugins.push(new webpack.NoErrorsPlugin());
}
module.exports = manifest;