forked from mozilla/thimble.mozilla.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
165 lines (145 loc) · 3.92 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
"use strict";
const webpack = require("webpack");
const path = require("path");
const ProgressBarPlugin = require("progress-bar-webpack-plugin");
const WebpackOnBuildPlugin = require("on-build-webpack");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const autoprefixer = require("autoprefixer");
const colors = require("colors");
const env = require("./server/lib/environment");
const IS_DEVELOPMENT = env.get("NODE_ENV") === "development";
const moduleConfig = {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
}, {
test: /\.less$/,
use: ExtractTextPlugin.extract({
use: [{
loader: "css-loader",
options: {
minimize: !IS_DEVELOPMENT
}
}, {
loader: "postcss-loader",
options: {
plugins: [ autoprefixer() ]
}
}, {
loader: "less-loader"
}]
})
}, {
test: /\.svg$/,
loader: "svg-url-loader"
}]
};
const plugins = [
new ExtractTextPlugin("stylesheets/style.css")
];
if(!IS_DEVELOPMENT) {
plugins.push(
new webpack.optimize.UglifyJsPlugin()
);
} else {
plugins.push(
new WebpackOnBuildPlugin(stats => {
if(stats.compilation.outputOptions.path === path.resolve(__dirname, "dist/editor")) {
process.nextTick(() => {
console.log(colors.cyan(`Client files have been built. You can now load Thimble at ${env.get("APP_HOSTNAME")}`));
});
}
})
)
}
plugins.push(new ProgressBarPlugin({
clear: false
}));
function absolutePublicPath(filePath) {
return path.resolve(__dirname, "public", filePath);
}
const HOMEPAGE_CONFIG = {
entry: [
"homepage/scripts/main.js",
"homepage/stylesheets/style.less",
"homepage/stylesheets/get-involved.less",
"homepage/stylesheets/gallery.less",
"homepage/stylesheets/features.less"
]
.map(absolutePublicPath),
output: {
path: path.resolve(__dirname, "dist/homepage"),
pathinfo: IS_DEVELOPMENT,
filename: "scripts/main.js"
}
};
const PROJECTS_LIST_CONFIG = {
entry: [
"projects-list/scripts/main.js",
"projects-list/stylesheets/style.less"
]
.map(absolutePublicPath),
output: {
path: path.resolve(__dirname, "dist/projects-list"),
pathinfo: IS_DEVELOPMENT,
filename: "scripts/main.js"
}
};
const EDITOR_CONFIG = {
entry: [
"editor/scripts/main",
"editor/stylesheets/editor.less",
"editor/stylesheets/publish.less"
]
.map(absolutePublicPath),
output: {
path: path.resolve(__dirname, "dist/editor"),
pathinfo: IS_DEVELOPMENT,
filename: "scripts/main.js"
}
};
const RESOURCES_JS_CONFIG = {
entry: {
"bitjs-untar-worker.min": absolutePublicPath("resources/scripts/bitjs-untar-worker.min.js"),
"error": absolutePublicPath("resources/scripts/error.js"),
"google-analytics": absolutePublicPath("resources/scripts/google-analytics.js")
},
output: {
path: path.resolve(__dirname, "dist/resources"),
pathinfo: IS_DEVELOPMENT,
filename: "scripts/[name].js"
}
};
const RESOURCES_CSS_CONFIG = {
entry: {
"error": absolutePublicPath("resources/stylesheets/error.less"),
"normalize": absolutePublicPath("resources/stylesheets/normalize.less"),
"userbar": absolutePublicPath("resources/stylesheets/userbar.less"),
"glitch": absolutePublicPath("resources/stylesheets/glitch.less"),
"remix": absolutePublicPath("resources/remix/style.less")
},
output: {
path: path.resolve(__dirname, "dist/resources"),
filename: "stylesheets/[name].css"
},
plugins: [
new ExtractTextPlugin("stylesheets/[name].css"),
...plugins.slice(1)
]
};
module.exports = [
HOMEPAGE_CONFIG,
PROJECTS_LIST_CONFIG,
EDITOR_CONFIG,
RESOURCES_JS_CONFIG,
RESOURCES_CSS_CONFIG
].map(config => Object.assign({
module: moduleConfig,
plugins,
externals: {
strings: "__THIMBLE_STRINGS__"
},
watch: IS_DEVELOPMENT,
stats: IS_DEVELOPMENT ? "errors-only" : "normal"
}, config));