-
Notifications
You must be signed in to change notification settings - Fork 52
/
webpack.config.babel.js
63 lines (59 loc) · 1.5 KB
/
webpack.config.babel.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
import fs from 'fs'
import {promisify as p} from 'util'
import {DefinePlugin} from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import config from './src/config'
export default async (env, argv) => {
const production = argv.mode === `production`
const studentId = await p(fs.readFile)(`${__dirname}/.id`, `utf8`).then(v => v.trim())
const backend = production ? `csci-e39.herokuapp.com` : `localhost:${config.port}`
return {
devtool: `eval-cheap-module-source-map`,
entry: `./src/client.js`,
output: {
path: `${__dirname}/public`,
filename: `app.js`,
libraryTarget: `var`,
library: `MyApp`
},
plugins: [
new DefinePlugin({
__STUDENT_ID__: JSON.stringify(studentId),
__BACKEND__: JSON.stringify(backend),
}),
new HtmlWebpackPlugin({template: `src/index.html`}),
new MiniCssExtractPlugin({
filename: `[name].css`,
chunkFilename: `[id].css`
})
],
module: {
rules: [
{ test: /\.js$/, exclude: /node_modules/, loader: `babel-loader` },
{
test: /\.css$/,
use: [`style-loader`, `css-loader`],
},
{
test: /\.scss$/,
use: [
production ? `style-loader` : MiniCssExtractPlugin.loader,
`css-loader`,
`sass-loader`,
],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: `file-loader`,
options: {
name: `[name].[ext]`,
outputPath: `fonts/`,
},
}],
},
],
}
}
}