forked from RedHatGov/ocdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
93 lines (83 loc) · 3.22 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
81
82
83
84
85
86
87
88
89
90
91
92
93
const Webpack = require("webpack");
const Glob = require("glob");
const path = require('path');
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ManifestPlugin = require("webpack-manifest-plugin");
const CleanObsoleteChunks = require('webpack-clean-obsolete-chunks');
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const LiveReloadPlugin = require('webpack-livereload-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const configurator = {
plugins() {
var plugins = [
new CleanObsoleteChunks(),
new Webpack.ProvidePlugin({$: "jquery",jQuery: "jquery"}),
new MiniCssExtractPlugin({filename: "[name].[contenthash].css"}),
new CopyWebpackPlugin({patterns: [{from: "./assets",to: ""}]}, {copyUnmodified: true,ignore: ["css/**", "js/**", "src/**"] }),
new Webpack.LoaderOptionsPlugin({minimize: true,debug: false}),
new ManifestPlugin({fileName: "manifest.json"})
];
return plugins
},
moduleOptions: function() {
return {
rules: [
{
test: /\.s[ac]ss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: {sourceMap: true}},
{ loader: "sass-loader", options: {sourceMap: true, includePaths: [ "/node_modules/@patternfly/patternfly/" ]}}
]
},
{ test: /\.tsx?$/, use: "ts-loader", exclude: /node_modules/},
{ test: /\.jsx?$/, loader: "babel-loader",exclude: /node_modules/ },
{ test: /\.(woff|woff2|ttf|svg|png|jpg)(\?v=\d+\.\d+\.\d+)?$/,use: "url-loader"},
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,use: "file-loader" },
{ test: require.resolve("jquery"),use: "expose-loader?jQuery!expose-loader?$"},
{ test: /\.css$/, use: ["style-loader", "css-loader"] },
{ test: /\.mdx?$/, use: ['babel-loader', '@mdx-js/loader']},
]
}
},
buildConfig: function(){
// NOTE: If you are having issues with this not being set "properly", make
// sure your GO_ENV is set properly as `buffalo build` overrides NODE_ENV
// with whatever GO_ENV is set to or "development".
const env = process.env.NODE_ENV || "development";
var config = {
mode: env,
entry: { app: path.resolve(__dirname, 'assets', 'src', 'index.tsx') },
output: {filename: "[name].[hash].js", path: `${__dirname}/public/assets`},
plugins: configurator.plugins(),
module: configurator.moduleOptions(),
resolve: {
extensions: ['.ts', '.js', '.json', '.tsx', '.md'],
plugins: [
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, './tsconfig.json')
})
]
},
node: { fs: 'empty' },
}
if( env === "development" ){
config.plugins.push(new LiveReloadPlugin({appendScriptTag: true}))
return config
}
const uglifier = new UglifyJsPlugin({
uglifyOptions: {
beautify: false,
mangle: {keep_fnames: true},
output: {comments: false},
compress: {}
}
})
config.optimization = {
minimizer: [uglifier]
}
return config
}
}
module.exports = configurator.buildConfig()