diff --git a/README.md b/README.md index 4aef8da9..e9197a24 100644 --- a/README.md +++ b/README.md @@ -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" ] } diff --git a/package.json b/package.json index 818164ea..d977ebda 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/cases/simple-publicpath/expected/main.css b/test/cases/simple-publicpath/expected/main.css new file mode 100644 index 00000000..6073c14a --- /dev/null +++ b/test/cases/simple-publicpath/expected/main.css @@ -0,0 +1,2 @@ +body { background: red; background-image: url(/static/img/cd0bb358c45b584743d8ce4991777c42.svg); } + diff --git a/test/cases/simple-publicpath/index.js b/test/cases/simple-publicpath/index.js new file mode 100644 index 00000000..aa3357bf --- /dev/null +++ b/test/cases/simple-publicpath/index.js @@ -0,0 +1 @@ +import './style.css'; diff --git a/test/cases/simple-publicpath/react.svg b/test/cases/simple-publicpath/react.svg new file mode 100644 index 00000000..5b3b22a4 --- /dev/null +++ b/test/cases/simple-publicpath/react.svg @@ -0,0 +1 @@ +logo-on-dark-bg \ No newline at end of file diff --git a/test/cases/simple-publicpath/style.css b/test/cases/simple-publicpath/style.css new file mode 100644 index 00000000..edcbc24a --- /dev/null +++ b/test/cases/simple-publicpath/style.css @@ -0,0 +1 @@ +body { background: red; background-image: url(./react.svg); } diff --git a/test/cases/simple-publicpath/webpack.config.js b/test/cases/simple-publicpath/webpack.config.js new file mode 100644 index 00000000..75b7b8b8 --- /dev/null +++ b/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', + }), + ], +};