forked from enterstudio/Glitch-Community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
157 lines (152 loc) · 4.75 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const path = require('path');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const AutoprefixerStylus = require('autoprefixer-stylus');
const StatsPlugin = require('stats-webpack-plugin');
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const aliases = require('./shared/aliases');
const BUILD = path.resolve(__dirname, 'build');
const SRC = path.resolve(__dirname, 'src');
const SHARED = path.resolve(__dirname, 'shared');
const STYLES = path.resolve(__dirname, 'styles');
const NODE_MODULES = path.resolve(__dirname, 'node_modules');
const STYLE_BUNDLE_NAME = 'styles';
let mode = 'development';
if (process.env.NODE_ENV === 'production') {
mode = 'production';
}
const smp = new SpeedMeasurePlugin({ outputFormat: 'humanVerbose' });
console.log(`Starting Webpack in ${mode} mode.`);
module.exports = smp.wrap({
mode,
entry: {
client: `${SRC}/client.js`,
[STYLE_BUNDLE_NAME]: `${STYLES}/styles.styl`,
},
output: {
filename: '[name].[chunkhash:8].js',
path: BUILD,
publicPath: '/',
},
devtool: mode === 'production' ? 'source-map' : 'cheap-module-source-map',
optimization: {
splitChunks: {
chunks: 'initial',
maxInitialRequests: 5,
cacheGroups: {
curated: {
name: 'curated',
test: /[\\/]src[\\/]curated[\\/]/,
minSize: 0,
},
react: {
name: 'react',
test: /[\\/]node_modules[\\/]react[-\\/]/,
},
modules: {
name: 'dependencies',
test: /[\\/]node_modules[\\/]/,
priority: -1,
},
},
},
minimizer: [new TerserPlugin({ terserOptions: { safari10: true }, sourceMap: true })],
noEmitOnErrors: true,
runtimeChunk: {
name: "manifest"
}
},
context: path.resolve(__dirname),
resolve: {
extensions: ['.js'],
alias: aliases,
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
include: SRC,
loader: 'eslint-loader',
options: {
fix: false, //mode === 'development', // Only change source files in development
cache: false, // Keep this off, it can use a lot of space. Let Webpack --watch do the heavy lifting for us.
emitError: false,
emitWarning: true,
failOnError: false,
ignorePattern: 'src/curated/**',
},
},
{
oneOf: [
{
test: /\.js$/,
loader: 'babel-loader',
include: mode === 'development' ? [SRC, SHARED] : [SRC, SHARED, NODE_MODULES],
query: {
compact: mode === 'development' ? true : false,
},
},
{
test: /\.styl/,
include: SRC,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader?modules',
options: {
sourceMap: mode !== 'production', // no css source maps in production
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]',
},
},
{
loader: 'stylus-loader',
options: {
compress: mode === 'production', // Compress CSS as part of the stylus build
use: [AutoprefixerStylus()],
},
},
],
},
{
test: /\.styl$/,
include: STYLES,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: mode !== 'production', // no css source maps in production
},
},
{
loader: 'stylus-loader',
options: {
compress: mode === 'production', // Compress CSS as part of the stylus build
use: [AutoprefixerStylus()],
},
},
],
},
],
},
],
},
plugins: [
new LodashModuleReplacementPlugin({ shorthands: true }), // adding shorthands fixes https://github.com/lodash/lodash/issues/3101
new MiniCssExtractPlugin({ filename: '[name].[contenthash:8].css' }),
new StatsPlugin('stats.json', {
all: false,
entrypoints: true,
hash: true,
publicPath: true,
}),
new CleanWebpackPlugin({ dry: false, cleanStaleWebpackAssets: true, verbose: true, cleanOnceBeforeBuildPatterns: ['**/*', '!storybook/*', '!stats.json']}),
],
watchOptions: {
ignored: /node_modules/,
},
});