Skip to content

Commit 1884e55

Browse files
feat: publicPath can be a function (#172)
* fix: remove package lock and update yarnlocks * refactor: use babel for compiling client code * fix(options): enable using plugin without defining options * feat: publicPath can be a function * chore: various config and build updates * chore: updating tests and adding various CI improvements * test: correcting options and params * docs: more code examples based on features added
1 parent 139c6f4 commit 1884e55

File tree

80 files changed

+3420
-5923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3420
-5923
lines changed

.babelrc

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
11
{
22
"presets": [
33
[
4-
"env",
4+
"@babel/preset-env",
55
{
6-
"useBuiltIns": true,
76
"targets": {
87
"node": "6.9.0"
9-
},
10-
"exclude": [
11-
"transform-async-to-generator",
12-
"transform-regenerator"
13-
]
8+
}
149
}
1510
]
1611
],
17-
"plugins": [
18-
[
19-
"transform-object-rest-spread",
20-
{
21-
"useBuiltIns": true
22-
}
23-
]
24-
],
25-
"env": {
26-
"test": {
12+
"overrides": [
13+
{
14+
"test": "**/hmr/**/*.js",
2715
"presets": [
28-
"env"
29-
],
30-
"plugins": [
31-
"transform-object-rest-spread"
16+
[
17+
"@babel/preset-env",
18+
{
19+
"targets": {
20+
"node": "0.12"
21+
}
22+
}
23+
]
3224
]
3325
}
34-
}
26+
]
3527
}

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ insert_final_newline = true
99
trim_trailing_whitespace = true
1010

1111
[*.md]
12-
insert_final_newline = false
12+
insert_final_newline = true
1313
trim_trailing_whitespace = false

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/node_modules
22
/dist
3-
/test/cases
3+
/test/cases/*/expected
44
/test/js
55
/test/manual

.eslintrc.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
module.exports = {
22
root: true,
3+
parser: 'babel-eslint',
34
plugins: ['prettier'],
45
extends: ['@webpack-contrib/eslint-config-webpack'],
56
rules: {
6-
'prettier/prettier': [
7-
'error',
8-
{ singleQuote: true, trailingComma: 'es5', arrowParens: 'always' },
9-
],
10-
'class-methods-use-this': 'off',
11-
'no-undefined': 'off',
7+
'prettier/prettier': ['error'],
128
},
139
};

.prettierrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
singleQuote: true,
3+
trailingComma: 'es5',
4+
arrowParens: 'always',
5+
};

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,45 @@ module.exports = {
218218
};
219219
```
220220

221+
#### `publicPath` function example
222+
223+
**webpack.config.js**
224+
225+
```js
226+
const ExtractCSSChunksPlugin = require('extract-css-chunks-webpack-plugin');
227+
module.exports = {
228+
plugins: [
229+
new ExtractCSSChunksPlugin({
230+
// Options similar to the same options in webpackOptions.output
231+
// both options are optional
232+
filename: '[name].css',
233+
chunkFilename: '[id].css',
234+
}),
235+
],
236+
module: {
237+
rules: [
238+
{
239+
test: /\.css$/,
240+
use: [
241+
{
242+
loader: ExtractCSSChunksPlugin.loader,
243+
options: {
244+
publicPath: (resourcePath, context) => {
245+
// publicPath is the relative path of the resource to the context
246+
// e.g. for ./css/admin/main.css the publicPath will be ../../
247+
// while for ./css/main.css the publicPath will be ../
248+
return path.relative(path.dirname(resourcePath), context) + '/';
249+
},
250+
},
251+
},
252+
'css-loader',
253+
],
254+
},
255+
],
256+
},
257+
};
258+
```
259+
221260
## Desired Output
222261
Here's the sort of CSS you can expect to serve:
223262

lint-staged.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
ignore: ['package-lock.json'],
3+
linters: {
4+
'*.js': ['eslint --fix', 'git add'],
5+
},
6+
};

package.json

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,21 @@
3737
"scripts": {
3838
"start": "npm run build -- -w",
3939
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
40+
"postbuild": "es-check es5 dist/hmr/hotModuleReplacement.js",
4041
"clean": "del-cli dist",
4142
"commitlint": "commitlint",
42-
"commitmsg": "commitlint -e $GIT_PARAMS",
4343
"lint": "eslint --cache src test",
4444
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
4545
"lint-staged": "lint-staged",
4646
"prebuild": "npm run clean",
47-
"prepublish": "npm run build",
47+
"prepare": "npm run build",
4848
"release:validate": "commitlint --from=$(git describe --tags --abbrev=0) --to=$(git rev-parse HEAD)",
4949
"security": "npm audit",
50-
"test": "jest",
50+
"test:only": "jest",
5151
"test:watch": "jest --watch",
5252
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
53-
"test:manual": "webpack-dev-server test/manual/src/index.js --open --config test/manual/webpack.config.js",
53+
"pretest": "npm run lint",
54+
"test": "npm run test:coverage",
5455
"ci:lint": "npm run lint && npm run security",
5556
"ci:test": "npm run test -- --runInBand",
5657
"ci:coverage": "npm run test:coverage -- --runInBand",
@@ -66,42 +67,41 @@
6667
},
6768
"dependencies": {
6869
"loader-utils": "^1.1.0",
69-
"lodash": "^4.17.11",
7070
"normalize-url": "^2.0.1",
7171
"schema-utils": "^1.0.0",
7272
"webpack-sources": "^1.1.0"
7373
},
7474
"devDependencies": {
75-
"@commitlint/cli": "^6.1.3",
76-
"@commitlint/config-conventional": "^6.1.3",
77-
"@webpack-contrib/eslint-config-webpack": "^2.0.4",
78-
"babel-cli": "^6.26.0",
79-
"babel-jest": "^22.2.2",
80-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
81-
"babel-polyfill": "^6.26.0",
82-
"babel-preset-env": "^1.6.1",
83-
"conventional-github-releaser": "^2.0.2",
84-
"cross-env": "^5.1.3",
85-
"css-loader": "^0.28.10",
86-
"del": "^3.0.0",
75+
"@babel/cli": "^7.4.4",
76+
"@babel/core": "^7.4.4",
77+
"@babel/preset-env": "^7.4.4",
78+
"@commitlint/cli": "^7.6.1",
79+
"@commitlint/config-conventional": "^7.6.0",
80+
"@webpack-contrib/defaults": "^4.0.1",
81+
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
82+
"acorn": "^6.1.1",
83+
"babel-eslint": "^10.0.1",
84+
"babel-jest": "^24.8.0",
85+
"commitlint-azure-pipelines-cli": "^1.0.1",
86+
"cross-env": "^5.2.0",
87+
"css-loader": "^2.1.1",
88+
"del": "^4.1.1",
8789
"del-cli": "^1.1.0",
8890
"es-check": "^5.0.0",
89-
"eslint": "^4.17.0",
90-
"eslint-plugin-import": "^2.8.0",
91-
"eslint-plugin-prettier": "^2.6.0",
92-
"execa": "^1.0.0",
93-
"file-loader": "^1.1.11",
94-
"husky": "^0.14.3",
95-
"jest": "^22.2.2",
96-
"lint-staged": "^6.1.0",
91+
"eslint": "^5.16.0",
92+
"eslint-plugin-import": "^2.17.2",
93+
"eslint-plugin-prettier": "^3.1.0",
94+
"file-loader": "^3.0.1",
95+
"husky": "^2.2.0",
96+
"jest": "^24.8.0",
97+
"jest-junit": "^6.4.0",
98+
"lint-staged": "^8.1.6",
9799
"memory-fs": "^0.4.1",
98-
"pre-commit": "^1.2.2",
99-
"prettier": "^1.11.1",
100-
"semantic-release": "^15.13.1",
101-
"webpack": "^4.28.0",
102-
"webpack-cli": "^2.0.13",
103-
"webpack-defaults": "^2.3.0",
104-
"webpack-dev-server": "^3.1.14"
100+
"prettier": "^1.17.0",
101+
"standard-version": "^6.0.1",
102+
"webpack": "^4.31.0",
103+
"webpack-cli": "^3.3.2",
104+
"webpack-dev-server": "^3.3.1"
105105
},
106106
"pre-commit": "lint-staged",
107107
"lint-staged": {

0 commit comments

Comments
 (0)