-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
135 lines (127 loc) · 4.03 KB
/
Copy pathwebpack.config.js
File metadata and controls
135 lines (127 loc) · 4.03 KB
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
// Main imports | DON'T CHANGE
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackNotifierPlugin = require('webpack-notifier');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const SveltePreprocess = require('svelte-preprocess');
const pkg = require('./package.json');
// Project related settings
const ENV = process.env.NODE_ENV || 'development';
const isProd = ENV === 'production';
const dist = './dist';
const port = 8080;
// Webpack configuration | DON'T CHANGE
module.exports = {
entry: {
main: './src/index.js'
},
mode: ENV,
output: {
path: path.join(__dirname, dist),
filename: 'bundle.js',
chunkFilename: 'bundle.[chunk].js'
},
plugins: [
new MiniCssExtractPlugin({ filename: "[name].[chunkhash].css" }),
new WebpackNotifierPlugin({
title: pkg.displayName,
alwaysNotify: true
}),
new HtmlWebpackPlugin({
title: pkg.displayName,
template: './src/html/index.html'
})
],
resolve: {
// see below for an explanation
alias: {
svelte: path.resolve('node_modules', 'svelte')
},
extensions: ['.mjs', '.js', '.svelte'],
mainFields: ['svelte', 'browser', 'module', 'main']
},
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [
new CssMinimizerPlugin(),
],
},
module: {
rules: [
{
test: /\.(svelte)$/,
exclude: /node_modules/,
use: {
loader: 'svelte-loader',
options: {
compilerOptions: {
// NOTE Svelte's dev mode MUST be enabled for HMR to work
dev: !isProd,
},
// NOTE emitCss: true is currently not supported with HMR
// Enable it for production to output separate css file
emitCss: isProd, // Default: false
// Enable HMR only for dev mode
hotReload: !isProd, // Default: false
// Extra HMR options, the defaults are completely fine
// You can safely omit hotOptions altogether
hotOptions: {
// Prevent preserving local component state
preserveLocalState: false,
// If this string appears anywhere in your component's code, then local
// state won't be preserved, even when noPreserveState is false
noPreserveStateKey: '@!hmr',
// Prevent doing a full reload on next HMR update after fatal error
noReload: false,
// Try to recover after runtime errors in component init
optimistic: false,
// --- Advanced ---
// Prevent adding an HMR accept handler to components with
// accessors option to true, or to components with named exports
// (from <script context="module">). This have the effect of
// recreating the consumer of those components, instead of the
// component themselves, on HMR updates. This might be needed to
// reflect changes to accessors / named exports in the parents,
// depending on how you use them.
acceptAccessors: true,
acceptNamedExports: true,
},
preprocess: SveltePreprocess({
scss: true,
sass: true,
})
}
}
},
{
test: [/\.s[ac]ss$/i, /\.css$/],
use: [
isProd ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
"sass-loader"
],
},
{
// required to prevent errors from Svelte on Webpack 5+, omit on Webpack 4
test: /node_modules\/svelte\/.*\.mjs$/,
resolve: {
fullySpecified: false
}
}
]
},
devServer: {
contentBase: path.join(__dirname, dist),
watchContentBase: true,
watchOptions: {
poll: true
},
compress: true,
port: port,
host: 'localhost',
hot: true,
inline: true
}
};