Skip to content

Commit 18d0ae4

Browse files
committedJan 31, 2018
feat: use ESM for runtime files
1 parent 318a802 commit 18d0ae4

9 files changed

+2765
-2995
lines changed
 

‎.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["transform-es2015-modules-commonjs"]
3+
}

‎index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ module.exports.pitch = function (remainingRequest) {
4040
// on the client: dynamic inject + hot-reload
4141
var code = [
4242
'// add the styles to the DOM',
43-
'var update = require(' + addStylesClientPath + ')(' + id + ', content, ' + isProduction + ', ' + JSON.stringify(options) + ');'
43+
'var add = require(' + addStylesClientPath + ').default',
44+
'var update = add(' + id + ', content, ' + isProduction + ', ' + JSON.stringify(options) + ');'
4445
]
4546
if (!isProduction) {
4647
code = code.concat([
@@ -67,7 +68,7 @@ module.exports.pitch = function (remainingRequest) {
6768
// component's lifecycle hooks
6869
return shared.concat([
6970
'// add CSS to SSR context',
70-
'var add = require(' + addStylesServerPath + ')',
71+
'var add = require(' + addStylesServerPath + ').default',
7172
'module.exports.__inject__ = function (context) {',
7273
' add(' + id + ', content, ' + isProduction + ', context)',
7374
'};'

‎lib/addStylesClient.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Modified by Evan You @yyx990803
55
*/
66

7+
import listToStyles from './listToStyles'
8+
79
var hasDocument = typeof document !== 'undefined'
810

911
if (typeof DEBUG !== 'undefined' && DEBUG) {
@@ -14,8 +16,6 @@ if (typeof DEBUG !== 'undefined' && DEBUG) {
1416
) }
1517
}
1618

17-
var listToStyles = require('./listToStyles')
18-
1919
/*
2020
type StyleObject = {
2121
id: number;
@@ -49,7 +49,7 @@ var ssrIdKey = 'data-vue-ssr-id'
4949
// tags it will allow on a page
5050
var isOldIE = typeof navigator !== 'undefined' && /msie [6-9]\b/.test(navigator.userAgent.toLowerCase())
5151

52-
module.exports = function (parentId, list, _isProduction, _options) {
52+
export default function addStylesClient (parentId, list, _isProduction, _options) {
5353
isProduction = _isProduction
5454

5555
options = _options || {}

‎lib/addStylesServer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var listToStyles = require('./listToStyles')
1+
import listToStyles from './listToStyles'
22

3-
module.exports = function (parentId, list, isProduction, context) {
3+
export default function addStylesServer (parentId, list, isProduction, context) {
44
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
55
context = __VUE_SSR_CONTEXT__
66
}

‎lib/listToStyles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Translates the list format produced by css-loader into something
33
* easier to manipulate.
44
*/
5-
module.exports = function listToStyles (parentId, list) {
5+
export default function listToStyles (parentId, list) {
66
var styles = []
77
var newStyles = {}
88
for (var i = 0; i < list.length; i++) {

‎package-lock.json

-2,984
This file was deleted.

‎package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"loader-utils": "^1.0.2"
1717
},
1818
"devDependencies": {
19-
"jest": "^18.1.0"
19+
"babel-core": "^6.26.0",
20+
"babel-jest": "^22.1.0",
21+
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
22+
"jest": "^22.1.4"
2023
}
2124
}

‎test/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const addStylesClient = require('../lib/addStylesClient')
2-
const addStylesServer = require('../lib/addStylesServer')
1+
import addStylesClient from '../lib/addStylesClient'
2+
import addStylesServer from '../lib/addStylesServer'
33

44
const mockedList = [
55
[1, 'h1 { color: red; }', ''],

‎yarn.lock

+2,747
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.