forked from klembot/twinejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
130 lines (124 loc) · 2.89 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const PoPlugin = require('./webpack/po-webpack-plugin');
const Autoprefixer = require('less-plugin-autoprefix');
const package = require('./package.json');
const isRelease = process.env.NODE_ENV === 'production';
const useCdn = process.env.USE_CDN === 'y';
const useElectron = process.env.USE_ELECTRON === 'y';
const config = (module.exports = {
mode: isRelease ? 'production' : 'development',
entry: './src/index.js',
target: useElectron ? 'electron-renderer' : 'web',
output: {
path: path.join(
__dirname,
'dist',
useCdn ? 'web-cdn' : useElectron ? 'web-electron' : 'web'
),
filename: 'twine.js'
},
module: {
rules: [
/*
Inline resources below 10k in size.
*/
{
test: /\.(eot|png|svg|ttf|woff|woff2)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'rsrc/[name].[hash].[ext]'
}
},
/*
We must exclude the top-level template, as I think the HTML plugin
is expecting a string as output, not a function.
*/
{
test: /\.ejs$/,
exclude: /index\.ejs$/,
loader: 'ejs-webpack-loader'
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.less$/,
use: [
{loader: MiniCssExtractPlugin.loader},
{loader: 'css-loader', options: {minimize: isRelease}},
{
loader: 'less-loader',
options: {
plugins: [
new Autoprefixer({
browsers: package.browserslist.split(', ')
})
]
}
}
]
}
]
},
plugins: [
new CopyPlugin([
{from: 'src/common/img/favicon.ico', to: 'rsrc/favicon.ico'},
{from: 'story-formats/', to: 'story-formats/'},
{from: 'src/locale/view/img', to: 'rsrc/'},
{from: 'src/locale/po/*.js', to: 'locale/'}
]),
new HtmlPlugin({
template: './src/index.ejs',
package: package,
buildNumber: require('./scripts/build-number').number,
inject: false,
minify: isRelease && {collapseWhitespace: true},
cdn: useCdn
}),
new MiniCssExtractPlugin({filename: 'twine.css'}),
new PoPlugin({
src: 'src/locale/po/*.po',
dest: 'locale',
options: {
format: 'jed1.x',
domain: 'messages'
}
})
],
stats: 'minimal'
});
if (isRelease) {
/*
Transpile JS to our target platforms.
*/
config.module.rules.push({
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {presets: ['@babel/preset-env']}
});
}
if (useCdn) {
config.externals = {
codemirror: 'CodeMirror',
/*
core-js has no external interface, so we borrow an existing global
property.
*/
'core-js': 'location',
fastclick: 'FastClick',
jed: 'Jed',
jszip: 'JSZip',
moment: 'moment',
'svg.js': 'SVG',
'tether-drop': 'Drop',
vue: 'Vue',
'vue-router': 'VueRouter',
vuex: 'Vuex'
};
}