diff --git a/cli/hooks/webpack.js b/cli/hooks/webpack.js index be6373deb84..02eb1f6a62c 100644 --- a/cli/hooks/webpack.js +++ b/cli/hooks/webpack.js @@ -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; @@ -30,8 +30,7 @@ exports.init = (logger, config, cli) => { return; } - isWebpackProject = !!cli.tiapp.webpack; - if (!isWebpackProject) { + if (!isWebpackProject(cli.argv['project-dir'])) { return; } @@ -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(); } @@ -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; diff --git a/cli/lib/webpack/service.js b/cli/lib/webpack/service.js index 46118996748..2c1adbfc150 100644 --- a/cli/lib/webpack/service.js +++ b/cli/lib/webpack/service.js @@ -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(); @@ -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