forked from GeoffreyHuck/skulpt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
112 lines (102 loc) · 3.72 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
const path = require('path');
const webpack = require('webpack');
const shell = require('shelljs');
const chalk = require('chalk');
const ClosureWebpackPlugin = require('closure-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const GitRevisionPlugin = require('git-revision-webpack-plugin');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const git = new GitRevisionPlugin({branch: true});
const styleexcludes = /(node_modules)|(support)|(gen)|(tokenize.js)|(symtable.js)|(compile.js)|(ast.js)|(internalpython.js)/;
if (!shell.which('git')) {
console.log(chalk.red("WARNING: Cannot find git! Unsure if working directory is clean."));
}
var output = shell.exec('git diff-index --quiet HEAD');
if (output.code !== 0) {
console.log(chalk.red("WARNING: Working directory is not clean."));
} else {
console.log("Working directory is clean.");
}
module.exports = (env, argv) => {
var opt = {
minimize: false
};
var outfile = 'skulpt.js';
var assertfile = './assert-dev.js';
var mod = {};
var languageOut = (env && env.languageOut) || '';
if (argv.mode === 'production') {
opt = {
noEmitOnErrors: true,
minimizer: [
new ClosureWebpackPlugin({mode: 'STANDARD'}, {
jscomp_error: ['accessControls', 'checkRegExp', 'checkVars', /*'checkTypes',*/
'invalidCasts', 'missingProperties',
'nonStandardJsDocs', 'strictModuleDepCheck', 'undefinedVars',
'unknownDefines', 'visibility'],
jscomp_off: ['fileoverviewTags', 'deprecated', 'uselessCode', 'suspiciousCode', 'checkTypes',],
languageOut: languageOut || 'ECMASCRIPT_2015',
externs: 'support/externs/sk.js',
rewritePolyfills: true,
// compiler flags here
//
// for debugging help, try these:
//
// warningLevel: "QUIET",
// formatting: 'PRETTY_PRINT',
// debug: true,
// renaming: false
})
]
};
outfile = 'skulpt.min.js';
assertfile = './assert-prod.js';
mod = {
rules: [
{
test: /\.js$/,
enforce: 'pre',
exclude: styleexcludes,
loader: 'eslint-loader'
}
]
};
}
var config = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: outfile
},
devtool: 'source-map',
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin([
{ from: 'debugger/debugger.js', to: 'debugger.js' }
]),
new webpack.DefinePlugin({
GITVERSION: JSON.stringify(git.version()),
GITHASH: JSON.stringify(git.commithash()),
GITBRANCH: JSON.stringify(git.branch()),
BUILDDATE: JSON.stringify(new Date())
}),
new CompressionWebpackPlugin({
include: /^skulpt\.min\.js$/,
algorithm: 'gzip'
})
],
optimization: opt,
resolve: {
alias: {
'assert': assertfile,
}
},
module: mod,
// uncomment this while working on closure compiler errors
// externals: {
// jsbi: "JSBI",
// }
};
return config;
};