-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
126 lines (123 loc) · 3.24 KB
/
webpack.common.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
const { resolve } = require('path');
const sveltePreprocess = require('svelte-preprocess');
const svgToMiniDataURI = require('mini-svg-data-uri');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const isDevEnv = process.env.NODE_ENV === 'development';
const transpileDependencies = ['svelte'];
module.exports = {
mode: process.env.NODE_ENV,
devtool: isDevEnv ? 'eval-cheap-module-source-map' : 'source-map',
entry: './src/main.js',
output: {
publicPath: isDevEnv ? '/' : '/dist/',
filename: isDevEnv ? 'js/[name].js' : 'js/[name].[contenthash:8].js',
clean: true,
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: isDevEnv
? /node_modules/
: new RegExp(
`node_modules/(?!(${transpileDependencies.join('|')})/).*`
),
use: ['babel-loader'],
},
{
test: /\.(html|svelte)$/,
use: [
'babel-loader',
{
loader: 'svelte-loader',
options: {
emitCss: true,
hotReload: isDevEnv,
preprocess: sveltePreprocess({
scss: {
renderSync: true,
},
postcss: true,
}),
},
},
],
include: [resolve('./src/')],
},
{
test: /node_modules\/svelte\/.*\.mjs$/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false, // necessary if you use url('/path/to/some/asset.png|jpg|gif')
},
},
],
},
{
test: /\.(|png|jpe?g|gif)$/,
dependency: { not: ['url'] },
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
outputPath: 'images',
name: isDevEnv ? '[name].[ext]' : '[name].[contenthash:8].[ext]',
},
},
],
},
{
test: /\.svg$/,
type: 'asset/inline',
generator: {
dataUrl: (content) => svgToMiniDataURI(content.toString()),
},
},
{
test: /\.(woff|woff2|ttf|eot|ttf|otf)$/,
type: 'asset/resource',
generator: {
filename: isDevEnv
? 'fonts/[name].[ext]'
: 'fonts/[name].[contenthash:8].[ext]',
},
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: isDevEnv ? 'css/[name].css' : 'css/[name].[contenthash:8].css',
chunkFilename: isDevEnv ? 'css/[id].css' : 'css/[id].[contenthash:8].css',
}),
new HtmlWebpackPlugin({
title: 'Svelte App',
template: resolve('./public/index.html'),
filename: 'index.html',
}),
new ESLintPlugin({
extensions: ['js', 'svelte'],
files: './src/',
}),
],
optimization: {
runtimeChunk: 'single',
},
resolve: {
alias: {
svelte: resolve('./node_modules/svelte/'),
},
mainFields: ['svelte', 'browser', 'module', 'main'],
},
};