This repository has been archived by the owner on Dec 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
123 lines (107 loc) · 2.85 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
const webpack = require('webpack');
const UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const path = require('path');
const env = require('yargs').argv.env;
const glob = require('glob');
const root = path.resolve(__dirname);
const src = path.join(root, 'src/main');
const test = path.join(root, 'src/test');
const dest = path.join(root, 'build');
let main = 'js/Common/App.js';
let libraryName = 'petfinder-site';
let outputFile = '';
let port = 3000;
const config = {
context: src,
output: {
path: path.resolve(dest, 'statics'),
publicPath: 'http://localhost:' + port + '/'
},
module: {
rules: [{
test: /\.js$/,
use: [
{loader: 'babel-loader'},
],
exclude: /node_modules/
}, {
test: /.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|ico|eot)$/,
use: "url-loader?limit=100000"
}]
},
resolve: {
alias: {
js: path.resolve(src, 'js'),
styles: path.resolve(src, 'styles')
},
extensions: ['.json', '.js', '.scss']
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin()
],
};
if(env === 'dev') {
config.devServer = {
hot: true,
port: port,
https: false,
contentBase: dest,
publicPath: 'http://localhost:' + port + '/',
headers: {
'access-control-allow-origin': '*'
}
};
config.entry = [
'babel-polyfill',
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:' + port + '/',
'webpack/hot/only-dev-server',
path.resolve(src, main)
];
config.devtool = 'cheap-module-eval-source-map';
config.module.rules.push({
test: /\.scss$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader" // compiles Sass to CSS
}]
});
outputFile = libraryName + '.js';
}
else if(env === 'test') {
config.context = test;
config.entry = glob.sync(path.resolve(test,'js/**/*test.js'));
config.externals = {
'react/lib/ExecutionEnvironment': true,
'react/addons': true,
'react/lib/ReactContext': true
};
config.output.path = path.resolve(dest, 'tests');
outputFile = libraryName + '.test.js';
}
else {
if(env === 'build') {
config.devtool = 'cheap-source-map';
config.output.sourceMapFilename = libraryName + '.map';
config.plugins.push(new UglifyJsPlugin({minimize: true, sourceMap: true}));
}
config.plugins.push(new ExtractTextPlugin(libraryName + '.css'));
config.module.rules.push({
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ['css-loader', 'sass-loader']
}),
exclude: /node_modules/
});
config.entry = [path.resolve(src, main)];
outputFile = libraryName + '.js';
}
config.output.filename = outputFile;
config.module.rules.push({ test: /\.js?$/, loader: 'eslint-loader', exclude: /node_modules/ });
module.exports = config;