This repository was archived by the owner on Mar 12, 2023. It is now read-only.
forked from PinkaMinz/reepio
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
106 lines (98 loc) · 2.42 KB
/
webpack.config.js
File metadata and controls
106 lines (98 loc) · 2.42 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const fs = require('fs')
const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const clc = require('cli-color')
let env = getEnv()
let copyright = getCopyright()
let config = loadConfig(env)
let plugins = [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new webpack.DefinePlugin({
APP_ENV: JSON.stringify(env),
APP_CONFIG: JSON.stringify(config),
'process.env': {
'NODE_ENV': JSON.stringify(env)
}
}),
new ExtractTextPlugin({
filename: 'theme.css'
})
]
if (env !== 'dev') {
plugins = plugins.concat([
new webpack.BannerPlugin(copyright)
])
}
module.exports = {
entry: {
app: require.resolve(path.join(__dirname, 'src', 'js', 'app.js'))
},
output: {
path: path.resolve(__dirname, 'public/app'),
filename: '[name].bundle.js'
},
resolve: {
modules: [
'node_modules',
path.resolve(__dirname, 'src')
],
alias: {
jquery$: require.resolve('jquery/src/jquery')
},
extensions: ['.js', '.css', '.less']
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'babel-loader'
},
{
test: /\.less$/,
use: ExtractTextPlugin.extract([
{ loader: 'css-loader' },
{ loader: 'less-loader' }
])
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'url-loader',
options: {
limit: 10000
}
}
]
},
devtool: env === 'dev' ? 'eval' : false,
plugins: plugins
}
function getEnv () {
return process.env.NODE_ENV || 'dev'
}
function getCopyright () {
let licensePath = path.resolve(__dirname, 'COPYRIGHT')
try {
return fs.readFileSync(licensePath).toString()
} catch (e) {
console.error(clc.red(`no copyright file found at ${licensePath}`))
process.exit(1)
}
}
function getConfigurationPathForEnvironment (env) {
return path.resolve(__dirname, 'config', `config.${env}.js`)
}
function loadConfig (env) {
let envConfiguration = getConfigurationPathForEnvironment(env)
try {
return require(envConfiguration)
} catch (e) {
let defaultConfiguration = getConfigurationPathForEnvironment('production')
console.log(clc.yellow(`No config found for environment ${env}. Loading default configuration at ${defaultConfiguration}`))
return require(defaultConfiguration)
}
}