-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
99 lines (96 loc) · 2.29 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
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const StringReplacePlugin = require("string-replace-webpack-plugin");
let K_ENV = 'dev';
const K_ENV_DEV = 'dev';
const K_ENV_TEST = 'test';
const K_ENV_PROD = 'prod';
if (process.env.K_ENV) {
K_ENV = process.env.K_ENV;
}
module.exports = {
mode:'development',
context: path.join(__dirname),
entry: [
'./src/main.webpack.js'
],
resolve: {
extensions: ['.js', '.html']
},
output: {
path: path.join(__dirname, 'public'),
filename: 'js/bundle.js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.html$/,
use: [{
loader: 'svelte-loader',
query: {
dev: true,
hotReload: true,
emitCss: false,
store: true
}
},
{
loader: StringReplacePlugin.replace({
replacements:[{
pattern: /_COMPONENT_/g,
replacement: function(){
var id = this.resourcePath,
parts = id.split(path.sep);
return parts.pop().split('.').shift();
}
},{
pattern: /_FILE_/g,
replacement: function(){
var id = this.resourcePath,
parts = id.split(path.sep);
return parts.pop();
}
}]
})
}]
},
{
test: /\.scss$/,
use: [
'css-hot-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
query: {
url: false
}
},
'sass-loader'
]
}
]
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
K_ENV: JSON.stringify(K_ENV),
K_ENV_DEV: JSON.stringify(K_ENV_DEV),
K_ENV_TEST: JSON.stringify(K_ENV_TEST),
K_ENV_PROD: JSON.stringify(K_ENV_PROD)
}),
new StringReplacePlugin(),
new MiniCssExtractPlugin({
filename: "css/global.css"
})
].filter(Boolean),
devServer: {
contentBase: './public',
port: 5000,
host: '0.0.0.0',
hotOnly: true
},
devtool: 'inline-source-map'
};