webpack-2

google fonts + webpack

戏子无情 提交于 2019-11-27 19:31:55
I am new to webpack 2.2 ; I would like to know the best way to integrate a Google font within my project. I am using the Webpack HTML plugin to generate an index.html from a template. So for the moment I hard-coded the Google font CSS directly in a <script> tag but I do not really like this 'solution' since it does not really use webpack at all: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <link href="https://fonts.googleapis.com/css?family=Love+Ya+Like+A+Sister" rel="stylesheet"> <body> <div id='app'/> </body> </html> There is no need to use SASS. You will either need to use

Testing with Jest and Webpack aliases

China☆狼群 提交于 2019-11-27 15:30:50
问题 I am looking to be able to use webpack aliases to resolve imports when using jest, and optimally, reference the webpack.aliases to avoid duplication. Jest conf: "jest": { "modulePaths": ["src"], "moduleDirectories": ["node_modules"], "moduleNameMapper": { "^@shared$": "<rootDir>/shared/", "^@components$": "<rootDir>/shared/components/" } }, Webpack aliases: exports.aliases = { '@shared': path.resolve(paths.APP_DIR, 'shared'), '@components': path.resolve(paths.APP_DIR, 'shared/components'), };

How to pass .env file variables to webpack config?

会有一股神秘感。 提交于 2019-11-27 13:52:48
问题 I am new to webpack and worked out almost all build sections, but now the problem is that I want to pass the environment variables from a .env file to webpack config, so that I can pass that variables to my build files via webpack.DefinePlugin plugin. Currently I am able to to pass environment variable directly from webpack to to my build. Please see the code below which I used in webpack. new webpack.DefinePlugin({ "API_URL": JSON.stringify("http://my-api.com"), "SECRET_KEY" :

Field 'browser' doesn't contain a valid alias configuration

左心房为你撑大大i 提交于 2019-11-27 05:44:03
问题 I've started using webpack2 (to be precise, v2.3.2 ) and after re-creating my config I keep running into an issue I can't seem to solve I get (sorry in advance for ugly dump): ERROR in ./src/main.js Module not found: Error: Can't resolve 'components/DoISuportIt' in '[absolute path to my repo]/src' resolve 'components/DoISuportIt' in '[absolute path to my repo]/src' Parsed request is a module using description file: [absolute path to my repo]/package.json (relative path: ./src) Field 'browser'

webpack dynamic module loader by require

陌路散爱 提交于 2019-11-26 23:02:19
OK, i have searched high and low but cannot reliably deterrmine if this is or is not possible with webpack. https://github.com/webpack/webpack/tree/master/examples/require.context Appears to indicate that one can pass a string to a function and it load a module... But my attempt is just not working: webpack.config.js 'use strict'; let webpack = require('webpack'), jsonLoader = require("json-loader"), path = require("path"), fs = require('fs'), nodeModules = {}; fs.readdirSync('node_modules') .filter(function(x) { return ['.bin'].indexOf(x) === -1; }) .forEach(function(mod) { nodeModules[mod] =

webpack dynamic module loader by require

送分小仙女□ 提交于 2019-11-26 05:38:41
问题 OK, i have searched high and low but cannot reliably deterrmine if this is or is not possible with webpack. https://github.com/webpack/webpack/tree/master/examples/require.context Appears to indicate that one can pass a string to a function and it load a module... But my attempt is just not working: webpack.config.js \'use strict\'; let webpack = require(\'webpack\'), jsonLoader = require(\"json-loader\"), path = require(\"path\"), fs = require(\'fs\'), nodeModules = {}; fs.readdirSync(\'node

Define global variable with webpack

▼魔方 西西 提交于 2019-11-25 23:46:25
问题 Is it possible to define a global variable with webpack to result something like this: var myvar = {}; All of the examples I saw were using external file require(\"imports?$=jquery!./file.js\") 回答1: There are several way to approach globals: 1) Put your variables in a module. Webpack evaluates modules only once, so your instance remains global and carries changes through from module to module. So if you create something like a globals.js and export an object of all your globals then you can