forked from NatLibFi/qvain-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack-old.config.js
158 lines (152 loc) · 5.02 KB
/
webpack-old.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// build file for Qvain Javascript code
//
// This webpack config file packs the javascript code for Qvain into two bundles:
// - our javascript code and component files for widgets (all ES2015/ES6) get transpiled and bundled into app.bundle.js;
// - needed libraries (mainly vue and vue-router) go into vendor.bundle.js.
//
// See also: vue webpack-simple template https://github.com/vuejs-templates/webpack-simple
const path = require('path')
const webpack = require('webpack')
//process.traceDeprecation = true;
function envToBool(envVar) {
return process.env[envVar] === undefined || process.env[envVar] == "" || process.env[envVar] == "0" || process.env[envVar] == "false" || process.env[envVar] == "no" ? false : true
}
//const ISDEVBUILD = envToBool('APP_DEBUG');
// if APP_DEBUG is set to a true value, we are doing development; set NODE_ENV accordingly if not already set
if (process.env.NODE_ENV === undefined && process.env.APP_DEBUG !== undefined) {
//var debugMode = process.env.APP_DEBUG === undefined || process.env.APP_DEBUG == "" || process.env.APP_DEBUG == "0" || process.env.APP_DEBUG == "no" ? false : true;
//console.log("APP_DEBUG:", process.env.APP_DEBUG);
//console.log("debugMode set to", debugMode);
process.env.NODE_ENV = envToBool('APP_DEBUG') ? 'development' : 'production'
console.log("NODE_ENV set to", process.env.NODE_ENV)
}
module.exports = {
context: path.resolve(__dirname, './src'),
entry: {
app: './app.js',
vendor: ['vue', 'vue-router'],
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: '[name].bundle.js',
},
module: {
rules: [
// .vue component files: code compiles into the source as modules, HTML parts get compiled to render functions for those respective components; we don't use CSS/SASS here!
{
test: /\.vue$/,
loader: 'vue-loader',
/*
options: {
loaders: {
{{#sass}}
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': 'vue-style-loader!css-loader!sass-loader',
'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
{{/sass}}
}
// other vue-loader options go here
}
*/
},
// code is written in ES2015/ES6
// see also: https://github.com/babel/babel-loader
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
/* ["es2015", { "modules": false }], */
["env", { "modules": false }],
],
plugins: [require('babel-plugin-transform-object-rest-spread')],
},
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
},
// ideally all modules would be in the es2015/ES6 format as it's the closest thing to a standard; ours are, but import'ed code in our app might not be, so we can't force it
//
// see also:
// https://hacks.mozilla.org/2015/08/es6-in-depth-modules/
// https://www.jvandemo.com/a-10-minute-primer-to-javascript-modules-module-formats-module-loaders-and-module-bundlers/
//
// formats (uneducated guess):
// amd: some browsers; commonjs: node (also called "cjs"); systemjs: ES6 backported to ES5; harmony: ES6; browserify: commonjs + node functions; requirejs: most popular implementation of amd
{
parser: {
//amd: false,
//commonjs: false,
//systemjs: false,
//harmony: false,
//browserify: false,
//requirejs: false,
},
},
],
},
plugins: [
// split libraries into a vendor bundle
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
//filename: "vendor.js",
//minChunks: 2,
}),
// define constants that get compiled into the application
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"',
/* process.env.NODE_ENV !== 'production'; */
},
'APP_DEBUG': envToBool('APP_DEBUG'),
'magicalnumber': 666,
'SERVICE_URL': JSON.stringify("http://dev.example.com"),
}),
],
resolve: {
alias: {
// refer to the ES6-formatted module of Vue, not the old Node format; Vue in Node comes in multiple module formats
'vue$': 'vue/dist/vue.esm.js',
},
},
externals: {
//'bootstrap-vue': 'bootstrapVue',
//BootstrapVue: 'bootstrapVue',
},
devtool: 'cheap-module-eval-source-map', /* 'eval-source-map' */
node: {
setImmediate: false,
},
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
if (module.exports.resolve && module.exports.resolve.alias) {
delete module.exports.resolve['vue$']
}
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false,
},
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
}),
])
}