Skip to content

Commit

Permalink
chore: webpack hook wip
Browse files Browse the repository at this point in the history
  • Loading branch information
janvennemann committed Apr 24, 2020
1 parent 5b25c1d commit fe3197c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
27 changes: 23 additions & 4 deletions cli/hooks/webpack.js
Expand Up @@ -14,7 +14,7 @@ let AppcdClient;
exports.id = 'ti.webpack';
exports.init = (logger, config, cli) => {
let isBuildCommand = false;
let isWebpackProject = false;
let isWebpackEnabled = false;

cli.on('cli:command-loaded', (hookData) => {
const command = hookData.command;
Expand All @@ -30,8 +30,7 @@ exports.init = (logger, config, cli) => {
return;
}

isWebpackProject = !!cli.tiapp.webpack;
if (!isWebpackProject) {
if (!isWebpackProject(cli.argv['project-dir'])) {
return;
}

Expand All @@ -54,12 +53,14 @@ exports.init = (logger, config, cli) => {
}

AppcdClient = resolveAppcdClient(appcdRootPath);

isWebpackEnabled = true;
});

cli.on('build.pre.compile', {
priority: 800,
post(builder, callback) {
if (!isWebpackProject) {
if (!isWebpackEnabled) {
return callback();
}

Expand Down Expand Up @@ -97,6 +98,24 @@ exports.init = (logger, config, cli) => {
});
};

function isWebpackProject(projectDir) {
const pkgPath = path.join(projectDir, 'package.json');
if (!fs.existsSync(pkgPath)) {
return false;
}

const tiPlugins = [
'@titanium-sdk/webpack-plugin-classic',
'@titanium-sdk/webpack-plugin-alloy',
'@titanium-sdk/webpack-plugin-vue',
'@titanium-sdk/webpack-plugin-angular'
];
const pkg = require(pkgPath);
const allDeps = Object.keys(pkg.devDependencies || {})
.concat(Object.keys(pkg.dependencies || {}));
return tiPlugins.some(id => allDeps.includes(id));
}

function resolveModuleRoot(name, paths) {
try {
let resolvedPath;
Expand Down
9 changes: 7 additions & 2 deletions cli/lib/webpack/service.js
Expand Up @@ -13,10 +13,14 @@ class WebpackService {
this.projectSettings = {
path: cli.argv['project-dir'],
name: tiapp.name,
type: tiapp.webpack.type,
// type: tiapp.webpack.type,
};
this.loadBuildSettings(builder, cli);
this.shouldWatch = builder.deployType !== 'production' && !builder.buildOnly;
if (builder.buildOnly) {
this.shouldWatch = false;
} else {
this.shouldWatch = builder.deployType !== 'production' && !builder.buildOnly;
}

this.forceRebuild = this.buildSettings.platform === 'ios' ? builder.forceCleanBuild : builder.forceRebuild;
this.jobIdentifier = this.generateJobIdentifier();
Expand Down Expand Up @@ -77,6 +81,7 @@ class WebpackService {
ensureWebpackIsRunning() {
const options = {
identifier: this.jobIdentifier,
task: 'build', // this.buildSettings.deployType === 'production' ? 'build' : 'serve',
watch: this.shouldWatch,
project: this.projectSettings,
build: this.buildSettings
Expand Down

0 comments on commit fe3197c

Please sign in to comment.