Skip to content

Commit

Permalink
fix: 回滚webpack版本到4.28.4,修复动态import异常
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhliu committed Apr 2, 2019
1 parent 989701b commit 666ee38
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
6 changes: 4 additions & 2 deletions packages/a8k/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"jest": "^24.5.0",
"jest-cli": "^24.5.0",
"jest-config": "^24.5.0",
"jest-environment-jsdom": "^24.5.0",
"jest-environment-jsdom": "^24.6.0",
"joycon": "^2.2.4",
"loader-utils": "^1.2.3",
"lodash": "^4.17.11",
Expand Down Expand Up @@ -96,11 +96,13 @@
"string.prototype.padstart": "^3.0.0",
"strip-ansi": "^5.2.0",
"style-loader": "^0.23.1",
"stylelint": "^9.10.1",
"stylelint-webpack-plugin": "^0.10.5",
"svg-inline-loader": "^0.8.0",
"terser": "^3.17.0",
"terser-webpack-plugin": "^1.2.3",
"url": "^0.11.0",
"webpack": "^4.29.6",
"webpack": "4.28.4",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-chain": "^5.2.4",
"webpack-dev-server": "^3.1.14",
Expand Down
11 changes: 11 additions & 0 deletions packages/a8k/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,17 @@ class A8k {
});
}

async runCompiler(compiler) {
await new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err) {
return reject(err);
}
resolve(stats);
});
});
}

hasDependency(name, type = 'all') {
const prodDeps = Object.keys(this.pkg.data.dependencies || {});
const devDeps = Object.keys(this.pkg.data.devDependencies || {});
Expand Down
17 changes: 15 additions & 2 deletions packages/a8k/src/plugins/command-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ export default {
...options,
type: TYPE_CLIENT,
});
await context.runWebpack(webpackConfig);
const compiler = context.createWebpackCompiler(webpackConfig);
compiler.hooks.done.tap('done', stats => {
if (stats.hasErrors()) {
process.exit(-1);
}
});
await context.runCompiler(compiler);
await hooks.invokePromise('afterBuild', context);

const { ssrConfig } = context.config;
Expand All @@ -68,7 +74,14 @@ export default {
...options,
type: TYPE_SERVER,
});
await context.runWebpack(webpackConfigSSR);
const compilerSSR = context.createWebpackCompiler(webpackConfigSSR);
compilerSSR.hooks.done.tap('done', stats => {
if (stats.hasErrors()) {
process.exit(-1);
}
});
await context.runCompiler(compilerSSR);
// await context.runWebpack(webpackConfigSSR);
await context.hooks.invokePromise('afterSSRBuild', context);
}
});
Expand Down
7 changes: 4 additions & 3 deletions packages/a8k/src/plugins/command-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ export default {
.description('启动开发者模式')
.option('-s, --ssr', '服务端渲染开发调试')
.option('-p, --port <port>', '配置开发者服务器监听端口')
.option('--eslint', '禁用eslint检测代码', false)
.option('--eslint', '启用eslint检测代码')
.option('--stylelint', '启用stylelint检测css')
.option('-c, --css-source-map', '使用cssSourceMap ,但会导致开发模式 FOUC')
.option('--inspectWebpack', '输出webpack配置信息')
.action(async ({ ssr, port, eslint, cssSourceMap, inspectWebpack }) => {
.action(async ({ ssr, port, eslint, stylelint, cssSourceMap, inspectWebpack }) => {
process.env.NODE_ENV = ENV_DEV;
context.options.inspectWebpack = inspectWebpack;
context.internals.mode = ENV_DEV;
context.config.publicPath = ''; // 开发模式下面不用publicPath
if (port) {
context.config.devServer.port = port;
}
const options = { ssr, eslint, cssSourceMap };
const options = { ssr, eslint, stylelint, cssSourceMap };
const { devServer, ssrDevServer, ssrConfig } = context.config;

if (ssr) {
Expand Down
7 changes: 6 additions & 1 deletion packages/a8k/src/plugins/config-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ENV_DEV, TYPE_CLIENT } from '../const';

exports.apply = context => {
context.chainWebpack((config, options) => {
const { type, eslint, ssr } = options;
const { type, eslint, stylelint, ssr } = options;
// 只有客户端代码 开发模式才需要使用,构建服务器代码不需要
if (type === TYPE_CLIENT && context.internals.mode === ENV_DEV) {
// 开发模式
Expand Down Expand Up @@ -47,6 +47,11 @@ exports.apply = context => {
eslintPath: context.resolve('node_modules', 'eslint'),
});
}
if (stylelint) {
const StyleLintPlugin = require('stylelint-webpack-plugin');
StyleLintPlugin.__expression = "require('stylelint-webpack-plugin')";
config.plugin('StyleLintPlugin').use(StyleLintPlugin, []);
}
const { HotModuleReplacementPlugin } = webpack;
HotModuleReplacementPlugin.__expression = "require('webpack').HotModuleReplacementPlugin";
config.plugin('HotModuleReplacementPlugin').use(webpack.HotModuleReplacementPlugin);
Expand Down

0 comments on commit 666ee38

Please sign in to comment.