forked from divkit/divkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack-dev.config.js
179 lines (167 loc) · 6.67 KB
/
webpack-dev.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { typescript/*, postcss*/ } = require('svelte-preprocess');
const { asMarkupPreprocessor } = require('svelte-as-markup-preprocessor');
// const cssModules = require('svelte-preprocess-cssmodules');
// const { version } = require('../package.json');
const isProd = process.env.NODE_ENV === 'production';
const configCommon = isServer => ({
mode: isProd ? 'production' : 'development',
devtool: isProd ? false : 'cheap-module-source-map',
output: {
publicPath: '/',
path: path.resolve(__dirname, 'dist')
},
optimization: {
minimizer: [
'...',
new CssMinimizerPlugin()
]
},
resolve: {
extensions: ['.ts', '.js', '.svelte', '.d.ts'],
},
module: {
rules: [
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
localIdentName: isProd ? 'divkit-[hash:4]' : '[local]-[hash:4]'
}
}
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('autoprefixer')
]
}
}
},
// require.resolve('postcss-loader')
// 'style-loader',
// 'css-loader'
],
},
{
test: /\.svelte$/,
use: {
loader: 'svelte-loader',
options: {
preprocess: [
asMarkupPreprocessor([
typescript(),
/*postcss({
plugins: [
require('autoprefixer')
]
})*/
]),
/*cssModules({
useAsDefaultScoping: true,
// localIdentName: 'divkit-[local]',
localIdentName: 'divkit-[local]-[hash:3]',
// localIdentName: 'divkit-[hash:4]',
// localIdentName: '[hash:4]',
includeAttributes: ['cls'],
parseExternalStylesheet: true
})*/
],
/*preprocess: sveltePreprocess({
typescript: true
}),*/
onwarn(e, cb) {
if (e.message.includes('has unused export property')) {
return;
}
cb(e);
},
compilerOptions: isServer ? {
generate: 'ssr'
} : {
dev: !isProd,
hydratable: true,
immutable: true,
accessors: true
},
emitCss: isProd,
// emitCss: true,
hotReload: !isProd,
hotOptions: isProd ? undefined : {
// 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,
}
}
},
},
{
test: /\.[jt]s$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: require.resolve('babel-loader'),
options: {
presets: [
['@babel/preset-env', {
browserslistEnv: isServer ? 'ssr' : 'development'
}],
'@babel/preset-typescript'
]
}
}
}
]
}
});
module.exports = [{
...configCommon(false),
target: 'web',
entry: {
client: './src/dev.ts',
},
output: {
// libraryTarget: 'commonjs'
},
plugins: [
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'dev.html'),
scriptLoading: 'blocking'
}),
!isProd && new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.DEVTOOL': JSON.stringify(true),
'process.env.IS_PROD': JSON.stringify(isProd)
})
].filter(Boolean),
devServer: isProd ? undefined : {
// hot: true,
// contentBase: path.resolve(__dirname, 'src')
}
}];