Skip to content

Commit

Permalink
feat: use ESM for runtime files
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 31, 2018
1 parent 318a802 commit 18d0ae4
Show file tree
Hide file tree
Showing 9 changed files with 2,765 additions and 2,995 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["transform-es2015-modules-commonjs"]
}
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ module.exports.pitch = function (remainingRequest) {
// on the client: dynamic inject + hot-reload
var code = [
'// add the styles to the DOM',
'var update = require(' + addStylesClientPath + ')(' + id + ', content, ' + isProduction + ', ' + JSON.stringify(options) + ');'
'var add = require(' + addStylesClientPath + ').default',
'var update = add(' + id + ', content, ' + isProduction + ', ' + JSON.stringify(options) + ');'
]
if (!isProduction) {
code = code.concat([
Expand All @@ -67,7 +68,7 @@ module.exports.pitch = function (remainingRequest) {
// component's lifecycle hooks
return shared.concat([
'// add CSS to SSR context',
'var add = require(' + addStylesServerPath + ')',
'var add = require(' + addStylesServerPath + ').default',
'module.exports.__inject__ = function (context) {',
' add(' + id + ', content, ' + isProduction + ', context)',
'};'
Expand Down
6 changes: 3 additions & 3 deletions lib/addStylesClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Modified by Evan You @yyx990803
*/

import listToStyles from './listToStyles'

var hasDocument = typeof document !== 'undefined'

if (typeof DEBUG !== 'undefined' && DEBUG) {
Expand All @@ -14,8 +16,6 @@ if (typeof DEBUG !== 'undefined' && DEBUG) {
) }
}

var listToStyles = require('./listToStyles')

/*
type StyleObject = {
id: number;
Expand Down Expand Up @@ -49,7 +49,7 @@ var ssrIdKey = 'data-vue-ssr-id'
// tags it will allow on a page
var isOldIE = typeof navigator !== 'undefined' && /msie [6-9]\b/.test(navigator.userAgent.toLowerCase())

module.exports = function (parentId, list, _isProduction, _options) {
export default function addStylesClient (parentId, list, _isProduction, _options) {
isProduction = _isProduction

options = _options || {}
Expand Down
4 changes: 2 additions & 2 deletions lib/addStylesServer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var listToStyles = require('./listToStyles')
import listToStyles from './listToStyles'

module.exports = function (parentId, list, isProduction, context) {
export default function addStylesServer (parentId, list, isProduction, context) {
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__
}
Expand Down
2 changes: 1 addition & 1 deletion lib/listToStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Translates the list format produced by css-loader into something
* easier to manipulate.
*/
module.exports = function listToStyles (parentId, list) {
export default function listToStyles (parentId, list) {
var styles = []
var newStyles = {}
for (var i = 0; i < list.length; i++) {
Expand Down
Loading

0 comments on commit 18d0ae4

Please sign in to comment.