blob: fc2f5a4387ea68c6c6a72bd28a074cae74f7cdc2 [file] [log] [blame]
Michael Landoed64b5e2017-06-09 03:19:04 +03001const path = require('path');
2const webpack = require('webpack');
3const ProgressPlugin = require('webpack/lib/ProgressPlugin');
4const HtmlWebpackPlugin = require('html-webpack-plugin');
5const ExtractTextPlugin = require('extract-text-webpack-plugin');
6const CleanWebpackPlugin = require('clean-webpack-plugin');
7const autoprefixer = require('autoprefixer');
8const postcssUrl = require('postcss-url');
9const {GlobCopyWebpackPlugin, BaseHrefWebpackPlugin} = require('@angular/cli/plugins/webpack');
10const {CommonsChunkPlugin} = require('webpack').optimize;
11const {AotPlugin} = require('@ngtools/webpack');
12
13const nodeModules = path.join(process.cwd(), 'node_modules');
14
15const bundledScripts = [
16 "script-loader!./node_modules/jquery/dist/jquery.min.js",
17 "script-loader!./node_modules/lodash/lodash.min.js",
18 "script-loader!./node_modules/angular/angular.min.js",
19 "script-loader!./node_modules/restangular/dist/restangular.min.js",
20 "script-loader!./node_modules/jqueryui/jquery-ui.min.js",
21 "script-loader!./node_modules/angular-ui-router/release/angular-ui-router.min.js",
22 "script-loader!./node_modules/angular-filter/dist/angular-filter.min.js",
23 "script-loader!./node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js",
24 "script-loader!./node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js",
25 "script-loader!./node_modules/angular-resource/angular-resource.min.js",
26 "script-loader!./node_modules/angular-base64/angular-base64.min.js",
27 "script-loader!./node_modules/angular-uuid4/angular-uuid4.min.js",
28 "script-loader!./node_modules/angular-translate/dist/angular-translate.min.js",
29 "script-loader!./node_modules/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js",
30 "script-loader!./node_modules/angular-base64-upload/dist/angular-base64-upload.min.js",
31 "script-loader!./node_modules/angular-ui-notification/dist/angular-ui-notification.min.js",
32 "script-loader!./node_modules/cytoscape/dist/cytoscape.min.js",
33 "script-loader!./node_modules/checklist-model/checklist-model.js",
34 "script-loader!./node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.jquery.min.js",
35 "script-loader!./node_modules/qtip2/dist/jquery.qtip.min.js",
Michael Lando4d97d5f2017-06-17 22:40:44 +030036 "script-loader!./node_modules/@bardit/cytoscape-qtip/cytoscape-qtip.js",
Michael Landoed64b5e2017-06-09 03:19:04 +030037 "script-loader!./node_modules/js-md5/build/md5.min.js",
38 "script-loader!./node_modules/angular-clipboard/angular-clipboard.js",
39 "script-loader!./node_modules/angular-resizable/angular-resizable.min.js",
Michael Lando4d97d5f2017-06-17 22:40:44 +030040 "script-loader!./node_modules/sdc-angular-dragdrop/src/angular-dragdrop.min.js",
Michael Landoed64b5e2017-06-09 03:19:04 +030041 "script-loader!./node_modules/angular-tooltips/dist/angular-tooltips.min.js",
42 "script-loader!./node_modules/angular-sanitize/angular-sanitize.min.js"
43];
44const baseHref = undefined;
45const deployUrl = undefined;
46
47// Arguments pass from webpack
48const prod = process.argv.indexOf('-p') !== -1;
49
50module.exports = function(params) {
51
52 const webpackCommonConfig = {
53 resolve: {
54 extensions: [
55 ".ts",
56 ".js",
57 ".less"
58 ],
59 modules: [
60 "./node_modules"
61 ],
62 alias: {
63 directives: path.join(__dirname, 'app/directives/'),
64 }
65 },
66 resolveLoader: {
67 modules: [
68 "./node_modules"
69 ]
70 },
71 entry: {
72 'scripts/main': [ './src/main.ts' ],
73 'scripts/polyfills': [ './src/polyfills.ts' ],
74 'scripts/vendor': bundledScripts,
75 'scripts/styles': [ "./src/styles.less" ]
76 },
77 module: {
78 rules: [
79 {
80 enforce: "pre",
81 test: /\.js$/,
82 loader: "source-map-loader",
83 exclude: [ /\/node_modules\// ]
84 },
85 { test: /\.json$/, loader: "json-loader" },
86 { test: /\.html$/, loader: "html-loader" },
87 {
88 exclude: [ path.join(process.cwd(), "src/styles.less") ],
89 test: /\.css$/,
90 loaders: [
91 "exports-loader?module.exports.toString()",
92 "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
93 "postcss-loader"
94 ]
95 },
96 {
97 exclude: [ path.join(process.cwd(), "src/styles.less") ],
98 test: /\.scss$|\.sass$/,
99 loaders: [
100 "exports-loader?module.exports.toString()",
101 "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
102 "postcss-loader",
103 "sass-loader"
104 ]
105 },
106 {
107 exclude: [ path.join(process.cwd(), "src/styles.less") ],
108 test: /\.less$/,
109 loaders: [
110 "exports-loader?module.exports.toString()",
111 "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
112 "postcss-loader",
113 "less-loader"
114 ]
115 },
116 {
117 exclude: [ path.join(process.cwd(), "src/styles.less") ],
118 test: /\.styl$/,
119 loaders: [
120 "exports-loader?module.exports.toString()",
121 "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
122 "postcss-loader",
123 "stylus-loader?{\"sourceMap\":false,\"paths\":[]}"
124 ]
125 },
126 {
127 include: [ path.join(process.cwd(), "src/styles.less") ],
128 test: /\.css$/,
129 loaders: ExtractTextPlugin.extract({
130 use: [
131 "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
132 "postcss-loader"
133 ],
134 fallback: "style-loader",
135 publicPath: ""
136 })
137 },
138 {
139 include: [ path.join(process.cwd(), "src/styles.less") ],
140 test: /\.scss$|\.sass$/,
141 loaders: ExtractTextPlugin.extract({
142 use: [
143 "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
144 "postcss-loader",
145 "sass-loader"
146 ],
147 fallback: "style-loader",
148 publicPath: ""
149 })
150 },
151 {
152 include: [ path.join(process.cwd(), "src/styles.less") ],
153 test: /\.less$/,
154 loaders: ExtractTextPlugin.extract({
155 use: [
156 "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
157 "postcss-loader",
158 "less-loader"
159 ],
160 fallback: "style-loader",
161 publicPath: ""
162 })
163 },
164 {
165 include: [ path.join(process.cwd(), "src/styles.less") ],
166 test: /\.styl$/,
167 loaders: ExtractTextPlugin.extract({
168 use: [
169 "css-loader?{\"sourceMap\":false,\"importLoaders\":1}",
170 "postcss-loader",
171 "stylus-loader?{\"sourceMap\":false,\"paths\":[]}"
172 ],
173 fallback: "style-loader",
174 publicPath: ""
175 })
176 },
177 { test: /\.ts$/, loader: "@ngtools/webpack" }
178 ]
179 },
180 plugins: [
181 new CleanWebpackPlugin(['dist', 'build'], {
182 root: path.join(__dirname, ''),
183 verbose: true,
184 dry: false,
185 exclude: ['shared.js']
186 }),
187 new webpack.LoaderOptionsPlugin({
188 debug: false
189 }),
190 new webpack.DefinePlugin({
191 process: {
192 env: {
193 sdcConfig: prod? '"production"': '"development"'
194 }
195 }
196 }),
197 new webpack.NoEmitOnErrorsPlugin(),
198 new ProgressPlugin(),
199 // new HtmlWebpackPlugin({
200 // template: "./src/index.html",
201 // filename: "./index.html",
202 // hash: false,
203 // inject: true,
204 // compile: true,
205 // favicon: false,
206 // minify: false,
207 // cache: true,
208 // showErrors: true,
209 // chunks: "all",
210 // excludeChunks: [],
211 // title: "Webpack App",
212 // xhtml: true,
213 // chunksSortMode: function sort(left, right) {
214 // let paramsString = params.entryPoints + '';
215 // let leftString = left.names[0].replace('scripts/','');
216 // let rightString = right.names[0].replace('scripts/','');
217 // let leftIndex = paramsString.indexOf(leftString);
218 // let rightindex = paramsString.indexOf(rightString);
219 // //console.log("left: " + leftString + " | leftIndex: " + leftIndex);
220 // //console.log("right: " + rightString + " | rightindex: " + rightindex);
221 // //console.log("result: " + leftIndex-rightindex);
222 // //console.log("----------------------------------------");
223 // return leftIndex-rightindex;
224 // }
225 // }),
226 new GlobCopyWebpackPlugin({
227 patterns: [
228 "assets/languages",
229 "assets/styles/fonts",
230 "assets/styles/images",
231 "assets/styles/app.css"
232 ],
233 globOptions: {
234 cwd: path.join(process.cwd(), "src"),
235 dot: true,
236 ignore: "**/.gitkeep"
237 }
238 }),
239 new GlobCopyWebpackPlugin({
240 patterns: [
241 "configurations"
242 ],
243 globOptions: {
244 cwd: path.join(process.cwd(), ""),
245 dot: true,
246 ignore: "**/.gitkeep"
247 }
248 }),
249 new BaseHrefWebpackPlugin({}),
250 new CommonsChunkPlugin({
251 name: "scripts/inline",
252 minChunks: null
253 }),
254 new CommonsChunkPlugin({
255 name: "scripts/vendor",
256 minChunks: (module) => module.resource && module.resource.startsWith(nodeModules),
257 chunks: [
258 "main"
259 ]
260 }),
261 new ExtractTextPlugin({
262 filename: "[name].bundle.css",
263 disable: true
264 }),
265 new webpack.LoaderOptionsPlugin({
266 sourceMap: false,
267 options: {
268 postcss: [
269 autoprefixer(),
270 postcssUrl({
271 url: (URL) => {
272 // Only convert absolute URLs, which CSS-Loader won't process into require().
273 if (!URL.startsWith('/')) {
274 return URL;
275 }
276 // Join together base-href, deploy-url and the original URL.
277 // Also dedupe multiple slashes into single ones.
278 return `/${baseHref || ''}/${deployUrl || ''}/${URL}`.replace(/\/\/+/g, '/');
279 }
280 })
281 ],
282 sassLoader: {
283 sourceMap: false,
284 includePaths: []
285 },
286 lessLoader: {
287 sourceMap: false
288 },
289 context: ""
290 }
291 }),
292 new AotPlugin({
293 mainPath: "main.ts",
294 exclude: [],
295 tsConfigPath: "src/tsconfig.json",
296 skipCodeGeneration: true
297 })
298 ],
299 node: {
300 fs: "empty",
301 global: true,
302 crypto: "empty",
303 tls: "empty",
304 net: "empty",
305 process: true,
306 module: false,
307 clearImmediate: false,
308 setImmediate: false
309 }
310 }
311
312 return webpackCommonConfig;
313}