react/shells/browser/shared/webpack.config.js

74 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-01-24 00:45:19 +08:00
const { readFileSync } = require('fs');
const { resolve } = require('path');
const { DefinePlugin } = require('webpack');
2019-01-23 03:04:37 +08:00
2019-01-31 02:38:52 +08:00
const __DEV__ = process.env.NODE_ENV !== 'production';
2019-01-23 03:04:37 +08:00
const DEVTOOLS_VERSION = JSON.parse(
readFileSync(resolve(__dirname, '../../../package.json'))
).version;
2019-01-23 03:04:37 +08:00
module.exports = {
mode: __DEV__ ? 'development' : 'production',
devtool: __DEV__ ? 'cheap-module-eval-source-map' : false,
entry: {
background: './src/background.js',
contentScript: './src/contentScript.js',
inject: './src/GlobalHook.js',
main: './src/main.js',
elements: './src/panels/elements.js',
settings: './src/panels/settings.js',
2019-01-23 03:04:37 +08:00
},
output: {
path: __dirname + '/build',
filename: '[name].js',
},
2019-01-24 10:06:21 +08:00
resolve: {
alias: {
src: resolve(__dirname, '../../../src'),
},
},
2019-01-24 00:45:19 +08:00
plugins: __DEV__
? [
new DefinePlugin({
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
}),
]
2019-01-24 00:45:19 +08:00
: [
// Ensure we get production React
new DefinePlugin({
2019-01-24 00:45:19 +08:00
'process.env.NODE_ENV': '"production"',
}),
new DefinePlugin({
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
}),
2019-01-24 00:45:19 +08:00
],
2019-01-23 03:04:37 +08:00
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
2019-01-24 10:06:21 +08:00
options: JSON.parse(
readFileSync(resolve(__dirname, '../../../.babelrc'))
),
2019-01-23 03:04:37 +08:00
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: true,
localIdentName: '[local]___[hash:base64:5]',
},
},
],
},
],
},
};