Skip to content

Commit 4cc017a

Browse files
committed
增加 cross-env 依赖,npm 命令更改: npm run buid 生成 example 页面,npm run dist 生成最终可供发布使用的源组件
1 parent 3d94100 commit 4cc017a

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

build/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exports.cssLoaders = function (options) {
3434

3535
// Extract CSS when that option is specified
3636
// (which is the case during production build)
37-
if (options.extract) {
37+
if (options.extract && !!!process.env.DIST_ENV) {
3838
return ExtractTextPlugin.extract({
3939
use: loaders,
4040
fallback: 'vue-style-loader'

build/webpack.prod.conf.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var HtmlWebpackPlugin = require('html-webpack-plugin')
99
var ExtractTextPlugin = require('extract-text-webpack-plugin')
1010
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
1111

12+
var isDist = !!process.env.DIST_ENV
13+
1214
var env = process.env.NODE_ENV === 'testing'
1315
? require('../config/test.env')
1416
: config.build.env
@@ -35,8 +37,22 @@ var webpackConfig = merge(baseWebpackConfig, {
3537
compress: {
3638
warnings: false
3739
},
38-
sourceMap: true
39-
}),
40+
sourceMap: config.build.productionSourceMap
41+
})
42+
]
43+
})
44+
45+
if (isDist) {
46+
webpackConfig.entry = {
47+
'vue-json-pretty': './src/index.js'
48+
}
49+
webpackConfig.output = {
50+
filename: './dist/[name].js',
51+
library: 'VueJsonPretty',
52+
libraryTarget: 'umd'
53+
}
54+
} else {
55+
webpackConfig.plugins.push(
4056
// extract css into its own file
4157
new ExtractTextPlugin({
4258
filename: utils.assetsPath('css/[name].[contenthash].css')
@@ -97,8 +113,8 @@ var webpackConfig = merge(baseWebpackConfig, {
97113
ignore: ['.*']
98114
}
99115
])
100-
]
101-
})
116+
)
117+
}
102118

103119
if (config.build.productionGzip) {
104120
var CompressionWebpackPlugin = require('compression-webpack-plugin')

config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
assetsRoot: path.resolve(__dirname, '../example-dist'),
99
assetsSubDirectory: 'static',
1010
assetsPublicPath: '/',
11-
productionSourceMap: true,
11+
productionSourceMap: false,
1212
// Gzip off by default as many popular static hosts such as
1313
// Surge or Netlify already gzip all static assets for you.
1414
// Before setting to `true`, make sure to:

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"private": true,
77
"scripts": {
88
"dev": "node build/dev-server.js",
9-
"build-example": "node build/build.js",
9+
"build": "node build/build.js",
10+
"dist": "cross-env DIST_ENV=true npm run build",
1011
"e2e": "node test/e2e/runner.js",
1112
"test": "npm run e2e",
1213
"lint": "eslint --ext .js,.vue src test/e2e/specs"
@@ -27,6 +28,7 @@
2728
"chromedriver": "^2.27.2",
2829
"connect-history-api-fallback": "^1.3.0",
2930
"copy-webpack-plugin": "^4.0.1",
31+
"cross-env": "^5.0.5",
3032
"cross-spawn": "^5.0.1",
3133
"css-loader": "^0.28.0",
3234
"cssnano": "^3.10.0",

src/index.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
// The Vue build version to load with the `import` command
2-
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
3-
import Vue from 'vue'
4-
import App from './App'
1+
import VueJsonPretty from './components/tree.vue'
52

6-
Vue.config.productionTip = false
7-
8-
/* eslint-disable no-new */
9-
new Vue({
10-
el: '#app',
11-
template: '<App/>',
12-
components: { App }
3+
export default Object.assign({}, VueJsonPretty, {
4+
version: '1.0.0'
135
})

0 commit comments

Comments
 (0)