Skip to content

Commit 42f34e5

Browse files
committed
Call webpack during preact's build.
1 parent 35d0dae commit 42f34e5

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"scripts": {
77
"webpack": "webpack",
88
"start": "if-env NODE_ENV=production && npm run -s serve || npm run -s dev",
9-
"build": "npm run webpack && preact build --clean --template src/index.html --no-prerender --service-worker false",
9+
"build": "preact build --clean --template src/index.html --no-prerender --service-worker false",
1010
"release": "gulp release",
1111
"serve": "npm run release && preact serve --dir app",
12-
"dev": "npm run webpack && preact watch --template src/index.html --no-prerender",
12+
"dev": "preact watch --template src/index.html --no-prerender",
1313
"lint": "eslint src",
1414
"test": "jest ./",
1515
"update-core": "yarn unlink vue-sequence sequence-parser && yarn add vue-sequence sequence-parser",
@@ -40,6 +40,7 @@
4040
"devDependencies": {
4141
"babel-eslint": "^7.2.3",
4242
"babel-minify": "^0.2.0",
43+
"before-build-webpack": "^0.2.9",
4344
"chrome-webstore-upload-cli": "^1.2.0",
4445
"clean-webpack-plugin": "^3.0.0",
4546
"css-loader": "^0.28.11",
@@ -71,7 +72,8 @@
7172
"style-loader": "^0.20.3",
7273
"svg-url-loader": "^5.0.0",
7374
"sw-precache": "^5.2.0",
74-
"webpack": "3.12.0"
75+
"webpack": "3.12.0",
76+
"webpack-watch-files-plugin": "^1.0.3"
7577
},
7678
"dependencies": {
7779
"@emmetio/codemirror-plugin": "^0.5.4",

preact.config.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import CopyWebpackPlugin from 'copy-webpack-plugin';
2-
var CommonsChunkPlugin = require('webpack/lib/optimize/CommonsChunkPlugin');
31
const webpack = require('webpack');
4-
const path = require('path')
5-
const GitRevisionPlugin = require('git-revision-webpack-plugin')
2+
const path = require('path');
3+
const GitRevisionPlugin = require('git-revision-webpack-plugin');
4+
var WebpackBeforeBuildPlugin = require('before-build-webpack');
5+
import WatchExternalFilesPlugin from 'webpack-watch-files-plugin'
6+
67
const fsUtil = require('./fs-util');
8+
const spawn = require('child_process').spawn;
79

810
/**
911
* Function that mutates original webpack config.
@@ -14,6 +16,18 @@ const fsUtil = require('./fs-util');
1416
* @param {WebpackConfigHelpers} helpers - object with useful helpers when working with config.
1517
**/
1618
export default function(config, env, helpers) {
19+
config.plugins.push(new WatchExternalFilesPlugin({
20+
files: [
21+
'./main.js'
22+
]
23+
}));
24+
config.plugins.push(new WebpackBeforeBuildPlugin(function (stats, callback) {
25+
const child = spawn('yarn', ['webpack']);
26+
child.stdout.on('data', data => process.stdout.write(data));
27+
child.stderr.on('data', data => process.stderr.write(data));
28+
child.on('close', code => process.stdout.write(`yarn webpack exists with code ${code}`));
29+
callback();
30+
}));
1731
const htmlWebpackPlugin = helpers.getPluginsByName(
1832
config,
1933
'HtmlWebpackPlugin'

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,6 +3631,11 @@ beeper@^1.0.0:
36313631
resolved "https://registry.yarnpkg.com/beeper/-/beeper-1.1.1.tgz#e6d5ea8c5dad001304a70b22638447f69cb2f809"
36323632
integrity sha1-5tXqjF2tABMEpwsiY4RH9pyy+Ak=
36333633

3634+
before-build-webpack@^0.2.9:
3635+
version "0.2.9"
3636+
resolved "https://registry.yarnpkg.com/before-build-webpack/-/before-build-webpack-0.2.9.tgz#5929bfdeee5b1b609e2890839313cc41f5a8e026"
3637+
integrity sha512-zhRNAqPATAx0ojj/0LaKyQRjU/6tTMw5JEu2XGYKCzg94istvI1Mk7nOMH2+8cDXLPCgEugBVjGa/YEG0kvHcA==
3638+
36343639
big-integer@^1.6.17:
36353640
version "1.6.48"
36363641
resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.48.tgz#8fd88bd1632cba4a1c8c3e3d7159f08bb95b4b9e"
@@ -16274,6 +16279,14 @@ webpack-sources@^1.0.1:
1627416279
source-list-map "^2.0.0"
1627516280
source-map "~0.6.1"
1627616281

16282+
webpack-watch-files-plugin@^1.0.3:
16283+
version "1.0.3"
16284+
resolved "https://registry.yarnpkg.com/webpack-watch-files-plugin/-/webpack-watch-files-plugin-1.0.3.tgz#11e5ceead6e55f59a2a08ce567d58990b6186b9f"
16285+
integrity sha512-K5Y6FM9R01QkjWfwSNwfKqkP7MV6n/XZlzNCoAcTxd0Kdv2zhXc/asGWPwy+f+eBtSE0+TX4UJBLLQmxX360uA==
16286+
dependencies:
16287+
glob "^7.1.3"
16288+
lodash "^4.17.11"
16289+
1627716290
[email protected], webpack@^3.7.0:
1627816291
version "3.12.0"
1627916292
resolved "https://registry.yarnpkg.com/webpack/-/webpack-3.12.0.tgz#3f9e34360370602fcf639e97939db486f4ec0d74"

0 commit comments

Comments
 (0)