forked from WeareJH/m2-dev-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
80 lines (77 loc) · 2.29 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
const path = require('path');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const { CheckerPlugin } = require('awesome-typescript-loader');
const extractSass = new ExtractTextPlugin({
filename: "panel.css",
disable: process.env.NODE_ENV === "development"
});
module.exports = {
entry: env({
dev: {
iframe: './src/envs/iframe.tsx',
plain: './src/envs/plain.tsx',
inject: './src/chrome/inject-plain.ts',
background: './src/chrome/background.ts',
},
production: {
panel: "./src/envs/chrome.tsx",
inject: './src/chrome/inject.ts',
background: './src/chrome/background.ts',
main: './src/chrome/main.ts',
plain: './src/envs/plain.tsx',
}
}),
devtool: env({dev: 'inline-source-map', production: "source-map"}),
module: {
rules: [
{
test: /\.tsx?$/,
use: 'awesome-typescript-loader',
exclude: /node_modules/
},
{
test: /\.scss$/,
use: extractSass.extract({
use: [{
loader: "css-loader"
}, {
loader: "sass-loader"
}],
// use style-loader in development
fallback: "style-loader"
})
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.scss']
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'shells/chrome/dist')
},
devServer: {},
plugins: env({
shared: [extractSass],
dev: [
new CheckerPlugin(),
],
production: [
new UglifyJSPlugin({
sourceMap: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
})
};
function env(input) {
const selection = input[process.env.NODE_ENV || 'dev'];
if (input.shared && Array.isArray(input.shared)) {
return input.shared.concat(selection);
}
return selection;
}