@@ -151,14 +151,37 @@ VueComponentCompiler = class VueCompo extends CachingCompiler {
151
151
152
152
//console.log(`js hash: ${jsHash}`);
153
153
154
+ // Lazy load files from NPM packages or imports directories
155
+ const isLazy = ! ! inputFilePath . match ( / ( ^ | \/ ) ( n o d e _ m o d u l e s | i m p o r t s ) \/ / ) ;
156
+
157
+ // Style
158
+ let css = '' ;
159
+ let cssHash = '' ;
160
+ if ( compileResult . styles . length !== 0 ) {
161
+ for ( let style of compileResult . styles ) {
162
+ css += style . css ;
163
+ }
164
+
165
+ cssHash = Hash ( css ) ;
166
+
167
+ //console.log(`css hash: ${cssHash}`);
168
+ if ( ! isDev && isLazy ) {
169
+ // Wrap CSS in Meteor's lazy CSS loader
170
+ css = `
171
+ const modules = require('meteor/modules');
172
+ modules.addStyles(${ JSON . stringify ( css ) } );
173
+ ` ;
174
+ }
175
+ }
176
+
154
177
const { js, templateHash } = generateJs ( vueId , inputFile , compileResult )
155
178
156
- let outputFilePath = inputFile . getPathInPackage ( ) ;
179
+ let outputFilePath = inputFilePath ;
157
180
// Meteor will error when loading .vue files on the server unless they are postfixed with .js
158
181
if ( inputFile . getArch ( ) . indexOf ( 'os' ) === 0 && inputFilePath . indexOf ( 'node_modules' ) !== - 1 ) {
159
182
outputFilePath += '.js' ;
160
183
}
161
-
184
+
162
185
// Including the source maps for .vue files from node_modules breaks source mapping.
163
186
const sourceMap = inputFilePath . indexOf ( 'node_modules' ) === - 1
164
187
? compileResult . map
@@ -167,27 +190,17 @@ VueComponentCompiler = class VueCompo extends CachingCompiler {
167
190
// Add JS Source file
168
191
inputFile . addJavaScript ( {
169
192
path : outputFilePath ,
170
- data : js ,
193
+ data : isLazy && ! isDev ? css + js : js ,
171
194
sourceMap : sourceMap ,
172
- lazy : false ,
195
+ lazy : isLazy ,
173
196
} ) ;
174
197
175
- // Style
176
- let css = '' ;
177
- let cssHash = '' ;
178
- if ( compileResult . styles . length !== 0 ) {
179
- for ( let style of compileResult . styles ) {
180
- css += style . css ;
181
- }
182
-
183
- cssHash = Hash ( css ) ;
184
-
185
- //console.log(`css hash: ${cssHash}`);
186
-
198
+ if ( css ) {
187
199
if ( isDev ) {
188
200
// Add style to client first-connection style list
189
201
global . _dev_server . __addStyle ( { hash : vueId , css, path : inputFilePath } , false ) ;
190
- } else {
202
+ } else if ( ! isLazy ) {
203
+ // In order to avoid lazy-loading errors in --production mode, addStylesheet must come after addJavaScript
191
204
this . addStylesheet ( inputFile , {
192
205
data : css
193
206
} ) ;
0 commit comments