mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 22:21:55 +08:00
DEV: transpile certain ES6 files without producing a module (#6460)
`.js.no-module.es6` files will be transpiled without producing a module. import/export statements are deliberately not supported, so one would still need to use `const module = require('moduleName').default.`
This commit is contained in:
parent
e55f220b33
commit
8b2a379e4e
|
@ -1,4 +1,4 @@
|
|||
require 'sprockets'
|
||||
|
||||
Sprockets.register_mime_type 'application/ecmascript6', extensions: ['.es6', '.js.es6'], charset: :unicode
|
||||
Sprockets.register_mime_type 'application/ecmascript6', extensions: ['.es6', '.js.es6', '.js.no-module.es6'], charset: :unicode
|
||||
Sprockets.register_transformer 'application/ecmascript6', 'application/javascript', Tilt::ES6ModuleTranspilerTemplate
|
||||
|
|
|
@ -178,7 +178,7 @@ JS
|
|||
|
||||
js_source = ::JSON.generate(source, quirks_mode: true)
|
||||
|
||||
if opts[:module_name]
|
||||
if opts[:module_name] && transpile_into_module?
|
||||
filename = opts[:filename] || 'unknown'
|
||||
"Babel.transform(#{js_source}, { moduleId: '#{opts[:module_name]}', filename: '#{filename}', ast: false, presets: ['es2015'], plugins: [['transform-es2015-modules-amd', {noInterop: true}], 'transform-decorators-legacy', exports.WidgetHbsCompiler] }).code"
|
||||
else
|
||||
|
@ -188,6 +188,10 @@ JS
|
|||
|
||||
private
|
||||
|
||||
def transpile_into_module?
|
||||
file.nil? || file.exclude?('.no-module')
|
||||
end
|
||||
|
||||
def module_name(root_path, logical_path)
|
||||
path = nil
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user