Skip to content

Commit ffd8adb

Browse files
elevatebartArtem Sapegin
authored and
Artem Sapegin
committedOct 18, 2018
Fix: Fix webpack warnings
1 parent 621c2c6 commit ffd8adb

File tree

5 files changed

+2633
-1455
lines changed

5 files changed

+2633
-1455
lines changed
 

‎bin/styleguidist.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function commandBuild() {
107107
verbose('Webpack config:', compiler.options);
108108

109109
// Custom error reporting
110-
compiler.plugin('done', function(stats) {
110+
compiler.hooks.done.tap('rsgCustomErrorBuild', function(stats) {
111111
const messages = formatWebpackMessages(stats.toJson({}, true));
112112
const hasErrors = printAllErrorsAndWarnings(messages, stats.compilation);
113113
if (hasErrors) {
@@ -146,13 +146,13 @@ function commandServer() {
146146
verbose('Webpack config:', compiler.options);
147147

148148
// Show message when webpack is recompiling the bundle
149-
compiler.plugin('invalid', function() {
149+
compiler.hooks.invalid.tap('rsgInvalidServer', function() {
150150
console.log();
151151
spinner = ora('Compiling...').start();
152152
});
153153

154154
// Custom error reporting
155-
compiler.plugin('done', function(stats) {
155+
compiler.hooks.done.tap('rsgCustomErrorServer', function(stats) {
156156
if (spinner) {
157157
spinner.stop();
158158
}

‎package-lock.json

+2,597-1,430
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@
8787
"type-detect": "^4.0.8",
8888
"uglifyjs-webpack-plugin": "1.2.7",
8989
"unist-util-visit": "^1.3.1",
90-
"webpack-dev-server": "^2.11.2",
90+
"walkes": "^0.2.1",
91+
"webpack-dev-server": "^2.11.3",
9192
"webpack-merge": "^4.1.3"
9293
},
9394
"peerDependencies": {

‎scripts/utils/StyleguidistOptionsPlugin.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,17 @@ class StyleguidistOptionsPlugin {
1111
}
1212

1313
plugin(compilation) {
14-
compilation.plugin('normal-module-loader', (context, module) => {
14+
const pluginFunc = (context, module) => {
1515
if (!module.resource) {
1616
return;
1717
}
1818
context._styleguidist = this.options;
19-
});
19+
};
20+
compilation.hooks.normalModuleLoader.tap('StyleguidistOptionsPlugin', pluginFunc);
2021
}
2122

2223
apply(compiler) {
23-
if (compiler.hooks) {
24-
// Webpack 4
25-
compiler.hooks.compilation.tap('StyleguidistOptionsPlugin', this.plugin);
26-
} else {
27-
// Webpack 3
28-
compiler.plugin('compilation', this.plugin);
29-
}
24+
compiler.hooks.compilation.tap('StyleguidistOptionsPlugin', this.plugin);
3025
}
3126
}
3227

‎scripts/utils/__tests__/StyleguidistOptionsPlugin.spec.js

+27-12
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,47 @@ const options = {
44
foo: 42,
55
};
66

7-
it('should attach Styleguidist config object to webpack context', () => {
7+
it('should attach Styleguidist config when webpack 4 is used', () => {
88
const context = {};
99
const compiler = {
10-
plugin: (step, callback) => {
11-
callback({
12-
plugin: (step, callback) => {
13-
callback(context, { resource: 'pizza' });
10+
hooks: {
11+
compilation: {
12+
tap: (name, callback) => {
13+
callback({
14+
hooks: {
15+
normalModuleLoader: {
16+
tap: (name, compilationCallback) => {
17+
compilationCallback(context, { resource: 'pizza' });
18+
},
19+
},
20+
},
21+
});
1422
},
15-
});
23+
},
1624
},
1725
};
1826
const plugin = new StyleguidistOptionsPlugin(options);
1927
plugin.apply(compiler);
20-
2128
expect(context._styleguidist).toEqual(options);
2229
});
2330

2431
it('should do nothing when resource is empty', () => {
2532
const context = {};
2633
const compiler = {
27-
plugin: (step, callback) => {
28-
callback({
29-
plugin: (step, callback) => {
30-
callback(context, {});
34+
hooks: {
35+
compilation: {
36+
tap: (name, callback) => {
37+
callback({
38+
hooks: {
39+
normalModuleLoader: {
40+
tap: (name, compilationCallback) => {
41+
compilationCallback(context, {});
42+
},
43+
},
44+
},
45+
});
3146
},
32-
});
47+
},
3348
},
3449
};
3550
const plugin = new StyleguidistOptionsPlugin(options);

0 commit comments

Comments
 (0)
Please sign in to comment.