From 350bb420c0f46abb23df1347fc09a9283c75e88b Mon Sep 17 00:00:00 2001 From: Vactor Date: Fri, 22 Jun 2018 11:34:03 +0800 Subject: [PATCH 1/5] Update README.md Update README.md to tell user they can specify a custom path in `url`, relative or absolute --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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" ] } From cb74603dfcd4e88593eee50dd76b5a34fa13b027 Mon Sep 17 00:00:00 2001 From: zhuqingguang Date: Fri, 22 Jun 2018 21:07:49 +0800 Subject: [PATCH 2/5] test: add test case for simple --- package.json | 1 + test/cases/simple/expected/main.css | 2 +- test/cases/simple/react.svg | 1 + test/cases/simple/style.css | 2 +- test/cases/simple/webpack.config.js | 17 +++++++++++++++-- 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 test/cases/simple/react.svg 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/expected/main.css b/test/cases/simple/expected/main.css index aea53e43..aff4e2be 100644 --- a/test/cases/simple/expected/main.css +++ b/test/cases/simple/expected/main.css @@ -1,2 +1,2 @@ -body { background: red; } +body { background: red; background-image: url(../cd0bb358c45b584743d8ce4991777c42.svg); } diff --git a/test/cases/simple/react.svg b/test/cases/simple/react.svg new file mode 100644 index 00000000..5b3b22a4 --- /dev/null +++ b/test/cases/simple/react.svg @@ -0,0 +1 @@ +logo-on-dark-bg \ No newline at end of file diff --git a/test/cases/simple/style.css b/test/cases/simple/style.css index 31fc5b8a..edcbc24a 100644 --- a/test/cases/simple/style.css +++ b/test/cases/simple/style.css @@ -1 +1 @@ -body { background: red; } +body { background: red; background-image: url(./react.svg); } diff --git a/test/cases/simple/webpack.config.js b/test/cases/simple/webpack.config.js index a22ebdad..54591c61 100644 --- a/test/cases/simple/webpack.config.js +++ b/test/cases/simple/webpack.config.js @@ -7,10 +7,23 @@ module.exports = { { test: /\.css$/, use: [ - Self.loader, + { + loader: Self.loader, + options: { + publicPath: '../' + } + }, 'css-loader', ], - }, + }, { + test: /\.(svg|png)$/, + use: [{ + loader: 'file-loader', + options: { + filename: '[name].[ext]' + } + }] + } ], }, plugins: [ From 9fd994a0816852a2c410c1956d673c490e66793c Mon Sep 17 00:00:00 2001 From: zhuqingguang Date: Sat, 23 Jun 2018 12:34:41 +0800 Subject: [PATCH 3/5] test: add a new test case for publicpath option --- package.json | 1 + .../cases/simple-publicpath/expected/main.css | 2 ++ test/cases/simple-publicpath/index.js | 1 + test/cases/simple-publicpath/react.svg | 1 + test/cases/simple-publicpath/style.css | 1 + .../cases/simple-publicpath/webpack.config.js | 34 +++++++++++++++++++ 6 files changed, 40 insertions(+) create mode 100644 test/cases/simple-publicpath/expected/main.css create mode 100644 test/cases/simple-publicpath/index.js create mode 100644 test/cases/simple-publicpath/react.svg create mode 100644 test/cases/simple-publicpath/style.css create mode 100644 test/cases/simple-publicpath/webpack.config.js 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', + }), + ], +}; From 20b27dbe6dfdf00f7f7701217034717cdb181e46 Mon Sep 17 00:00:00 2001 From: zhuqingguang Date: Sat, 23 Jun 2018 12:39:46 +0800 Subject: [PATCH 4/5] test: reset the change of simple test case --- test/cases/simple/expected/main.css | 2 +- test/cases/simple/react.svg | 1 - test/cases/simple/style.css | 2 +- test/cases/simple/webpack.config.js | 17 ++--------------- 4 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 test/cases/simple/react.svg diff --git a/test/cases/simple/expected/main.css b/test/cases/simple/expected/main.css index aff4e2be..aea53e43 100644 --- a/test/cases/simple/expected/main.css +++ b/test/cases/simple/expected/main.css @@ -1,2 +1,2 @@ -body { background: red; background-image: url(../cd0bb358c45b584743d8ce4991777c42.svg); } +body { background: red; } diff --git a/test/cases/simple/react.svg b/test/cases/simple/react.svg deleted file mode 100644 index 5b3b22a4..00000000 --- a/test/cases/simple/react.svg +++ /dev/null @@ -1 +0,0 @@ -logo-on-dark-bg \ No newline at end of file diff --git a/test/cases/simple/style.css b/test/cases/simple/style.css index edcbc24a..31fc5b8a 100644 --- a/test/cases/simple/style.css +++ b/test/cases/simple/style.css @@ -1 +1 @@ -body { background: red; background-image: url(./react.svg); } +body { background: red; } diff --git a/test/cases/simple/webpack.config.js b/test/cases/simple/webpack.config.js index 54591c61..a31253b1 100644 --- a/test/cases/simple/webpack.config.js +++ b/test/cases/simple/webpack.config.js @@ -7,22 +7,9 @@ module.exports = { { test: /\.css$/, use: [ - { - loader: Self.loader, - options: { - publicPath: '../' - } - }, + Self.loader, 'css-loader', - ], - }, { - test: /\.(svg|png)$/, - use: [{ - loader: 'file-loader', - options: { - filename: '[name].[ext]' - } - }] + ] } ], }, From 381a60e11b160e2aa7a9fa71dea7aeb91026a648 Mon Sep 17 00:00:00 2001 From: Vactor Date: Sat, 23 Jun 2018 12:41:27 +0800 Subject: [PATCH 5/5] Update webpack.config.js --- test/cases/simple/webpack.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cases/simple/webpack.config.js b/test/cases/simple/webpack.config.js index a31253b1..a22ebdad 100644 --- a/test/cases/simple/webpack.config.js +++ b/test/cases/simple/webpack.config.js @@ -9,8 +9,8 @@ module.exports = { use: [ Self.loader, 'css-loader', - ] - } + ], + }, ], }, plugins: [