This repository was archived by the owner on Oct 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
91 lines (87 loc) · 2.19 KB
/
Copy pathwebpack.config.js
File metadata and controls
91 lines (87 loc) · 2.19 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
const webpack = require('webpack')
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const importFresh = require('import-fresh')
const sass = require('node-sass')
const postcss = require('postcss')
const mode = process.env.NODE_ENV || 'development'
const prod = mode === 'production'
const svelteLoaders = [{
loader: 'svelte-loader',
options: {
preprocess: {
style: async (input) => {
const postCssOpts = {
from: input.filename.replace(__dirname, '').replace('.svelte', '.css'),
to: input.filename.replace(__dirname, '').replace('/build/', '/src/')
}
let result = sass.renderSync({
data: input.content
})
result = await postcss(require('./postcss.config')).process(result.css.toString(), postCssOpts)
return {
code: result.css.toString()
}
}
},
emitCss: false,
css: false,
hydratable: true
}
}]
if (prod) {
svelteLoaders.unshift({
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
useBuiltIns: 'entry',
corejs: 3
}]
],
sourceType: 'unambiguous'
}
})
}
/**
* Webpack is used to generate the client js files for hydration
* Each route will have its own js to ensure that it only loads
* the minimum svelte component.
*/
module.exports = {
entry: Object.assign({ 'bulma': './build/ui/assets/main.scss' }, importFresh('./build/client.json')),
mode: process.env.NODE_ENV || 'development',
output: {
libraryTarget: 'umd',
library: 'page',
path: path.resolve(__dirname, 'public')
},
module: {
rules: [
{
test: /\.(sass|scss)$/,
use: [
prod ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'sass-loader'
]
},
{
test: /\.(html|svelte)$/,
exclude: /node_modules/,
use: svelteLoaders
}
]
},
mode,
devtool: prod ? false : 'source-map',
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: 'development'
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
})
]
}