diff --git a/packages/strapi-helper-plugin/lib/internals/webpack/webpack.base.babel.js b/packages/strapi-helper-plugin/lib/internals/webpack/webpack.base.babel.js index db1ce5173b..ddfe29cda8 100755 --- a/packages/strapi-helper-plugin/lib/internals/webpack/webpack.base.babel.js +++ b/packages/strapi-helper-plugin/lib/internals/webpack/webpack.base.babel.js @@ -10,14 +10,33 @@ const webpack = require('webpack'); const pkg = require(path.resolve(process.cwd(), 'package.json')); const pluginId = pkg.name.replace(/^strapi-/i, ''); -const plugins = process.env.IS_ADMIN === 'true' ? fs.readdirSync(path.resolve(process.env.PWD, '..', 'plugins')) - .filter(x => x[0] !== '.') : []; +let noPlugin = false; +let plugins = []; +let pluginFolders = {}; -const pluginFolders = plugins.reduce((acc, current) => { - acc[current] = path.resolve(process.env.PWD, '..', 'plugins', current, 'node_modules', 'strapi-helper-plugin', 'lib', 'src'); +if (process.env.npm_lifecycle_event === 'start') { + try { + fs.accessSync(path.resolve(process.env.PWD, '..', 'plugins'), fs.constants.R_OK); + } catch (e) { + try { + fs.accessSync(path.resolve(process.env.PWD, '..', 'api'), fs.constants.R_OK); - return acc; -}, {}); + // Allow app without plugins. + noPlugin = true; + } catch (e) { + throw new Error(`You need to start the WebPack server from the /admin directory in a Strapi's project.`); + } + } + + plugins = process.env.IS_ADMIN === 'true' && !noPlugin ? fs.readdirSync(path.resolve(process.env.PWD, '..', 'plugins')) + .filter(x => x[0] !== '.') : []; + + pluginFolders = plugins.reduce((acc, current) => { + acc[current] = path.resolve(process.env.PWD, '..', 'plugins', current, 'node_modules', 'strapi-helper-plugin', 'lib', 'src'); + + return acc; + }, {}); +} module.exports = (options) => ({ entry: options.entry, diff --git a/packages/strapi-helper-plugin/lib/internals/webpack/webpack.dev.babel.js b/packages/strapi-helper-plugin/lib/internals/webpack/webpack.dev.babel.js index bb82115bd9..09f548547e 100755 --- a/packages/strapi-helper-plugin/lib/internals/webpack/webpack.dev.babel.js +++ b/packages/strapi-helper-plugin/lib/internals/webpack/webpack.dev.babel.js @@ -14,21 +14,35 @@ const postcssReporter = require('postcss-reporter'); const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; const LodashModuleReplacementPlugin = require('lodash-webpack-plugin'); -const plugins = process.env.IS_ADMIN === 'true' ? fs.readdirSync(path.resolve(process.env.PWD, '..', 'plugins')) - .filter(x => x[0] !== '.') : []; +let noPlugin = false; +let plugins = []; +let pluginFolders = {}; -const pluginFolders = plugins.reduce((acc, current) => { - acc[current] = path.resolve(process.env.PWD, '..', 'plugins', current, 'node_modules', 'strapi-helper-plugin', 'lib', 'src'); +if (process.env.npm_lifecycle_event === 'start') { + try { + fs.accessSync(path.resolve(process.env.PWD, '..', 'plugins'), fs.constants.R_OK); + } catch (e) { + try { + fs.accessSync(path.resolve(process.env.PWD, '..', 'api'), fs.constants.R_OK); - return acc; -}, {}); + // Allow app without plugins. + noPlugin = true; + } catch (e) { + throw new Error(`You need to start the WebPack server from the /admin directory in a Strapi's project.`); + } + } + + plugins = process.env.IS_ADMIN === 'true' && !noPlugin ? fs.readdirSync(path.resolve(process.env.PWD, '..', 'plugins')) + .filter(x => x[0] !== '.') : []; + + pluginFolders = plugins.reduce((acc, current) => { + acc[current] = path.resolve(process.env.PWD, '..', 'plugins', current, 'node_modules', 'strapi-helper-plugin', 'lib', 'src'); + + return acc; + }, {}); +} const appPath = path.join(process.cwd(), 'admin', 'src', 'app.js') - -const logger = require('../../server/logger'); - -const pkg = require(path.resolve(process.cwd(), 'package.json')); -const dllPlugin = pkg.dllPlugin; const port = argv.port || process.env.PORT || 3000; module.exports = require('./webpack.base.babel')({ diff --git a/packages/strapi-helper-plugin/package.json b/packages/strapi-helper-plugin/package.json index 31f9ab71c8..9446a85d55 100755 --- a/packages/strapi-helper-plugin/package.json +++ b/packages/strapi-helper-plugin/package.json @@ -115,4 +115,4 @@ "webpack-hot-middleware": "^2.18.2", "whatwg-fetch": "^2.0.3" } -} +} \ No newline at end of file