Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flags for webpack debug and production mode #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions lektor_webpack_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,30 @@ def __init__(self, *args, **kwargs):
def is_enabled(self, build_flags):
return bool(build_flags.get('webpack'))

def run_webpack(self, watch=False):
def is_debug(self, build_flags):
return bool(build_flags.get('debug'))

def is_production(self, build_flags):
return bool(build_flags.get('production'))

def get_mode(self, build_flags):
if self.is_debug(build_flags):
return 'd'
elif self.is_production(build_flags):
return 'p'

def run_webpack(self, watch=False, mode=None):
webpack_root = os.path.join(self.env.root_path, 'webpack')
args = [os.path.join(webpack_root, 'node_modules', '.bin', 'webpack')]
env = os.environ.copy()
if watch:
args.append('--watch')
return portable_popen(args, cwd=webpack_root)
if mode is 'd':
args.append('-d')
elif mode is 'p':
args.append('-p')
env['NODE_ENV'] = 'production'
return portable_popen(args, cwd=webpack_root, env=env)

def npm_install(self):
reporter.report_generic('Running npm install')
Expand All @@ -33,7 +51,7 @@ def on_server_spawn(self, build_flags, **extra):
return
self.npm_install()
reporter.report_generic('Spawning webpack watcher')
self.webpack_process = self.run_webpack(watch=True)
self.webpack_process = self.run_webpack(watch=True, mode=self.get_mode(build_flags))

def on_server_stop(self, **extra):
if self.webpack_process is not None:
Expand All @@ -46,5 +64,5 @@ def on_before_build_all(self, builder, **extra):
return
self.npm_install()
reporter.report_generic('Starting webpack build')
self.run_webpack().wait()
self.run_webpack(mode=self.get_mode(builder.build_flags)).wait()
reporter.report_generic('Webpack build finished')