Skip to content

Commit 60008ea

Browse files
committed
Remove CSS from JS
1 parent 26a0705 commit 60008ea

File tree

9 files changed

+522
-677
lines changed

9 files changed

+522
-677
lines changed

example/App.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export default {
1818
}
1919
}
2020
</script>
21-
2221
<style>
2322
.container {
2423
position: relative;

example/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Vue from 'vue'
22
import App from './App.vue'
33
import Vue2PerfectScrollbar from '../src'
4+
import '../src/style.css'
45

56
Vue.use(Vue2PerfectScrollbar, {
67
name: 'scroll'
78
})
8-
99
/* eslint-disable no-new */
1010
new Vue({
1111
el: '#app',

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"style": "dist/vue2-perfect-scrollbar.css",
1414
"scripts": {
1515
"build": "rollup -c --environment production",
16+
"build:css": "postcss src/style.css -o dist/vue2-perfect-scrollbar.min.css --env production && postcss src/style.css -o dist/vue2-perfect-scrollbar.css",
1617
"dev": "webpack-dev-server --config webpack.config.js",
1718
"test": "karma start --single-run",
1819
"test:dev": "karma start --single-run=false"
@@ -36,6 +37,7 @@
3637
"babel-loader": "^8.0.2",
3738
"chai": "^4.1.2",
3839
"css-loader": "^1.0.0",
40+
"cssnano": "^4.1.3",
3941
"eslint": "^5.5.0",
4042
"eslint-config-standard": "^12.0.0",
4143
"eslint-loader": "^2.1.0",
@@ -53,14 +55,12 @@
5355
"karma-webpack": "^3.0.5",
5456
"mocha": "^5.2.0",
5557
"node-sass": "^4.9.3",
58+
"postcss-import": "^12.0.0",
5659
"rollup": "^0.65.2",
5760
"rollup-plugin-buble": "^0.19.2",
5861
"rollup-plugin-commonjs": "^9.1.6",
59-
"rollup-plugin-css-only": "^0.4.0",
6062
"rollup-plugin-node-resolve": "^3.4.0",
61-
"rollup-plugin-postcss": "^1.6.2",
6263
"rollup-plugin-uglify": "^5.0.2",
63-
"rollup-plugin-vue": "^4.3.2",
6464
"sass-loader": "^7.1.0",
6565
"style-loader": "^0.23.0",
6666
"ts-loader": "^5.1.0",

postcss.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var path = require('path')
2+
var postcssImport = require('postcss-import')
3+
var cssnano = require('cssnano')
4+
module.exports = ctx => ({
5+
plugins: {
6+
'postcss-import': {
7+
resolve (id, basedir) {
8+
if (/^~/.test(id)) return path.resolve('./node_modules', id.replace('~', ''))
9+
return path.resolve(basedir, id)
10+
}
11+
},
12+
'cssnano': ctx.env === 'production'
13+
}
14+
})

rollup.config.js

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { writeFile } from 'fs'
21
import buble from 'rollup-plugin-buble'
32
import { uglify } from 'rollup-plugin-uglify'
43
import resolve from 'rollup-plugin-node-resolve'
54
import commonjs from 'rollup-plugin-commonjs'
65
import pkg from './package.json'
7-
import css from 'rollup-plugin-css-only'
8-
import vue from 'rollup-plugin-vue'
96

107
const browser = {
118
input: 'src/index.js',
@@ -15,16 +12,11 @@ const browser = {
1512
file: pkg.browser
1613
},
1714
plugins: [
18-
vue({
19-
template: {
20-
isProduction: true
21-
}
22-
}),
15+
buble(),
2316
resolve({
24-
browser: true
17+
browser: true, jsnext: true, main: true
2518
}),
26-
commonjs(),
27-
buble()
19+
commonjs()
2820
]
2921
}
3022

@@ -36,13 +28,8 @@ const browserMin = {
3628
file: 'dist/vue2-perfect-scrollbar.umd.min.js'
3729
},
3830
plugins: [
39-
vue({
40-
template: {
41-
isProduction: true
42-
}
43-
}),
4431
resolve({
45-
browser: true
32+
browser: true, jsnext: true, main: true
4633
}),
4734
commonjs(),
4835
buble(),
@@ -63,24 +50,6 @@ const nodeModules = {
6350
}
6451
],
6552
plugins: [
66-
css({
67-
output: (styles, styleNodes) => {
68-
writeFile(pkg.style, styles, (err) => {
69-
if (err) {
70-
console.log(err)
71-
} else {
72-
resolve()
73-
}
74-
})
75-
}
76-
}),
77-
vue({
78-
template: {
79-
isProduction: true
80-
},
81-
style: false,
82-
css: false
83-
})
8453
],
8554
external: [ 'perfect-scrollbar' ]
8655
}

src/Scrollbar.vue renamed to src/Scrollbar.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<script>
21
import PerfectScrollbar from 'perfect-scrollbar'
32
export default {
43
name: 'PerfectScrollbar',
@@ -43,10 +42,3 @@ export default {
4342
this.$slots.default)
4443
}
4544
}
46-
</script>
47-
<style src="perfect-scrollbar/css/perfect-scrollbar.css"/>
48-
<style>
49-
.ps {
50-
position: relative;
51-
}
52-
</style>

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import PerfectScrollbar from './Scrollbar.vue'
1+
import PerfectScrollbar from './Scrollbar'
22

3-
function install (Vue, settings) {
3+
export function install (Vue, settings) {
44
if (settings) {
55
if (settings.name && typeof settings.name === 'string') {
66
PerfectScrollbar.name = settings.name

src/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@import '~perfect-scrollbar/css/perfect-scrollbar.css';
2+
.ps {
3+
position: relative;
4+
}

0 commit comments

Comments
 (0)