Skip to content

Commit

Permalink
docs: publicPath documentation (#187)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
way2ex authored and evilebottnawi committed Jun 25, 2018
1 parent 98b4d0e commit 0b3a7b2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Expand Up @@ -58,7 +58,14 @@ module.exports = {
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
MiniCssExtractPlugin.loader,
options: {
// you can specify a publicPath here
// by default it use publicPath in webpackOptions.output
publicPath: '../'
}
},
"css-loader"
]
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -64,6 +64,7 @@
"eslint": "^4.17.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-prettier": "^2.6.0",
"file-loader": "^1.1.11",
"husky": "^0.14.3",
"jest": "^22.2.2",
"lint-staged": "^6.1.0",
Expand Down
2 changes: 2 additions & 0 deletions test/cases/simple-publicpath/expected/main.css
@@ -0,0 +1,2 @@
body { background: red; background-image: url(/static/img/cd0bb358c45b584743d8ce4991777c42.svg); }

1 change: 1 addition & 0 deletions test/cases/simple-publicpath/index.js
@@ -0,0 +1 @@
import './style.css';
1 change: 1 addition & 0 deletions test/cases/simple-publicpath/react.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/cases/simple-publicpath/style.css
@@ -0,0 +1 @@
body { background: red; background-image: url(./react.svg); }
34 changes: 34 additions & 0 deletions test/cases/simple-publicpath/webpack.config.js
@@ -0,0 +1,34 @@
const Self = require('../../../');

module.exports = {
entry: './index.js',
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: Self.loader,
options: {
publicPath: '/static/img/'
}
},
'css-loader',
],
}, {
test: /\.(svg|png)$/,
use: [{
loader: 'file-loader',
options: {
filename: '[name].[ext]'
}
}]
}
],
},
plugins: [
new Self({
filename: '[name].css',
}),
],
};

0 comments on commit 0b3a7b2

Please sign in to comment.