Skip to content

Commit 59ce1ab

Browse files
committed
Remove redundant webpack config, use loaders for static assets instead.
1 parent 3d7950e commit 59ce1ab

File tree

7 files changed

+41
-17
lines changed

7 files changed

+41
-17
lines changed
File renamed without changes.

demo/index.html renamed to demo/src/index.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
name="description"
1010
content="Accessible Accordion component for React"
1111
/>
12-
<link rel="stylesheet" href="main.css" />
13-
<link rel="shortcut icon" href="favicon.ico" />
12+
<link rel="shortcut icon" href="${require('./favicon.ico')}" />
1413
</head>
1514
<body>
1615
<div class="wrapper">

demo/js/demo.tsx renamed to demo/src/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
} from '../../src';
1212

1313
// tslint:disable-next-line no-import-side-effect
14+
import './main.css';
15+
16+
// tslint:disable-next-line no-import-side-effect ordered-imports
1417
import '../../src/css/fancy-example.css';
1518

1619
// tslint:disable-next-line max-func-body-length
File renamed without changes.

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"build:clean": "mkdir dist || true & rm -rf dist/*",
1818
"build:rollup": "rollup -c",
1919
"build:types": "yarn tsc --project tsconfig.declaration.json",
20-
"build": "yarn build:clean && yarn build:css && yarn build:rollup",
21-
"start-demo": "webpack-dev-server --mode=development",
22-
"pages": "rm -rf pages && webpack --mode=production --progress && cp demo/*.css pages && cp demo/*.ico pages",
20+
"build:demo": "webpack --context=demo --mode=production --progress --output-path=pages",
21+
"start-demo": "webpack-dev-server --context=demo --mode=development --hot",
22+
"pages": "rm -rf pages && yarn build:demo",
2323
"deploy": "yarn pages && ./bin/deploy.sh",
2424
"format": "prettier \"**/*\" --write",
2525
"prepublishOnly": "yarn typecheck && yarn lint && yarn test && yarn build"
@@ -75,10 +75,12 @@
7575
"enzyme": "^3.3.0",
7676
"enzyme-adapter-react-16": "^1.1.1",
7777
"enzyme-to-json": "^3.3.4",
78+
"file-loader": "^3.0.1",
7879
"html-webpack-plugin": "^3.2.0",
7980
"husky": "^1.2.1",
8081
"jest": "^23.6.0",
8182
"lint-staged": "^8.1.0",
83+
"mini-css-extract-plugin": "^0.5.0",
8284
"prettier": "^1.15.3",
8385
"raf": "^3.4.0",
8486
"react": "^16.4.0",

webpack.config.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
const webpack = require('webpack');
33
const path = require('path');
44
const HtmlWebpackPlugin = require('html-webpack-plugin');
5+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
56

67
module.exports = (env, options) => ({
78
mode: options.mode,
8-
devtool: 'source-map',
9-
entry: path.resolve(__dirname, 'demo/js/demo.tsx'),
109
output: {
11-
path: path.resolve(__dirname, 'pages'),
1210
filename:
1311
options.mode === 'production'
1412
? '[name][chunkhash].js'
@@ -27,7 +25,16 @@ module.exports = (env, options) => ({
2725
},
2826
{
2927
test: /\.css$/,
30-
loaders: ['style-loader', 'css-loader'],
28+
use: [
29+
options.mode === 'production'
30+
? MiniCssExtractPlugin.loader
31+
: 'style-loader',
32+
'css-loader',
33+
],
34+
},
35+
{
36+
test: /\.ico$/,
37+
loaders: ['file-loader'],
3138
},
3239
],
3340
},
@@ -36,15 +43,11 @@ module.exports = (env, options) => ({
3643
},
3744

3845
plugins: [
39-
options.mode === 'development'
40-
? new webpack.HotModuleReplacementPlugin()
41-
: () => {},
4246
new HtmlWebpackPlugin({
43-
template: path.resolve(__dirname, 'demo/index.html'),
47+
template: 'src/index.html',
48+
}),
49+
new MiniCssExtractPlugin({
50+
filename: '[name][contenthash].css',
4451
}),
4552
],
46-
47-
devServer: {
48-
contentBase: './demo',
49-
},
5053
});

yarn.lock

+17
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,14 @@ figures@^2.0.0:
30413041
dependencies:
30423042
escape-string-regexp "^1.0.5"
30433043

3044+
file-loader@^3.0.1:
3045+
version "3.0.1"
3046+
resolved "https://registry.yarnpkg.com/file-loader/-/file-loader-3.0.1.tgz#f8e0ba0b599918b51adfe45d66d1e771ad560faa"
3047+
integrity sha512-4sNIOXgtH/9WZq4NvlfU3Opn5ynUsqBwSLyM+I7UOwdGigTBYfVVQEwe/msZNX/j4pCJTIM14Fsw66Svo1oVrw==
3048+
dependencies:
3049+
loader-utils "^1.0.2"
3050+
schema-utils "^1.0.0"
3051+
30443052
filename-regex@^2.0.0:
30453053
version "2.0.1"
30463054
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26"
@@ -5150,6 +5158,15 @@ mimic-fn@^1.0.0:
51505158
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
51515159
integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==
51525160

5161+
mini-css-extract-plugin@^0.5.0:
5162+
version "0.5.0"
5163+
resolved "https://registry.yarnpkg.com/mini-css-extract-plugin/-/mini-css-extract-plugin-0.5.0.tgz#ac0059b02b9692515a637115b0cc9fed3a35c7b0"
5164+
integrity sha512-IuaLjruM0vMKhUUT51fQdQzBYTX49dLj8w68ALEAe2A4iYNpIC4eMac67mt3NzycvjOlf07/kYxJDc0RTl1Wqw==
5165+
dependencies:
5166+
loader-utils "^1.1.0"
5167+
schema-utils "^1.0.0"
5168+
webpack-sources "^1.1.0"
5169+
51535170
minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1:
51545171
version "1.0.1"
51555172
resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"

0 commit comments

Comments
 (0)