influxdb/ui/webpack/dev.config.js

233 lines
6.0 KiB
JavaScript
Raw Normal View History

const path = require('path')
const fs = require('fs')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const WebpackOnBuildPlugin = require('on-build-webpack')
const HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plugin')
const keys = require('lodash/keys')
const difference = require('lodash/difference')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const buildDir = path.resolve(__dirname, '../build')
2018-03-22 21:50:05 +00:00
const babelLoader = {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: [['env', {modules: false}], 'react', 'stage-0'],
},
}
2018-03-22 21:50:55 +00:00
const stats = {
colors: true,
children: false,
modules: false,
version: false,
assetsSort: '!size',
excludeAssets: [/\.(hot-update|woff|eot|ttf|svg|ico|png)/],
}
module.exports = {
2018-03-22 21:50:55 +00:00
stats,
2018-02-20 15:23:53 +00:00
node: {
fs: 'empty',
module: 'empty',
},
watch: true,
cache: true,
devtool: 'cheap-eval-source-map',
entry: {
2018-03-29 17:14:24 +00:00
app: path.resolve(__dirname, '..', 'src', 'index.tsx'),
},
output: {
publicPath: '/',
path: path.resolve(__dirname, '../build'),
filename: '[name].[hash].dev.js',
},
resolve: {
alias: {
src: path.resolve(__dirname, '..', 'src'),
shared: path.resolve(__dirname, '..', 'src', 'shared'),
style: path.resolve(__dirname, '..', 'src', 'style'),
utils: path.resolve(__dirname, '..', 'src', 'utils'),
},
extensions: ['.ts', '.tsx', '.js'],
},
module: {
noParse: [
path.resolve(
__dirname,
'..',
'node_modules',
'memoizerific',
'memoizerific.js'
),
],
rules: [
2018-03-21 22:31:40 +00:00
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
loader: 'tslint-loader',
enforce: 'pre',
options: {
emitWarning: true,
2018-03-22 21:51:25 +00:00
configFile: path.resolve(__dirname, '..', 'tslint.json'),
2018-03-21 22:31:40 +00:00
},
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
2018-02-20 00:04:38 +00:00
enforce: 'pre',
2018-03-09 23:24:23 +00:00
options: {
2018-03-21 22:31:40 +00:00
emitWarning: true,
},
},
{
test: /\.scss$/,
2018-02-20 00:04:38 +00:00
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
'sass-loader',
'resolve-url-loader',
'sass-loader?sourceMap',
],
}),
},
{
test: /\.css$/,
2018-02-20 00:04:38 +00:00
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader'],
}),
},
{
test: /\.(ico|png|cur|jpg|ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
2018-02-20 00:04:38 +00:00
loader: 'file-loader',
},
{
test: /\.js$/,
include: path.resolve(__dirname, '..', 'src'),
exclude: /node_modules/,
use: [
2018-03-05 16:44:53 +00:00
{loader: 'thread-loader'},
{
loader: 'babel-loader',
options: {
presets: ['env', 'react', 'stage-0'],
plugins: ['transform-decorators-legacy'],
cacheDirectory: true, // use a cache directory to speed up compilation
},
},
],
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'thread-loader',
options: {
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
workers: require('os').cpus().length - 1,
},
},
babelLoader,
{
loader: 'ts-loader',
options: {
happyPackMode: true, // required for use with thread-loader
},
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
2018-02-24 18:31:39 +00:00
new webpack.DllReferencePlugin({
context: process.cwd(),
2018-02-26 04:45:46 +00:00
manifest: require('../build/vendor.dll.json'),
2018-02-24 18:31:39 +00:00
}),
new ForkTsCheckerWebpackPlugin({
checkSyntacticErrors: true,
}),
2018-02-20 00:04:38 +00:00
new webpack.LoaderOptionsPlugin({
options: {
postcss: require('./postcss'),
sassLoader: {
includePaths: [path.resolve(__dirname, 'node_modules')],
},
eslint: {
failOnWarning: false,
failOnError: false,
},
},
}),
new webpack.HotModuleReplacementPlugin(),
new ExtractTextPlugin('chronograf.css'),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, '..', 'src', 'index.template.html'),
inject: 'body',
favicon: 'assets/images/favicon.ico',
}),
new HtmlWebpackIncludeAssetsPlugin({
assets: ['vendor.dll.js'],
append: false,
2016-09-30 20:16:24 +00:00
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(require('../package.json').version),
}),
2018-03-22 21:51:25 +00:00
new WebpackOnBuildPlugin(webpackStats => {
const newlyCreatedAssets = webpackStats.compilation.assets
fs.readdir(buildDir, (readdirErr, buildDirFiles) => {
if (readdirErr) {
console.error('webpack build directory error')
return
}
const assetFileNames = keys(newlyCreatedAssets)
const filesToRemove = difference(buildDirFiles, assetFileNames)
for (const file of filesToRemove) {
if (file.includes('dll')) {
return
}
const ext = path.extname(file)
if (['.js', '.json', '.map'].includes(ext)) {
fs.unlink(path.join(buildDir, file), unlinkErr => {
if (unlinkErr) {
console.error('webpack cleanup error', unlinkErr)
}
})
}
}
})
}),
],
target: 'web',
devServer: {
2018-03-22 21:51:45 +00:00
stats,
hot: true,
historyApiFallback: true,
2017-11-09 18:01:21 +00:00
clientLogLevel: 'info',
contentBase: 'build',
quiet: false,
watchOptions: {
aggregateTimeout: 300,
2017-11-09 18:01:21 +00:00
poll: 1000,
},
proxy: {
'/chronograf/v1': {
target: 'http://localhost:8888',
secure: false,
},
},
},
}