react/packages/react-devtools-shell/webpack.config.js

93 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-08-14 08:58:03 +08:00
const {resolve} = require('path');
const {DefinePlugin} = require('webpack');
const {getGitHubURL, getVersionString} = require('../utils');
const NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV) {
console.error('NODE_ENV not set');
process.exit(1);
}
2019-05-03 23:55:31 +08:00
const TARGET = process.env.TARGET;
if (!TARGET) {
console.error('TARGET not set');
process.exit(1);
}
const __DEV__ = NODE_ENV === 'development';
const root = resolve(__dirname, '../..');
2019-04-12 09:44:44 +08:00
const GITHUB_URL = getGitHubURL();
const DEVTOOLS_VERSION = getVersionString();
2019-01-23 03:04:37 +08:00
2019-05-03 23:55:31 +08:00
const config = {
2019-04-15 22:39:25 +08:00
mode: __DEV__ ? 'development' : 'production',
2019-01-23 03:04:37 +08:00
devtool: false,
entry: {
app: './app/index.js',
devtools: './src/devtools.js',
},
resolve: {
alias: {
'react-devtools-inline': resolve(
root,
2019-08-14 09:12:19 +08:00
'packages/react-devtools-inline/src/',
),
src: resolve(root, 'src'),
2019-01-23 03:04:37 +08:00
},
},
plugins: [
new DefinePlugin({
2019-08-12 23:49:26 +08:00
__DEV__,
__TEST__: false,
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
}),
],
2019-01-23 03:04:37 +08:00
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
2019-04-27 02:29:51 +08:00
options: {
configFile: resolve(root, 'babel.config.js'),
2019-04-27 02:29:51 +08:00
},
2019-01-23 03:04:37 +08:00
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: true,
2019-01-23 03:04:37 +08:00
modules: true,
localIdentName: '[local]___[hash:base64:5]',
},
},
],
},
],
},
};
2019-05-03 23:55:31 +08:00
if (TARGET === 'local') {
config.devServer = {
hot: true,
port: 8080,
clientLogLevel: 'warning',
publicPath: '/dist/',
stats: 'errors-only',
};
} else {
config.output = {
path: resolve(__dirname, 'dist'),
filename: '[name].js',
};
}
module.exports = config;