forked from OpenChargingCloud/ChargyMobileApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
165 lines (146 loc) · 5.59 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
var path = require("path"),
fs = require("fs"),
webpack = require("webpack"),
ExtractTextPlugin = require("extract-text-webpack-plugin"),
CopyWebpackPlugin = require("copy-webpack-plugin"),
HtmlWebpackPlugin = require("html-webpack-plugin");
var BUNDLE_NAME = "bundle",
DEVTOOL = "inline-source-map",
CONTEXT = __dirname,
SOURCE_WWW = path.resolve(CONTEXT, "www.src"),
SOURCE_TYPESCRIPT = path.resolve(SOURCE_WWW, "ts"),
SOURCE_JAVASCRIPT = path.resolve(SOURCE_WWW, "es"),
SOURCE_NAME = "index",
SOURCE_SCSS = path.resolve(SOURCE_WWW, "scss"),
SOURCE_SCSS_NAME = "styles.scss",
SOURCE_CSS = path.resolve(SOURCE_WWW, "css"),
SOURCE_CSS_NAME = "styles.css",
TARGET_CSS = "css",
TARGET_JAVASCRIPT = "js",
TARGET_WWW = path.resolve(CONTEXT, "www"),
VENDOR_NAME = "vendor";
var usingTypeScript = fs.existsSync(SOURCE_TYPESCRIPT),
usingScss = fs.existsSync(SOURCE_SCSS);
var SOURCE_ENTRY = path.join(path.basename(usingTypeScript ? SOURCE_TYPESCRIPT : SOURCE_JAVASCRIPT), SOURCE_NAME + (usingTypeScript ? ".ts" : ".js")),
SOURCE_STYLE = path.join(path.basename(usingScss ? SOURCE_SCSS : SOURCE_CSS), usingScss ? SOURCE_SCSS_NAME : SOURCE_CSS_NAME),
TARGET_JS_FILE = path.join(TARGET_JAVASCRIPT, BUNDLE_NAME + ".js"),
TARGET_JS_VENDOR = path.join(TARGET_JAVASCRIPT, VENDOR_NAME + ".js"),
TARGET_CSS_FILE = path.join(TARGET_CSS, BUNDLE_NAME + ".css"),
TARGET_CSS_VENDOR = path.join(TARGET_CSS, VENDOR_NAME + ".css");
var extractStylesPlugin = new ExtractTextPlugin(TARGET_CSS_FILE),
extractStylesVendorPlugin = new ExtractTextPlugin(TARGET_CSS_VENDOR);
var vendor = ["core-js"];
var webpackConfig = {
context: SOURCE_WWW,
devtool: DEVTOOL,
entry: {
app: [
"./" + SOURCE_ENTRY,
"./" + SOURCE_STYLE,
/* any other entry files */
]
},
output: {
filename: TARGET_JS_FILE,
path: TARGET_WWW
},
resolve: {
extensions: [
".js", ".ts", ".jsx", ".es",// typical JS extensions
".jsm", ".esm", // jsm is node's ES6 module ext
".json", // some modules require json without an extension
".css", ".scss", // CSS & SASS extensions
"*" // allow extensions on imports
],
modules: [
path.resolve(SOURCE_TYPESCRIPT, "lib"),
path.resolve(SOURCE_TYPESCRIPT, "vendor"),
path.resolve(SOURCE_JAVASCRIPT, "lib"),
path.resolve(SOURCE_JAVASCRIPT, "vendor"),
path.resolve(SOURCE_WWW, "lib"),
path.resolve(SOURCE_WWW, "vendor"),
"node_modules"
],
alias: {
"$LIB": "lib",
"Lib": "lib",
"$VENDOR": "vendor",
"Vendor": "vendor",
/* any more aliases you need */
},
},
module: {
rules: [
// HTML & TEXT files should just be loaded as raw (included in bundle)
{ test: /\.(html|txt)$/, use: "raw-loader" },
// Images and web fonts should be copied & file path returned
{
test: /\.(png|jpe?g|svg|gif|eot|ttf|woff|woff2)$/,
use: ["file-loader?name=[path][name].[ext]&emitFile=true"]
},
// JSON/JSON5 should use the JSON5 loader and be included in bundle
{ test: /\.(json|json5)$/, use: "json5-loader" },
// Extract our app's CSS into the bundle
{
test: /\.s?css$/,
exclude: /node_modules\/.*\.css$/,
use: extractStylesPlugin.extract({
fallback: "style-loader",
publicPath: "../",
use: [
{ loader: "css-loader?sourceMap=true" },
{ loader: "resolve-url-loader?sourceMap=true" },
{ loader: "sass-loader?sourceMap=true" },
]
})
},
// css files in node_modules are put into a vendor bundle
{
test: /node_modules\/.*\.css$/,
use: extractStylesVendorPlugin.extract({
fallback: "style-loader",
publicPath: "../",
use: [
{ loader: "css-loader?sourceMap=true" },
{ loader: "resolve-url-loader?sourceMap=true" },
]
})
},
// JavaScript / TypeScript code
{
test: /\.((j|t)sx?)$/,
use: ["ts-loader" + (usingTypeScript ? "" : "?entryFileIsJs")],
exclude: /node_modules/
},
]
},
plugins: [
new CopyWebpackPlugin([
{ from: "*.*" },
{ from: "img/**/*" },
{ from: "css/**/*" },
{ from: "js/**/*" },
{ from: "vendor/**/*" },
{ from: "lib/**/*" },
{ from: "html/**/*" },
{ from: "webfonts/**/*" },
/* any other files you need to copy */
]),
extractStylesPlugin,
extractStylesVendorPlugin,
new HtmlWebpackPlugin({
filename: "index.html",
template: "index.html",
inject: true,
chunksSortMode: "dependency"
}),
]
};
if (vendor.length > 0) {
webpackConfig.entry.vendor = vendor;
webpackConfig.plugins.push(new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
filename: TARGET_JS_VENDOR
}));
}
module.exports = webpackConfig;