Skip to content

Commit 0b3a7b2

Browse files
way2exevilebottnawi
authored andcommitted
docs: publicPath documentation (#187)
* Update README.md Update README.md to tell user they can specify a custom path in `url`, relative or absolute * test: add test case for simple * test: add a new test case for publicpath option * test: reset the change of simple test case * Update webpack.config.js
1 parent 98b4d0e commit 0b3a7b2

File tree

7 files changed

+48
-1
lines changed

7 files changed

+48
-1
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ module.exports = {
5858
{
5959
test: /\.css$/,
6060
use: [
61-
MiniCssExtractPlugin.loader,
61+
{
62+
MiniCssExtractPlugin.loader,
63+
options: {
64+
// you can specify a publicPath here
65+
// by default it use publicPath in webpackOptions.output
66+
publicPath: '../'
67+
}
68+
},
6269
"css-loader"
6370
]
6471
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"eslint": "^4.17.0",
6565
"eslint-plugin-import": "^2.8.0",
6666
"eslint-plugin-prettier": "^2.6.0",
67+
"file-loader": "^1.1.11",
6768
"husky": "^0.14.3",
6869
"jest": "^22.2.2",
6970
"lint-staged": "^6.1.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
body { background: red; background-image: url(/static/img/cd0bb358c45b584743d8ce4991777c42.svg); }
2+

test/cases/simple-publicpath/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './style.css';
+1
Loading
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body { background: red; background-image: url(./react.svg); }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const Self = require('../../../');
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [
10+
{
11+
loader: Self.loader,
12+
options: {
13+
publicPath: '/static/img/'
14+
}
15+
},
16+
'css-loader',
17+
],
18+
}, {
19+
test: /\.(svg|png)$/,
20+
use: [{
21+
loader: 'file-loader',
22+
options: {
23+
filename: '[name].[ext]'
24+
}
25+
}]
26+
}
27+
],
28+
},
29+
plugins: [
30+
new Self({
31+
filename: '[name].css',
32+
}),
33+
],
34+
};

0 commit comments

Comments
 (0)