Guest User

Untitled

a guest
Nov 24th, 2017
10
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const path = require('path');
  3. const CopyWebpackPlugin = require('copy-webpack-plugin');
  4. const ProgressPlugin = require('webpack/lib/ProgressPlugin');
  5. const CircularDependencyPlugin = require('circular-dependency-plugin');
  6. const HtmlWebpackPlugin = require('html-webpack-plugin');
  7. const autoprefixer = require('autoprefixer');
  8. const postcssUrl = require('postcss-url');
  9. const cssnano = require('cssnano');
  10.  
  11. const { NoEmitOnErrorsPlugin, SourceMapDevToolPlugin, NamedModulesPlugin } = require('webpack');
  12. const { NamedLazyChunksWebpackPlugin, BaseHrefWebpackPlugin } = require('@angular/cli/plugins/webpack');
  13. const { CommonsChunkPlugin } = require('webpack').optimize;
  14. const { AotPlugin } = require('@ngtools/webpack');
  15.  
  16. const nodeModules = path.join(process.cwd(), 'node_modules');
  17. const realNodeModules = fs.realpathSync(nodeModules);
  18. const genDirNodeModules = path.join(process.cwd(), 'src', '$$_gendir', 'node_modules');
  19. const entryPoints = ["inline","polyfills","sw-register","styles","vendor","main"];
  20. const minimizeCss = false;
  21. const baseHref = "";
  22. const deployUrl = "";
  23. const postcssPlugins = function () {
  24. // safe settings based on: https://github.com/ben-eb/cssnano/issues/358#issuecomment-283696193
  25. const importantCommentRe = /@preserve|@license|[@#]\s*source(?:Mapping)?URL|^!/i;
  26. const minimizeOptions = {
  27. autoprefixer: false,
  28. safe: true,
  29. mergeLonghand: false,
  30. discardComments: { remove: (comment) => !importantCommentRe.test(comment) }
  31. };
  32. return [
  33. postcssUrl({
  34. url: (URL) => {
  35. // Only convert root relative URLs, which CSS-Loader won't process into require().
  36. if (!URL.startsWith('/') || URL.startsWith('//')) {
  37. return URL;
  38. }
  39. if (deployUrl.match(/:\/\//)) {
  40. // If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
  41. return `${deployUrl.replace(/\/$/, '')}${URL}`;
  42. }
  43. else if (baseHref.match(/:\/\//)) {
  44. // If baseHref contains a scheme, include it as is.
  45. return baseHref.replace(/\/$/, '') +
  46. `/${deployUrl}/${URL}`.replace(/\/\/+/g, '/');
  47. }
  48. else {
  49. // Join together base-href, deploy-url and the original URL.
  50. // Also dedupe multiple slashes into single ones.
  51. return `/${baseHref}/${deployUrl}/${URL}`.replace(/\/\/+/g, '/');
  52. }
  53. }
  54. }),
  55. autoprefixer(),
  56. ].concat(minimizeCss ? [cssnano(minimizeOptions)] : []);
  57. };
  58.  
  59.  
  60.  
  61.  
  62. module.exports = {
  63. "resolve": {
  64. "extensions": [
  65. ".ts",
  66. ".js"
  67. ],
  68. "modules": [
  69. "./node_modules",
  70. "./node_modules"
  71. ],
  72. "symlinks": true
  73. },
  74. "resolveLoader": {
  75. "modules": [
  76. "./node_modules",
  77. "./node_modules"
  78. ]
  79. },
  80. "entry": {
  81. "main": [
  82. "./src/main.ts"
  83. ],
  84. "polyfills": [
  85. "./src/polyfills.ts"
  86. ],
  87. "styles": [
  88. "./src/styles.css"
  89. ]
  90. },
  91. "output": {
  92. "path": path.join(process.cwd(), "dist"),
  93. "filename": "[name].bundle.js",
  94. "chunkFilename": "[id].chunk.js"
  95. },
  96. "module": {
  97. "rules": [
  98. {
  99. "enforce": "pre",
  100. "test": /\.js$/,
  101. "loader": "source-map-loader",
  102. "exclude": [
  103. /(\\|\/)node_modules(\\|\/)/
  104. ]
  105. },
  106. {
  107. "test": /\.html$/,
  108. "loader": "raw-loader"
  109. },
  110. {
  111. "test": /\.(eot|svg|cur)$/,
  112. "loader": "file-loader",
  113. "options": {
  114. "name": "[name].[hash:20].[ext]",
  115. "limit": 10000
  116. }
  117. },
  118. {
  119. "test": /\.(jpg|png|webp|gif|otf|ttf|woff|woff2|ani)$/,
  120. "loader": "url-loader",
  121. "options": {
  122. "name": "[name].[hash:20]",
  123. "limit": 10000
  124. }
  125. },
  126. {
  127. "exclude": [
  128. path.join(process.cwd(), "src/styles.css")
  129. ],
  130. "test": /\.css$/,
  131. "use": [
  132. "exports-loader?module.exports.toString()",
  133. {
  134. "loader": "css-loader",
  135. "options": {
  136. "sourceMap": false,
  137. "importLoaders": 1
  138. }
  139. },
  140. {
  141. "loader": "postcss-loader",
  142. "options": {
  143. "ident": "postcss",
  144. "plugins": postcssPlugins
  145. }
  146. }
  147. ]
  148. },
  149. {
  150. "exclude": [
  151. path.join(process.cwd(), "src/styles.css")
  152. ],
  153. "test": /\.scss$|\.sass$/,
  154. "use": [
  155. "exports-loader?module.exports.toString()",
  156. {
  157. "loader": "css-loader",
  158. "options": {
  159. "sourceMap": false,
  160. "importLoaders": 1
  161. }
  162. },
  163. {
  164. "loader": "postcss-loader",
  165. "options": {
  166. "ident": "postcss",
  167. "plugins": postcssPlugins
  168. }
  169. },
  170. {
  171. "loader": "sass-loader",
  172. "options": {
  173. "sourceMap": false,
  174. "precision": 8,
  175. "includePaths": []
  176. }
  177. }
  178. ]
  179. },
  180. {
  181. "exclude": [
  182. path.join(process.cwd(), "src/styles.css")
  183. ],
  184. "test": /\.less$/,
  185. "use": [
  186. "exports-loader?module.exports.toString()",
  187. {
  188. "loader": "css-loader",
  189. "options": {
  190. "sourceMap": false,
  191. "importLoaders": 1
  192. }
  193. },
  194. {
  195. "loader": "postcss-loader",
  196. "options": {
  197. "ident": "postcss",
  198. "plugins": postcssPlugins
  199. }
  200. },
  201. {
  202. "loader": "less-loader",
  203. "options": {
  204. "sourceMap": false
  205. }
  206. }
  207. ]
  208. },
  209. {
  210. "exclude": [
  211. path.join(process.cwd(), "src/styles.css")
  212. ],
  213. "test": /\.styl$/,
  214. "use": [
  215. "exports-loader?module.exports.toString()",
  216. {
  217. "loader": "css-loader",
  218. "options": {
  219. "sourceMap": false,
  220. "importLoaders": 1
  221. }
  222. },
  223. {
  224. "loader": "postcss-loader",
  225. "options": {
  226. "ident": "postcss",
  227. "plugins": postcssPlugins
  228. }
  229. },
  230. {
  231. "loader": "stylus-loader",
  232. "options": {
  233. "sourceMap": false,
  234. "paths": []
  235. }
  236. }
  237. ]
  238. },
  239. {
  240. "include": [
  241. path.join(process.cwd(), "src/styles.css")
  242. ],
  243. "test": /\.css$/,
  244. "use": [
  245. "style-loader",
  246. {
  247. "loader": "css-loader",
  248. "options": {
  249. "sourceMap": false,
  250. "importLoaders": 1
  251. }
  252. },
  253. {
  254. "loader": "postcss-loader",
  255. "options": {
  256. "ident": "postcss",
  257. "plugins": postcssPlugins
  258. }
  259. }
  260. ]
  261. },
  262. {
  263. "include": [
  264. path.join(process.cwd(), "src/styles.css")
  265. ],
  266. "test": /\.scss$|\.sass$/,
  267. "use": [
  268. "style-loader",
  269. {
  270. "loader": "css-loader",
  271. "options": {
  272. "sourceMap": false,
  273. "importLoaders": 1
  274. }
  275. },
  276. {
  277. "loader": "postcss-loader",
  278. "options": {
  279. "ident": "postcss",
  280. "plugins": postcssPlugins
  281. }
  282. },
  283. {
  284. "loader": "sass-loader",
  285. "options": {
  286. "sourceMap": false,
  287. "precision": 8,
  288. "includePaths": []
  289. }
  290. }
  291. ]
  292. },
  293. {
  294. "include": [
  295. path.join(process.cwd(), "src/styles.css")
  296. ],
  297. "test": /\.less$/,
  298. "use": [
  299. "style-loader",
  300. {
  301. "loader": "css-loader",
  302. "options": {
  303. "sourceMap": false,
  304. "importLoaders": 1
  305. }
  306. },
  307. {
  308. "loader": "postcss-loader",
  309. "options": {
  310. "ident": "postcss",
  311. "plugins": postcssPlugins
  312. }
  313. },
  314. {
  315. "loader": "less-loader",
  316. "options": {
  317. "sourceMap": false
  318. }
  319. }
  320. ]
  321. },
  322. {
  323. "include": [
  324. path.join(process.cwd(), "src/styles.css")
  325. ],
  326. "test": /\.styl$/,
  327. "use": [
  328. "style-loader",
  329. {
  330. "loader": "css-loader",
  331. "options": {
  332. "sourceMap": false,
  333. "importLoaders": 1
  334. }
  335. },
  336. {
  337. "loader": "postcss-loader",
  338. "options": {
  339. "ident": "postcss",
  340. "plugins": postcssPlugins
  341. }
  342. },
  343. {
  344. "loader": "stylus-loader",
  345. "options": {
  346. "sourceMap": false,
  347. "paths": []
  348. }
  349. }
  350. ]
  351. },
  352. {
  353. "test": /\.ts$/,
  354. "loader": "@ngtools/webpack"
  355. }
  356. ]
  357. },
  358. "plugins": [
  359. new NoEmitOnErrorsPlugin(),
  360. new CopyWebpackPlugin([
  361. {
  362. "context": "src",
  363. "to": "",
  364. "from": {
  365. "glob": "assets/**/*",
  366. "dot": true
  367. }
  368. },
  369. {
  370. "context": "src",
  371. "to": "",
  372. "from": {
  373. "glob": "favicon.ico",
  374. "dot": true
  375. }
  376. }
  377. ], {
  378. "ignore": [
  379. ".gitkeep"
  380. ],
  381. "debug": "warning"
  382. }),
  383. new ProgressPlugin(),
  384. new CircularDependencyPlugin({
  385. "exclude": /(\\|\/)node_modules(\\|\/)/,
  386. "failOnError": false
  387. }),
  388. new NamedLazyChunksWebpackPlugin(),
  389. new HtmlWebpackPlugin({
  390. "template": "./src/index.html",
  391. "filename": "./index.html",
  392. "hash": false,
  393. "inject": true,
  394. "compile": true,
  395. "favicon": false,
  396. "minify": false,
  397. "cache": true,
  398. "showErrors": true,
  399. "chunks": "all",
  400. "excludeChunks": [],
  401. "title": "Webpack App",
  402. "xhtml": true,
  403. "chunksSortMode": function sort(left, right) {
  404. let leftIndex = entryPoints.indexOf(left.names[0]);
  405. let rightindex = entryPoints.indexOf(right.names[0]);
  406. if (leftIndex > rightindex) {
  407. return 1;
  408. }
  409. else if (leftIndex < rightindex) {
  410. return -1;
  411. }
  412. else {
  413. return 0;
  414. }
  415. }
  416. }),
  417. new BaseHrefWebpackPlugin({}),
  418. new CommonsChunkPlugin({
  419. "name": [
  420. "inline"
  421. ],
  422. "minChunks": null
  423. }),
  424. new CommonsChunkPlugin({
  425. "name": [
  426. "vendor"
  427. ],
  428. "minChunks": (module) => {
  429. return module.resource
  430. && (module.resource.startsWith(nodeModules)
  431. || module.resource.startsWith(genDirNodeModules)
  432. || module.resource.startsWith(realNodeModules));
  433. },
  434. "chunks": [
  435. "main"
  436. ]
  437. }),
  438. new SourceMapDevToolPlugin({
  439. "filename": "[file].map[query]",
  440. "moduleFilenameTemplate": "[resource-path]",
  441. "fallbackModuleFilenameTemplate": "[resource-path]?[hash]",
  442. "sourceRoot": "webpack:///"
  443. }),
  444. new CommonsChunkPlugin({
  445. "name": [
  446. "main"
  447. ],
  448. "minChunks": 2,
  449. "async": "common"
  450. }),
  451. new NamedModulesPlugin({}),
  452. new AotPlugin({
  453. "mainPath": "main.ts",
  454. "replaceExport": false,
  455. "hostReplacementPaths": {
  456. "environments/environment.ts": "environments/environment.ts"
  457. },
  458. "exclude": [],
  459. "tsConfigPath": "src/tsconfig.app.json",
  460. "skipCodeGeneration": true
  461. })
  462. ],
  463. "node": {
  464. "fs": "empty",
  465. "global": true,
  466. "crypto": "empty",
  467. "tls": "empty",
  468. "net": "empty",
  469. "process": true,
  470. "module": false,
  471. "clearImmediate": false,
  472. "setImmediate": false
  473. },
  474. "devServer": {
  475. "historyApiFallback": true
  476. }
  477. };
RAW Paste Data