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

fix/compiling-with-webpack-without-source-file #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 21 additions & 5 deletions webpack-loader.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
fs = require 'fs'

{log, getEnv} = require 'art-standard-lib'
loaderUtils = require 'loader-utils'

CaffeineMc = require './index'
CaffeineEight = require 'caffeine-eight'
loaderUtils = require 'loader-utils'
{log, getEnv} = require 'art-standard-lib'

###
TODO: Fix SOURCEMAPS (SBD 2018-07-30 notes)
Expand All @@ -18,6 +21,12 @@ SO - cafSourceMaps is off by default, but you can turn it on if you want:
{cafSourceMaps} = getEnv

module.exports = (source) ->
###
Compile source file if it's present on file system.
If it's inline source or just string compilation - than compile source itself.
(for example, when using inline code in .vue files)
###

@cacheable?()
# CaffeineMc manages its own cachability, but I'm unclear what disabling webpack's caching
# does... Does it cache across runs? What triggers a re-load if cacheable is false?
Expand All @@ -28,15 +37,22 @@ module.exports = (source) ->
# Even with addDependency, it wouldn't catch a file being added which alters module-resolution.

sourceFile = loaderUtils.getRemainingRequest @
try
{compiled:{js, sourceMap}} = CaffeineMc.FileCompiler.compileFileSync sourceFile, {
fileExists = fs.existsSync(sourceFile)

compileOptions = {
source
@debug
sourceRoot: "" # make sourceMaps references relative to webpack's start directory
cache: true # CaffeineMc's external-reference-smart caching
inlineMap: !!cafSourceMaps # experimental - works in Safari, not Chrome
prettier: !cafSourceMaps # prettier is incompatible with sourceMaps
}

try
if fileExists
{compiled: {js, sourceMap}} = CaffeineMc.FileCompiler.compileFileSync sourceFile, compileOptions
else
{compiled: {js, sourceMap}} = CaffeineMc.compile source, compileOptions
@callback null, js, sourceMap

catch e
Expand All @@ -48,4 +64,4 @@ module.exports = (source) ->
log.error "CaffeineMc webpack-loader error": e
throw e

module.exports.separable = true
module.exports.separable = true
40 changes: 27 additions & 13 deletions webpack-loader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.