Guest User

Untitled

a guest
May 25th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. var path = require('path');
  2. const sass = require("node-sass");
  3. const sassUtils = require("node-sass-utils")(sass);
  4. const sassVars = require(__dirname + "/src/styles/theme.js");
  5. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  6.  
  7. // Convert js strings to dimenssions
  8. const convertStringToSassDimension = function(result) {
  9. // Only attempt to convert strings
  10. if (typeof result !== "string") {
  11. return result;
  12. }
  13.  
  14. const cssUnits = [
  15. "rem",
  16. "em",
  17. "vh",
  18. "vw",
  19. "vmin",
  20. "vmax",
  21. "ex",
  22. "%",
  23. "px",
  24. "cm",
  25. "mm",
  26. "in",
  27. "pt",
  28. "pc",
  29. "ch"
  30. ];
  31. const parts = result.match(/[a-zA-Z]+|[0-9]+/g);
  32. const value = parts[0];
  33. const unit = parts[parts.length - 1];
  34. if (cssUnits.indexOf(unit) !== -1) {
  35. result = new sassUtils.SassDimension(parseInt(value, 10), unit);
  36. }
  37.  
  38. return result;
  39. };
  40.  
  41. const dist = path.resolve(__dirname, 'dist');
  42. const app = path.resolve(__dirname, 'src');
  43.  
  44. module.exports = {
  45. mode: 'production',
  46. entry: './src/index.js',
  47. output: {
  48. path: dist,
  49. filename: 'index.js',
  50. libraryTarget: 'commonjs2' // THIS IS THE MOST IMPORTANT LINE! :mindblow: I wasted more than 2 days until realize this was the line most important in all this guide.
  51. },
  52. module: {
  53. rules: [
  54. // Javascript file loading
  55. {
  56. test: /.js$/,
  57. include: app,
  58. exclude: /(node_modules|bower_components|dist)/,
  59. use: {
  60. loader: 'babel-loader',
  61. options: {
  62. presets: ['env']
  63. }
  64. }
  65. },
  66. {
  67. test: /.(scss|sass)$/,
  68. use: ExtractTextPlugin.extract({
  69. fallback: 'style-loader',
  70. use: [
  71. { loader: 'css-loader' },
  72. {
  73. loader: "sass-loader?sourceMap",
  74. options: {
  75. functions: {
  76. "get($keys)": function(keys) {
  77. keys = keys.getValue().split(".");
  78. var result = sassVars;
  79. var i;
  80. for (i = 0; i < keys.length; i++) {
  81. result = result[keys[i]];
  82. // Convert to SassDimension if dimenssion
  83. if (typeof result === "string") {
  84. result = convertStringToSassDimension(result);
  85. } else if (typeof result === "object") {
  86. Object.keys(result).forEach(function(key) {
  87. var value = result[key];
  88. result[key] = convertStringToSassDimension(value);
  89. });
  90. }
  91. }
  92. result = sassUtils.castToSass(result);
  93. return result;
  94. }
  95. }
  96. },
  97. },
  98. ],
  99. })
  100. },
  101. {
  102. test: /.(woff2?|eot|ttf|otf)(?.*)?$/,
  103. loader: 'url-loader',
  104. options: {
  105. limit: 10000,
  106. name: 'fonts/[name].[ext]'
  107. }
  108. }
  109. ]
  110. },
  111. plugins: [
  112. new ExtractTextPlugin({ filename: '[name].css' })
  113. ]
  114. };
  115.  
  116. import Header1 from './elements/Header1';
  117. import Header2 from './elements/Header2';
  118. import Header3 from './elements/Header3';
  119. import Toggle from './elements/Toggle';
  120.  
  121. module.exports = {
  122. Header1,
  123. Header2,
  124. Header3,
  125. Toggle,
  126. };
  127.  
  128. import styled from 'styled-components';
  129. import * as theme from '../styles/theme';
  130. import '../styles/variables.scss';
  131.  
  132. const Header1 = styled.h1`
  133. font-family: brownprott;
  134. font-weight: bold;
  135. font-size: 32px;
  136. color: ${theme.colors.teal};
  137. `;
  138.  
  139. export default Header1;
  140.  
  141. @import 'typography.scss';
  142.  
  143. $colors: get("colors");
  144.  
  145. $white: #FFFFFF;
  146. $teal: #00EBD0;
  147. $lightGrey: #DADCDD;
  148. $darkGrey: #222425;
  149. $red: #FF0000;
  150. $info: #1FB6FF;
  151. $success: #13CE66;
  152. $danger: #FF4949;
  153. $warning: #FFC82C;
  154.  
  155. $font_path: '~/assets/fonts/';
  156.  
  157. @font-face {
  158. font-family: "brownprott";
  159. src: url($font_path + "brownprott_light.ttf");
  160. font-weight: "lighter";
  161. }
  162.  
  163. @font-face {
  164. font-family: "brownprott";
  165. src: url($font_path + "brownprott_regular.ttf");
  166. font-weight: "normal";
  167. }
  168.  
  169. @font-face {
  170. font-family: "brownprott";
  171. src: url($font_path + "brownprott_italic.ttf");
  172. font-weight: "normal";
  173. font-style: "italic";
  174. }
  175.  
  176. @font-face {
  177. font-family: "brownprott";
  178. src: url($font_path + "brownprott_bold.ttf");
  179. font-weight: "bold";
  180. }
  181.  
  182. Webpack is watching the files…
  183.  
  184. Hash: 549baa5760d8010ca491
  185. Version: webpack 4.8.3
  186. Time: 1148ms
  187. Built at: 2018-05-25 11:29:58
  188. Asset Size Chunks Chunk Names
  189. index.js 55.7 KiB 0 [emitted] main
  190. main.css 504 bytes 0 [emitted] main
  191. Entrypoint main = index.js main.css
  192. [2] ./src/styles/theme.js 373 bytes {0} [built]
  193. [11] ./src/elements/Toggle.js 4.42 KiB {0} [built]
  194. [12] ./src/elements/Header3.js 1.17 KiB {0} [built]
  195. [13] ./src/elements/Header2.js 1.17 KiB {0} [built]
  196. [21] (webpack)/buildin/harmony-module.js 597 bytes {0} [built]
  197. [23] ./src/elements/Header1.js 1.16 KiB {0} [built]
  198. [24] ./src/index.js 630 bytes {0} [built]
  199. [28] ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js??ref--5-3!./src/styles/variables.scss 712 bytes [built]
  200. [29] ./src/styles/variables.scss 41 bytes [built]
  201. + 21 hidden modules
  202. Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js!node_modules/sass-loader/lib/loader.js??ref--5-3!src/styles/variables.scss:
  203. Entrypoint undefined = extract-text-webpack-plugin-output-filename
  204. [1] ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js??ref--5-3!./src/styles/variables.scss 712 bytes {0} [built]
  205. + 1 hidden module
Add Comment
Please, Sign In to add comment