-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
198 lines (179 loc) · 6.18 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
var fs = require('fs')
var path = require('path')
var webpack = require('webpack')
var WebpackStrip = require('webpack-strip') // to remove console.log etc statement
var StringReplacePlugin = require('string-replace-webpack-plugin')
var host = 'localhost'
var port = 3000
var srcPath = 'src'
var production = process.env.NODE_ENV === 'production'
var testMode = (process.env.MODE === undefined || process.env.MODE !== 'production') ? true : false
console.log('running in production mode', production, 'in test mode', testMode)
var getSymlinkedModules = function () {
var rootPath = path.join(__dirname, 'node_modules')
var contents = fs.readdirSync(rootPath)
var results = contents
.map(function (entry) {
var fPath = path.join(rootPath, entry)
return fPath
})
.filter(function (fPath) {
function check (entry) {
var stats = fs.lstatSync(fPath)
return stats.isSymbolicLink()
}
return check(fPath)
})
.map(function (fPath) {
return fs.realpathSync(fPath)
})
return results
}
// add any extra folders we want to apply loaders to
var pathsToInclude = [path.join(__dirname, srcPath)] // getSymlinkedModules().concat( path.join(__dirname, srcPath) )
// FIXME !! temporary hack: add any paths where loaders should be apllied
// pathsToInclude.push( path.join(__dirname, "node_modules", "glView-helpers") )
// ugh, also needed because of workers (ie worker loader)
// pathsToInclude.push( path.join(__dirname, "node_modules", "usco-stl-parser") )
// pathsToInclude.push( path.join(__dirname, "node_modules", "usco-ctm-parser") )
// pathsToInclude.push( path.join(__dirname, "node_modules", "usco-ply-parser") )
console.log('pathsToInclude', pathsToInclude)
//pathsToInclude.push(path.join(__dirname, 'node_modules', 'usco-ym-storage'))
// console.log("will user loaders on",pathsToInclude)
var config = {
host: host,
port: port,
devtool: 'eval',
entry: {
jam: './' + srcPath + '/index'
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
publicPath: '/dist/' // '/'+'dist'+'/'
},
plugins: [
// new webpack.NoErrorsPlugin(),
// new webpack.optimize.DedupePlugin()
// new webpack.optimize.CommonsChunkPlugin("init.js")
new StringReplacePlugin()
],
module: {
loaders: [
{ test: /\.json$/, loader: 'json-loader' },
// { test: /-worker*\.js$/, loader: "worker-loader",include : pathsToInclude},//if any module does "require(XXX-worker)" it converts to a web worker
{ test: /\.js$/, loaders: ['babel'], exclude: /node_modules/}, // /* WebpackStrip.loader('console.log', 'console.error')*/
// include: pathsToInclude},//,
{ test: /\.css$/, loader: 'style-loader!css-loader' },
// special string replacements , could be cleaner
{ test: /index.js$/, loader: StringReplacePlugin.replace({
replacements: [
{
pattern: `mode = 'production'`,
replacement: function (match, p1, offset, string) {
return 'mode = "' + process.env.NODE_ENV + '"'
}
}
]})
}
],
noParse: [
/\.min\.js/
]
},
resolve: {
extensions: ['', '.js', '.jsx', 'json'],
root: [
path.join(__dirname, 'node_modules')
],
/* alias: {
"q$":path.join(__dirname, "node_modules","usco-kernel2/src/kernel.js"),//needed only FOR DEV
}*/
alias: {
'three$': path.join(__dirname, 'node_modules', 'three/three.min.js'),
}
},
resolveLoader: {
root: path.join(__dirname, 'node_modules')
}
}
// console.log("production",production,"dev",dev)
if (production) {
config.bail = true
config.debug = false
config.profile = false
config.output.pathInfo = false
config.output.publicPath = './dist/' // withouth this, issues with webworker paths
// config.devtool = "#source-map"
// config.output.filename = "[name].min.js"//"[name].[hash].min.js"
// config.output.chunkFilename = '[id].js'
config.plugins = config.plugins.concat([
new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify('production') } }),
new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1}),
new webpack.optimize.DedupePlugin(),
new webpack.NoErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({ minimize: true }) // ,drop_console:true})
/*
new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['require', 'export', '$super', 'import']
},
compress: {
warnings: false,
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true
}
})
, new CompressionPlugin({
asset: "{file}.gz",
algorithm: "gzip",
regExp: /\.js$|\.html$/,
threshold: 10240,
minRatio: 0.8
})*/
])
/* config.module= {
loaders: [
{ test: /\.json$/, loader: "json-loader" },//?optional[]=runtime&optional=es6.blockScoping
//{ test: /-worker*\.js$/, loader: "worker-loader",include : pathsToInclude},//if any module does "require(XXX-worker)" it converts to a web worker
//'react-hot',
{ test: /\.js?$/, loaders: [WebpackStrip.loader('console.log', 'console.error') ,'babel', ],include : pathsToInclude,exclude: /(node_modules|bower_components)/},
{ test: /\.css$/, loader: "style-loader!css-loader" },
//{ test: /\.js$/, loader: }
],
noParse: /\.min\.js/
}*/
var stripLoader = {
test: [],
loader: WebpackStrip.loader('console.log')
}
config.module.loaders.push(stripLoader)
} else {
/* config.entry = config.entry.concat([
//'webpack-dev-server/client?',//http://'+host+":"+port,
//'webpack/hot/only-dev-server',
])*/
/* var ymReplacerLoader = {
test: /youMagineDriver.js$/,loader: StringReplacePlugin.replace({
replacements: [
{
pattern: 'api.',
replacement: function (match, p1, offset, string) {
return 'api-test.'
}
}
]})
}
config.module.loaders.push(ymReplacerLoader)*/
config.plugins = config.plugins.concat([
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1})
])
}
module.exports = config