Skip to content

Commit 08fe9fd

Browse files
committed
fix(webpack): fix compatibility with latest webpack
1 parent 2d2ae53 commit 08fe9fd

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"sass-loader": "^4.0.2",
7272
"style-loader": "^0.13.1",
7373
"url-loader": "^0.5.7",
74-
"webpack": "^2.1.0-beta.22",
74+
"webpack": "2.1.0-beta.25",
7575
"yargs": "^5.0.0"
7676
},
7777
"devDependencies": {

src/configure-bundler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default async function(options) {
2222

2323
return webpack(configure({
2424
context: WORKINGDIR,
25-
devtool: options.devtool,
25+
devtool: options.devtool ? options.devtool : false,
2626
production: options.production,
2727
output: {
2828
path: WORKINGDIR,

src/configure-webpack.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@ const BABEL_LOADER = 'babel-loader?' + JSON.stringify(babelrc);
88
const CSS_LOADER = 'css-loader?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]';
99
const SASS_LOADER = 'sass-loader?sourceMap';
1010
const LESS_LOADER = 'less-loader?sourceMap';
11-
const STYLE_LOADERS = [ 'style-loader', CSS_LOADER, 'postcss-loader' ];
12-
13-
export const extensions = [ '', '.web.js', '.js' ];
11+
const STYLE_LOADERS = [
12+
'style-loader',
13+
CSS_LOADER,
14+
{
15+
loader: 'postcss-loader',
16+
options: {
17+
plugins() {
18+
return [ autoprefixer ];
19+
},
20+
},
21+
}
22+
];
1423

1524
export default (options) => ({
1625
context: options.context,
1726
entry: options.entry,
1827
output: options.output,
1928
devtool: options.devtool,
2029

21-
postcss() {
22-
return [ autoprefixer ];
23-
},
24-
2530
plugins: [
2631
new webpack.NoErrorsPlugin(),
2732
new webpack.DefinePlugin({
@@ -44,7 +49,7 @@ export default (options) => ({
4449
.concat(options.plugins || []),
4550

4651
module: {
47-
loaders: [
52+
rules: [
4853
{
4954
test: /\.js$/,
5055
exclude: /node_modules/,
@@ -56,21 +61,21 @@ export default (options) => ({
5661
},
5762
{
5863
test: /\.css$/,
59-
loaders: STYLE_LOADERS,
64+
use: STYLE_LOADERS,
6065
},
6166
{
6267
test: /\.less$/,
63-
loaders: [ ...STYLE_LOADERS, LESS_LOADER ],
68+
use: [ ...STYLE_LOADERS, LESS_LOADER ],
6469
},
6570
{
6671
test: /\.scss$/,
67-
loaders: [ ...STYLE_LOADERS, SASS_LOADER ],
72+
use: [ ...STYLE_LOADERS, SASS_LOADER ],
6873
},
6974
{
7075
test: /\.(gif|jpg|png|webp|svg)$/,
7176
loader: 'url?limit=25000',
7277
},
73-
]
78+
],
7479
},
7580

7681
resolveLoader: {
@@ -81,7 +86,6 @@ export default (options) => ({
8186
},
8287

8388
resolve: {
84-
extensions,
8589
modules: [
8690
path.join(CURRENTDIR, 'node_modules'),
8791
path.resolve(options.context, 'node_modules'),

src/quik-middleware-hmr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function(options) {
3737
]
3838
});
3939

40-
const loaders = config.module.loaders;
40+
const loaders = config.module.rules;
4141

4242
for (const loader of loaders) {
4343
if (loader.loader && loader.loader.indexOf('babel') > -1) {

src/quik-middleware-js.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import readFileAsync from './read-file-async';
44
import runCompilerAsync from './run-compiler-async';
55
import formatError from './format-error';
66
import bundler from './configure-bundler';
7-
import { extensions } from './configure-webpack';
8-
97
const CONTENT_TYPE = 'application/javascript';
108

119
export default function(options) {
1210
const WORKINGDIR = options.root;
1311

14-
const test = file => extensions.some(ext => ext && file.endsWith(ext));
12+
const test = file => file.endsWith('.js');
1513

1614
return function *(next) {
1715
if (this.method === 'GET' && this.accepts(CONTENT_TYPE) && test(this.path) && this.query.transpile !== 'false') {

test/hmr.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import EventSource from 'eventsource';
77
import server from '../dist/server';
88

99
test.cb('should rebuild on changes', t => {
10+
const SYNC = 'sync';
1011
const BUILDING = 'building';
1112
const BUILT = 'built';
1213
const HEARTBEAT = '💓';
@@ -32,7 +33,7 @@ test.cb('should rebuild on changes', t => {
3233
});
3334
}
3435

35-
t.plan(14);
36+
t.plan(15);
3637

3738
const hmr = new EventSource('http://localhost:3005/__webpack_hmr');
3839

@@ -45,13 +46,13 @@ test.cb('should rebuild on changes', t => {
4546
};
4647

4748
let i = 0;
48-
let action = BUILDING;
49+
let action = SYNC;
4950

5051
hmr.onmessage = message => {
5152
/* eslint-disable ava/no-statement-after-end */
5253
const data = message.data;
5354

54-
if (i === 6) {
55+
if (i === 7) {
5556
t.deepEqual(data, HEARTBEAT, 'should recieve heartbeat');
5657

5758
hmr.close();
@@ -74,6 +75,9 @@ test.cb('should rebuild on changes', t => {
7475
}
7576

7677
switch (parsed.action) {
78+
case SYNC:
79+
action = BUILDING;
80+
break;
7781
case BUILDING:
7882
action = BUILT;
7983
break;

0 commit comments

Comments
 (0)