forked from klembot/chapbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
110 lines (99 loc) · 2.14 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
100
101
102
103
104
105
106
107
108
109
110
const fs = require('fs');
const CssPlugin = require('mini-css-extract-plugin');
const HtmlPlugin = require('html-webpack-plugin');
const path = require('path');
const TwineStory = require('twine-utils/story');
const isRelease = process.env.NODE_ENV === 'production';
const isMicro = process.env.CHAPBOOK_MICRO === 'y';
const browserSupport = ['defaults'];
const htmlMinifyOptions = {collapseWhitespace: true};
const args = require('yargs')
.default('example', 'hello-world')
.alias('e', 'example').argv;
const config = {
devServer: {
disableHostCheck: true,
stats: 'minimal',
},
mode: isRelease ? 'production' : 'development',
module: {
rules: [
{
test: /\.jsx$/,
use: {
loader: 'babel-loader',
options: {
presets: [['preact']],
},
},
},
{
test: /\.scss$/,
use: [
CssPlugin.loader,
{loader: 'css-loader', options: {minimize: isRelease}},
'sass-loader',
],
},
{
test: /\.svg$/,
use: ['url-loader'],
},
],
},
output: {
path: path.resolve(__dirname, `dist/${isMicro ? 'micro' : 'full'}`),
},
plugins: [
new CssPlugin({filename: '[name].css'}),
new HtmlPlugin({
inject: !isRelease,
minify: isRelease && htmlMinifyOptions,
template: 'src/index.ejs',
templateParameters(compilation, assets, options) {
if (isRelease) {
return {
storyData: '{{STORY_DATA}}',
inline: true,
assets,
compilation,
options,
};
}
const story = new TwineStory();
story.mergeTwee(
fs.readFileSync(
path.resolve(__dirname, `./examples/${args.example}.txt`),
{
encoding: 'utf8',
}
)
);
story.attributes.name = args.example;
story.setStartByName('Start');
return {storyData: story.toHtml(), inline: false};
},
}),
],
resolve: {
extensions: ['.js', '.jsx'],
},
};
if (isMicro) {
config.externals = {
'./backstage': 'undefined',
};
}
if (isRelease) {
config.module.rules.push({
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [['env', {targets: {browsers: browserSupport}}]],
},
},
});
}
module.exports = config;