@ -48,22 +48,22 @@ class MonacoWebpackPlugin {
constructor ( options = { } ) {
constructor ( options = { } ) {
const languages = options . languages || Object . keys ( languagesById ) ;
const languages = options . languages || Object . keys ( languagesById ) ;
const features = getFeaturesIds ( options . features || [ ] , featuresById ) ;
const features = getFeaturesIds ( options . features || [ ] , featuresById ) ;
const output = options . output || '' ;
this . options = {
this . options = {
languages : languages . map ( ( id ) => languagesById [ id ] ) . filter ( Boolean ) ,
languages : languages . map ( ( id ) => languagesById [ id ] ) . filter ( Boolean ) ,
features : features . map ( id => featuresById [ id ] ) . filter ( Boolean ) ,
features : features . map ( id => featuresById [ id ] ) . filter ( Boolean ) ,
output ,
output : options . output || '' ,
publicPath : options . publicPath || ''
} ;
} ;
}
}
apply ( compiler ) {
apply ( compiler ) {
const { languages , features , output } = this . options ;
const { languages , features , output , publicPath } = this . options ;
const publicPath = get PublicPath( compiler ) ;
const com pilationP ublicPath = get Compilation PublicPath( compiler ) ;
const modules = [ EDITOR _MODULE ] . concat ( languages ) . concat ( features ) ;
const modules = [ EDITOR _MODULE ] . concat ( languages ) . concat ( features ) ;
const workers = modules . map (
const workers = modules . map (
( { label , worker } ) => worker && ( mixin ( { label } , worker ) )
( { label , worker } ) => worker && ( mixin ( { label } , worker ) )
) . filter ( Boolean ) ;
) . filter ( Boolean ) ;
const rules = createLoaderRules ( languages , features , workers , output , publicPath );
const rules = createLoaderRules ( languages , features , workers , output , publicPath , compilationPublicPath );
const plugins = createPlugins ( workers , output ) ;
const plugins = createPlugins ( workers , output ) ;
addCompilerRules ( compiler , rules ) ;
addCompilerRules ( compiler , rules ) ;
addCompilerPlugins ( compiler , plugins ) ;
addCompilerPlugins ( compiler , plugins ) ;
@ -80,11 +80,11 @@ function addCompilerPlugins(compiler, plugins) {
plugins . forEach ( ( plugin ) => plugin . apply ( compiler ) ) ;
plugins . forEach ( ( plugin ) => plugin . apply ( compiler ) ) ;
}
}
function get PublicPath( compiler ) {
function get Compilation PublicPath( compiler ) {
return compiler . options . output && compiler . options . output . publicPath || '' ;
return compiler . options . output && compiler . options . output . publicPath || '' ;
}
}
function createLoaderRules ( languages , features , workers , outputPath , p ublicPath) {
function createLoaderRules ( languages , features , workers , outputPath , p luginPublicPath, compilationP ublicPath) {
if ( ! languages . length && ! features . length ) { return [ ] ; }
if ( ! languages . length && ! features . length ) { return [ ] ; }
const languagePaths = flatArr ( languages . map ( ( { entry } ) => entry ) . filter ( Boolean ) ) ;
const languagePaths = flatArr ( languages . map ( ( { entry } ) => entry ) . filter ( Boolean ) ) ;
const featurePaths = flatArr ( features . map ( ( { entry } ) => entry ) . filter ( Boolean ) ) ;
const featurePaths = flatArr ( features . map ( ( { entry } ) => entry ) . filter ( Boolean ) ) ;
@ -105,6 +105,16 @@ function createLoaderRules(languages, features, workers, outputPath, publicPath)
workerPaths [ 'razor' ] = workerPaths [ 'html' ] ;
workerPaths [ 'razor' ] = workerPaths [ 'html' ] ;
}
}
// Determine the public path from which to load worker JS files. In order of precedence:
// 1. Plugin-specific public path.
// 2. Dynamic runtime public path.
// 3. Compilation public path.
const pathPrefix = Boolean ( pluginPublicPath )
? JSON . stringify ( pluginPublicPath )
: ` typeof __webpack_public_path__ === 'string' ` +
` ? __webpack_public_path__ ` +
` : ${ JSON . stringify ( compilationPublicPath ) } `
const globals = {
const globals = {
'MonacoEnvironment' : ` (function (paths) {
'MonacoEnvironment' : ` (function (paths) {
function stripTrailingSlash ( str ) {
function stripTrailingSlash ( str ) {
@ -112,7 +122,7 @@ function createLoaderRules(languages, features, workers, outputPath, publicPath)
}
}
return {
return {
getWorkerUrl : function ( moduleId , label ) {
getWorkerUrl : function ( moduleId , label ) {
var pathPrefix = ( typeof _ _webpack _public _path _ _ === 'string' ? _ _webpack _public _path _ _ : $ { JSON . stringify ( publicPath ) } ) ;
var pathPrefix = $ { pathPrefix } ;
return ( pathPrefix ? stripTrailingSlash ( pathPrefix ) + '/' : '' ) + paths [ label ] ;
return ( pathPrefix ? stripTrailingSlash ( pathPrefix ) + '/' : '' ) + paths [ label ] ;
}
}
} ;
} ;