2017-10-01 13:02:25 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const merge = require('webpack-merge');
|
|
|
|
const common = require('./webpack.common.js');
|
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
2018-04-18 08:01:36 -05:00
|
|
|
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
|
2017-10-01 13:02:25 -05:00
|
|
|
const ExtractTextPlugin = require("extract-text-webpack-plugin");
|
2018-04-18 08:01:36 -05:00
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
2017-10-01 13:02:25 -05:00
|
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
|
|
|
2018-04-18 08:01:36 -05:00
|
|
|
const TARGET = process.env.npm_lifecycle_event;
|
|
|
|
const HOT = TARGET === 'start';
|
|
|
|
|
|
|
|
const extractSass = new ExtractTextPlugin({
|
|
|
|
filename: "grafana.[name].css",
|
|
|
|
disable: HOT
|
|
|
|
});
|
2017-10-01 13:02:25 -05:00
|
|
|
|
2018-04-18 08:01:36 -05:00
|
|
|
const entries = HOT ? {
|
|
|
|
app: [
|
|
|
|
'webpack-dev-server/client?http://localhost:3333',
|
|
|
|
'./public/app/dev.ts',
|
|
|
|
],
|
|
|
|
vendor: require('./dependencies'),
|
|
|
|
} : {
|
|
|
|
app: './public/app/index.ts',
|
2017-10-01 13:02:25 -05:00
|
|
|
dark: './public/sass/grafana.dark.scss',
|
|
|
|
light: './public/sass/grafana.light.scss',
|
2017-10-03 04:02:40 -05:00
|
|
|
vendor: require('./dependencies'),
|
2018-04-18 08:01:36 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = merge(common, {
|
|
|
|
devtool: "cheap-module-source-map",
|
|
|
|
|
|
|
|
entry: entries,
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions: ['.scss', '.ts', '.tsx', '.es6', '.js', '.json', '.svg', '.woff2', '.png'],
|
|
|
|
},
|
|
|
|
|
|
|
|
devServer: {
|
|
|
|
publicPath: '/public/build/',
|
|
|
|
hot: HOT,
|
|
|
|
port: 3333,
|
|
|
|
proxy: {
|
|
|
|
'!/public/build': 'http://localhost:3000'
|
|
|
|
}
|
2017-10-01 13:02:25 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
2018-04-18 08:01:36 -05:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
enforce: 'pre',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'tslint-loader',
|
|
|
|
options: {
|
|
|
|
emitErrors: true,
|
|
|
|
typeCheck: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
plugins: [
|
2018-04-26 04:58:42 -05:00
|
|
|
'syntax-dynamic-import',
|
2018-04-18 08:01:36 -05:00
|
|
|
'react-hot-loader/babel',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'awesome-typescript-loader',
|
|
|
|
options: {
|
|
|
|
useCache: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2017-10-01 13:02:25 -05:00
|
|
|
require('./sass.rule.js')({
|
2018-05-07 10:02:55 -05:00
|
|
|
sourceMap: true, minimize: false, preserveUrl: HOT
|
2018-04-18 08:01:36 -05:00
|
|
|
}, extractSass),
|
|
|
|
{
|
|
|
|
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
|
|
|
|
loader: 'file-loader'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|gif)$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2017-10-01 13:02:25 -05:00
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
2018-04-18 08:01:36 -05:00
|
|
|
new CleanWebpackPlugin('../public/build', { allowExternal: true }),
|
|
|
|
extractSass,
|
2017-10-01 13:02:25 -05:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
filename: path.resolve(__dirname, '../../public/views/index.html'),
|
|
|
|
template: path.resolve(__dirname, '../../public/views/index.template.html'),
|
|
|
|
inject: 'body',
|
|
|
|
chunks: ['manifest', 'vendor', 'app'],
|
2018-04-18 08:01:36 -05:00
|
|
|
alwaysWriteToDisk: HOT
|
2017-10-01 13:02:25 -05:00
|
|
|
}),
|
2018-04-18 08:01:36 -05:00
|
|
|
new HtmlWebpackHarddiskPlugin(),
|
|
|
|
new webpack.NamedModulesPlugin(),
|
|
|
|
new webpack.HotModuleReplacementPlugin(),
|
2017-10-01 13:02:25 -05:00
|
|
|
new webpack.DefinePlugin({
|
2018-04-18 08:01:36 -05:00
|
|
|
'GRAFANA_THEME': JSON.stringify(process.env.GRAFANA_THEME || 'dark'),
|
2017-10-01 13:02:25 -05:00
|
|
|
'process.env': {
|
|
|
|
'NODE_ENV': JSON.stringify('development')
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
new webpack.optimize.CommonsChunkPlugin({
|
|
|
|
names: ['vendor', 'manifest'],
|
|
|
|
}),
|
2017-10-03 05:18:22 -05:00
|
|
|
// new BundleAnalyzerPlugin({
|
|
|
|
// analyzerPort: 8889
|
|
|
|
// })
|
2017-10-01 13:02:25 -05:00
|
|
|
]
|
|
|
|
});
|