Webpack

Material UI / Webpack / React - the className optimization/minification in production mode

我与影子孤独终老i 提交于 2021-02-09 07:23:28
问题 webpack - v4+ material ui - v4.9.6 react - v16.12.0 In a normal way all classes should be as the last one from the first example. In some reason on production mode, many of the classes do not change. Any idea? Example 1: <div class="MuiDrawer-root MuiDrawer-docked jss408"></div> Example 2: <div class="MuiPaper-root jss469 MuiPaper-elevation1 MuiPaper-rounded"></div> 回答1: styles className is not designed as deterministic in prod mode. But the generated class names of the @material-ui/core

Best way to have absolute imports with Webpack 2?

吃可爱长大的小学妹 提交于 2021-02-09 07:12:07
问题 I'm in the process of setting up a Webpack configuration for a React project and I want to be able to import my components like this: import ComponentName from "components/ComponentName" instead of like this: import ComponentName from "../../components/ComponentName" (this all would be assuming that my components directory lives inside a src directory) Doing a little bit of research, so far I've found two different methods to achieve this using Webpack: Making Webpack resolve modules inside

Best way to have absolute imports with Webpack 2?

天涯浪子 提交于 2021-02-09 07:07:26
问题 I'm in the process of setting up a Webpack configuration for a React project and I want to be able to import my components like this: import ComponentName from "components/ComponentName" instead of like this: import ComponentName from "../../components/ComponentName" (this all would be assuming that my components directory lives inside a src directory) Doing a little bit of research, so far I've found two different methods to achieve this using Webpack: Making Webpack resolve modules inside

Best way to have absolute imports with Webpack 2?

风格不统一 提交于 2021-02-09 07:05:21
问题 I'm in the process of setting up a Webpack configuration for a React project and I want to be able to import my components like this: import ComponentName from "components/ComponentName" instead of like this: import ComponentName from "../../components/ComponentName" (this all would be assuming that my components directory lives inside a src directory) Doing a little bit of research, so far I've found two different methods to achieve this using Webpack: Making Webpack resolve modules inside

SyntaxError: Invalid or unexpected token @import

怎甘沉沦 提交于 2021-02-09 02:45:51
问题 I am trying to add Jest and Enzyme to a React webpack project. Everything is working, until I add tests to a component, with a style sheet importing google fonts. The error I get is: ● Test suite failed to run /Users/dev/Code/Git/react-redux-webpack/src/App.sass:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){@import url('https://fonts.googleapis.com/css?family=Barlow+Condensed') ^ SyntaxError: Invalid or unexpected token The sass file looks like:

SyntaxError: Invalid or unexpected token @import

旧时模样 提交于 2021-02-09 02:45:33
问题 I am trying to add Jest and Enzyme to a React webpack project. Everything is working, until I add tests to a component, with a style sheet importing google fonts. The error I get is: ● Test suite failed to run /Users/dev/Code/Git/react-redux-webpack/src/App.sass:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){@import url('https://fonts.googleapis.com/css?family=Barlow+Condensed') ^ SyntaxError: Invalid or unexpected token The sass file looks like:

How to make an import shortcut/alias in create-react-app?

瘦欲@ 提交于 2021-02-08 23:47:26
问题 How to set import shortcuts/aliases in create-react-app? From this: import { Layout } from '../../Components/Layout' to this: import { Layout } from '@Components/Layout' I have a webpack 4.42.0 version. I don't have a webpack.config.js file in the root directory. I've tried to create one myself with this code inside: const path = require('path') module.exports = { resolve: { alias: { '@': path.resolve(__dirname, 'src/'), } } }; But it doesn't seem to work. I've seen the NODE_PATH=. variant in

How to make an import shortcut/alias in create-react-app?

本秂侑毒 提交于 2021-02-08 23:45:04
问题 How to set import shortcuts/aliases in create-react-app? From this: import { Layout } from '../../Components/Layout' to this: import { Layout } from '@Components/Layout' I have a webpack 4.42.0 version. I don't have a webpack.config.js file in the root directory. I've tried to create one myself with this code inside: const path = require('path') module.exports = { resolve: { alias: { '@': path.resolve(__dirname, 'src/'), } } }; But it doesn't seem to work. I've seen the NODE_PATH=. variant in

How do I turn off source maps in production in Gatsby v2?

*爱你&永不变心* 提交于 2021-02-08 15:18:31
问题 I'm struggling how to disable source maps for production since the default Webpack set up is to leave out the devtool option, but Gatsby v2 is enabling it. I've tried coming up with a way based on the old version and the new docs, but it doesn't work: // gatsby-node.js exports.onCreateWebpackConfig = ({ actions, stage }) => { if (stage === 'build-javascript') { // turn off source-maps actions.setWebpackConfig({ devtool: false }) } }; 回答1: The code in the question is the correct solution. The