This repository was archived by the owner on Sep 25, 2025. It is now read-only.
forked from buildit/aem-react-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
84 lines (75 loc) · 2.23 KB
/
webpack.config.js
File metadata and controls
84 lines (75 loc) · 2.23 KB
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
var path = require('path')
var webpack = require('webpack')
const jcrPath = path.join(__dirname, 'src', 'content', 'jcr_root', 'etc', 'designs', 'react-demo', 'js', 'react-demo');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
let serverJs = false;
for (const idx in process.argv) {
let arg = process.argv[idx];
if (arg === '--env=production') {
process.env.NODE_ENV = 'production';
} else if (arg === '--env=development') {
process.env.NODE_ENV = 'development';
}
if (arg === '--server') {
serverJs = true;
}
}
const targetFileName = serverJs ? "server.js" : "app.js"
console.log("Webpack build for '" + process.env.NODE_ENV + "' -> " + targetFileName)
let entries = []
if (!serverJs) {
entries.push('./aem/client.jsx')
} else {
entries.push('./aem/server.jsx')
}
const config = {
entry: entries,
debug:true,
output: {
path: jcrPath,
filename: targetFileName
},
resolveLoader: {
root: path.join(__dirname, 'node_modules')
},
resolve: {
root: __dirname,
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx'],
modulesDirectories: [
path.join(__dirname, 'node_modules'),
path.join(__dirname, 'aem')
]
},
module: {
preLoaders: [
{ test: /\.(js|jsx)$/, exclude: [ /node_modules/, /vendor/ ], loader: 'eslint-loader' }
],
loaders: [
{ test: /\.(js|jsx)$/, exclude: [ /node_modules/, /vendor/ ], loader: 'babel' },
{ test: /\.(css)$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader') },
{ test: /\.(png|jpg|gif)$/, loader: 'file-loader' },
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader' }
]
},
eslint: {
failOnWarning: false,
failOnError: true
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': '"' + process.env.NODE_ENV + '"'
}
}),
new ExtractTextPlugin('[name].css', { allChunks: true })
]
}
if (process.env.NODE_ENV === 'production') {
config.plugins.push(new webpack.optimize.UglifyJsPlugin())
} else {
config.devtool = 'inline-source-map'
}
module.exports = [
config
]