Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 14, 2025. It is now read-only.

Commit e411605

Browse files
author
vinogradov
committed
Improve webpack.config.js and jest config: add shared bin file types
1 parent b18031f commit e411605

File tree

9 files changed

+44
-8
lines changed

9 files changed

+44
-8
lines changed

‎bin-file-types.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'jpe?g|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac';

‎jest.config.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const BIN_FILE_TYPES = require('./bin-file-types');
2+
3+
module.exports = {
4+
moduleNameMapper: {
5+
'\\.(css)$': '<rootDir>/__mocks__/styleMock.js',
6+
[`\\.(${BIN_FILE_TYPES})$`]: '<rootDir>/__mocks__/fileMock.js'
7+
}
8+
};

‎package.json‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,5 @@
6161
},
6262
"engines": {
6363
"node": ">=7.5.0"
64-
},
65-
"jest": {
66-
"moduleNameMapper": {
67-
"\\.(css)$": "<rootDir>/__mocks__/styleMock.js",
68-
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|ico)$": "<rootDir>/__mocks__/fileMock.js"
69-
}
7064
}
7165
}

‎src/examples/react/__tests__/__snapshots__/hello.test.js.snap‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
exports[`renders correctly 1`] = `
44
<div>
5+
<img
6+
alt=""
7+
src=""
8+
styleName="logo"
9+
/>
510
<div>
611
Hello
712
<span

‎src/examples/react/hello.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
border: 1px solid black;
1212
margin-top: 10px;
1313
}
14+
15+
.logo {
16+
width: 20px;
17+
}

‎src/examples/react/hello.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import './hello.css';
4+
import logo from './logo.svg';
45

56
export class Hello extends React.Component {
67
constructor(props) {
@@ -22,6 +23,7 @@ export class Hello extends React.Component {
2223
render() {
2324
return (
2425
<div>
26+
<img src={logo} styleName="logo" alt="" />
2527
<div>Hello <span styleName="name">{this.props.name}</span></div>
2628
<button styleName="submit-button" onClick={this.onClickHandler}>
2729
toggle: {this.state.toggle ? 'ON' : 'OFF'}

‎src/examples/react/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import * as ReactDOM from 'react-dom';
33
import {Hello} from './hello';
44

55
ReactDOM.render(
6-
<Hello name="John" />,
6+
<Hello name="React" />,
77
document.querySelector('#app')
88
);

‎src/examples/react/logo.svg‎

Lines changed: 21 additions & 0 deletions
Loading[フレーム]

‎webpack.config.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const ChunkManifestPlugin = require('chunk-manifest-webpack-plugin');
77
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
88
const WebpackChunkHash = require('webpack-chunk-hash');
99
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
10+
const BIN_FILE_TYPES = require('./bin-file-types');
1011

1112
function getVendorSplittingPlugins(defaultPlugins) {
1213
// https://webpack.js.org/guides/caching/
@@ -163,7 +164,7 @@ module.exports = (env) => {
163164
use: `css-loader?${IS_PRODUCTION ? 'minimize&' : ''}${CSS_MODULES_CONFIG}`
164165
})
165166
}, {
166-
test: /\.(jpe?g|png|gif|svg)$/,
167+
test: newRegExp(`\\.(${BIN_FILE_TYPES})$`),
167168
include: SRC_ABSOLUTE_PATH, // other paths are ignored
168169
use: 'file-loader'
169170
}]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /