Commit 97d69e46 authored by liupengfei's avatar liupengfei

开发环境搭建

parents
Pipeline #272152 failed with stages
in 0 seconds
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
# 本地打包输出目录
LOCAL_DIR=dist
# 应用名称
APP_NAME=flexible
\ No newline at end of file
# 本地开发端口号
SERVER_PORT=2222
# 本地mock目录
MOCK_DIR=mock
# 代理ip
#PROXY_HOST=0.0.0.0
# 代理端口号
#PROXY_PORT=17435
# 上传CDN目录
CDN_DIR=/tuia-package/
# CDN地址
CDN_HOST=//yun.tuisnake.com
# 如果需要上传资源到cdn备用,可以指定图片是否启用hash,仅针对手动上传
ASSETS_NAME=[name].[hash:8]
\ No newline at end of file
node_modules
dist
app.js
\ No newline at end of file
/*
* @Author: flyharvest
* @Date: 2020-07-08 14:53:42
* @LastEditTime: 2020-07-14 10:11:24
* @LastEditors: flyharvest
*/
const config = {
root: true, // 作用的目录是根目录
extends: [
'standard',
"plugin:vue/essential"
], // 继承标准规则
// parser: 'babel-eslint',
parserOptions: {
sourceType: 'module',
},
globals: {
localStorage: true,
alert: true,
Image: true,
history: true,
location: true
},
rules: {
"no-console": process.env.NODE_ENV === 'production' ? "error" : "warn",
"no-debugger": process.env.NODE_ENV === 'production' ? "error" : "warn",
"no-unused-vars": process.env.NODE_ENV === 'production' ? "error" : "warn"
}
}
module.exports = config
.DS_Store
node_modules
*-lock.json
*.lock
dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
{
"hooks": {
"pre-commit": "lint-staged"
}
}
\ No newline at end of file
{
"src/**/*.{js,vue}": [
"cross-env NODE_ENV=production eslint"
],
"src/**/*.{css,less,vue}": [
"stylelint"
]
}
\ No newline at end of file
registry=http://npm.dui88.com
\ No newline at end of file
module.exports = {
"ignoreFiles": ["**/*.js", "**/fonts/**", "dist/**"],
"extends": ["stylelint-config-standard", "stylelint-config-recess-order"],
"plugins": ["stylelint-order"],
"rules": {
"selector-pseudo-class-no-unknown": null,
"unit-case":null,
"no-descending-specificity":null
}
}
<!--
* @Author: flyharvest
* @Date: 2020-07-08 17:22:20
* @LastEditTime: 2020-07-08 17:38:40
* @LastEditors: flyharvest
-->
# @tuia/flexible
flexible by rem
# Usage
```javascript
/**
* 根据项目,设置页面禁止缩放
*/
rem.setViewPort()
/**
* 初始化
* aw 适配尺寸,默认值 750,大部分项目是640
* dw 设计尺寸,默认值750,大部分项目是750
*/
rem.init(750, 750)
/**
* 获取当前根字体大小
*/
console.log('当前根字体大小 ' + rem.getFontSize())
/**
* 获取设计尺寸
*/
console.log('设计尺寸为 ' + rem.getDesignWidth())
/**
* px => rem
*/
console.log('750px 对应rem ' + rem.px2rem(750))
console.log('750px 对应rem ' + rem.px2rem('750px'))
/**
* rem => px
*/
console.log('3.75rem 对应px ' + rem.rem2px(3.75))
console.log('3.75rem 对应px ' + rem.rem2px('3.75rem'))
```
module.exports = {
presets: [
['@babel/preset-env', {
modules: false
}]
],
plugins: ['@babel/plugin-transform-runtime']
}
/*
* @Author: flyharvest
* @Date: 2020-07-14 10:15:41
* @LastEditTime: 2020-07-14 10:43:04
* @LastEditors: flyharvest
*/
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
function commandArgs (string) {
return process.env[string]
}
// 检测文件
function access (path) {
return new Promise((resolve, reject) => {
fs.access(path, (err) => {
if (err) {
reject(`没有找到对应文件 ${path}`)
} else {
resolve(true)
}
})
})
}
// 写入文件
function writeFile (path, content) {
return new Promise((resolve, reject) => {
fs.writeFile(path, content, { encoding: 'utf8' }, (err) => {
if (err) {
reject(`写入文件失败 ${path}`)
} else {
resolve(content)
}
})
})
}
// log相关
function buildError (reason) {
console.log(chalk.red(`[构建错误]:\n ${reason}`))
}
function buildSuccess (success) {
console.log(chalk.green(`[构建成功]:\n ${success}`))
}
function buildInStep (stepDes) {
console.log(chalk.green(`[构建中...]:\n ${stepDes}`))
}
const autoWriteNote = (fileName) => {
return `// this file is auto Write By ${fileName}`
}
const lib = commandArgs('lib')
const env = process.env.NODE_ENV
const autoWriteFileName = `${env} scripts`
// 获取入口文件
async function getEntry() {
if (!lib) {
return Promise.reject(`开发模式下,必须指定包名 \n lib = xxx yarn serve`)
} else {
const devPath = path.resolve(__dirname, '../test', lib, './index.js')
let devHtml = path.resolve(__dirname, '../test', lib, './index.html')
const libPath = path.resolve(__dirname, '../src', lib, './index.js')
const has = await Promise.all([access(devPath), access(devHtml), access(libPath)])
if (has[1] === false) {
devHtml = path.resolve(__dirname, '../test/public/index.html')
}
if (has[0] === false) {
return Promise.reject(`dev 下未找到${lib}/index.js`)
} else if (has[2] === false) {
return Promise.reject(`src 下未找到${lib}/index.js`)
}
return [devPath, devHtml]
}
}
// 生成配置文件
function createBuildFile (entryBuildPath, libJs, libHtml) {
const temp = `
${autoWriteNote(autoWriteFileName)}
module.exports = {
entry: '${libJs}',
libHtml: '${libHtml}',
output: {
path: '${path.resolve(__dirname, `../temporary/${lib}`)}'
}
}
`
return writeFile(entryBuildPath, temp)
}
function buildEntry () {
buildInStep('开始校验文件')
return getEntry()
.then(res => {
buildInStep('文件校验完成')
const buildEntryPath = path.resolve(__dirname, './entry.js')
return createBuildFile(buildEntryPath, res[0], res[1])
})
.then(() => {
buildInStep('入口文件构建完成, 开始 rollup 构建')
})
.catch (err => {
buildError(err)
})
}
module.exports = buildEntry
\ No newline at end of file
/*
* @Author: flyharvest
* @Date: 2020-07-08 17:22:20
* @LastEditTime: 2020-07-14 11:23:40
* @LastEditors: flyharvest
*/
const { dotenv } = require('./util')
dotenv(`.env.${process.env.NODE_ENV}`, true)
const rollup = require('rollup')
async function build () {
// start(require('./rollup/rollup.config')('es'))
start(require('./rollup/rollup.config')('umd'))
}
async function start ({ inputOptions, outputOptions }) {
// create a bundle
const bundle = await rollup.rollup(inputOptions)
// generate code and a sourcemap
await bundle.generate(outputOptions)
// or write the bundle to disk
await bundle.write(outputOptions)
}
build()
const fs = require('fs')
const path = require('path')
const api = fs.readdirSync(path.join(__dirname, './util')).filter(value => value !== 'index.js')
let str = ''
api.forEach((value, i) => {
const name = /(.*).js/.exec(value)[1]
if (i === api.length - 1) {
str += `exports.${name} = require('./${value}')
`
} else {
str += `exports.${name} = require('./${value}')\n
`
}
})
fs.writeFileSync(path.join(__dirname, './util/index.js'), str)
const { execSync, log } = require('./util')
const chalk = require('chalk')
const { stderr, exit } = require('process')
execSync('git fetch origin master')
const result = execSync('git cherry -v HEAD origin/master').toString().split('\n')
result.pop()
if (result.length) {
stderr.write(chalk.red('\n'))
stderr.write(chalk.red('\n'))
stderr.write(chalk.red('【请更新最新代码】 \n\n'))
stderr.write(chalk.red(`与远程 master 分支存在以下 ${result.length} 个commit未更新:\n\n`))
result.forEach((i, index) => {
index < 10 && stderr.write(chalk.red(`${index + 1}.${i.replace('+', '')}\n`))
})
result.length > 10 && stderr.write(chalk.red('......\n'))
stderr.write(chalk.red('\n'))
stderr.write(chalk.red('【更新命令 git pull origin master】\n\n'))
exit(1)
} else {
stderr.write(chalk.red('\n'))
stderr.write(chalk.red('\n'))
log.succcess(chalk.green('baseline 校验通过'))
}
// this file is auto Write By development scripts
module.exports = {
entry: '/Users/liupengfei/work/duiba/@tuia/tuia-flexible/test/flexible/index.js',
libHtml: '/Users/liupengfei/work/duiba/@tuia/tuia-flexible/test/flexible/index.html',
output: {
path: '/Users/liupengfei/work/duiba/@tuia/tuia-flexible/temporary/flexible'
}
}
/*
* @Author: flyharvest
* @Date: 2020-07-08 13:46:42
* @LastEditTime: 2020-07-14 11:42:57
* @LastEditors: flyharvest
*/
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const commonjs = require('@rollup/plugin-commonjs')
const json = require('@rollup/plugin-json')
const buble = require('@rollup/plugin-buble')
const image = require('@rollup/plugin-image')
const alias = require('@rollup/plugin-alias')
const replace = require('@rollup/plugin-replace')
const VuePlugin = require('rollup-plugin-vue')
const postcss = require('rollup-plugin-postcss')
const del = require('rollup-plugin-delete')
const multiInput = require('rollup-plugin-multi-input').default
const { env, git } = require('../util')
const path = require('path')
const { isProd, isDev } = env
const localDir = path.join(__dirname, '../../' + process.env.LOCAL_DIR)
const bannerInfo = `/*!\n * @bundleinfo-${git.name} * -${git.email} * -${(new Date()).toLocaleString()}\n */`
const inputOptions = {
input: ['src/**/index.js'],
// external: id => /src/.test(id),
plugins: [
multiInput(),
del({ targets: localDir }),
replace({
'process.env.isProd': isProd,
'process.env.isDev': isDev
}),
nodeResolve(),
// babel({
// exclude: 'node_modules/**',
// babelHelpers: 'runtime'
// }),
commonjs(),
json(),
VuePlugin({
css: false
}),
postcss({
extract: 'index.css'
}),
buble(),
alias({
entries: {
'@lib': path.join(__dirname, '../../src')
}
}),
image()
]
}
module.exports = function (format = 'es') {
const outputOptions = {
dir: 'dist',
format,
name: process.env.APP_NAME,
banner: bannerInfo
}
return {
inputOptions,
outputOptions
}
}
const glob = require('glob')
const { requireNoCache, log, qs } = require('./util')
const fs = require('fs')
const MOCK = process.env.MOCK_DIR
const resolve = dir => require('path').resolve(__dirname, '../', MOCK + dir)
function handleJs (req, res, api) {
return requireNoCache(resolve(api))(req, res)
}
function handleJson (req, res, api) {
return requireNoCache(resolve(api))
}
function handleError () {
return {
code: 0,
success: true
}
}
function routerCurry (app, api) {
// 将req.headers.referer的参数解析出来,提供给mock使用
app.get('*', (req, res, next) => {
if (req.headers.referer) {
req.mock = qs.parse(req.headers.referer)
}
next()
})
return ({ type, handler, suffix }) => {
app[type](api.split(suffix)[0], (req, res) => {
// 设置响应头
res.setHeader('Content-Type', 'application/json; charset=utf-8')
// 延迟时间
const randomTime = Math.floor(Math.random() * 100) * 10
const result = handler(req, res, api)
// 模拟请求延时
setTimeout(() => {
res.json(result)
}, randomTime)
})
}
}
function router (routerApiCurry, handler, suffix) {
routerApiCurry({
type: 'get',
handler,
suffix
})
routerApiCurry({
type: 'post',
handler,
suffix
})
}
exports.routeAPi = app => {
if (fs.existsSync(MOCK)) {
glob.sync(MOCK + '/**/*.?(js|json)').forEach(api => {
const routerApiCurry = routerCurry(app, api.substring(MOCK.length))
if (api.endsWith('.js')) {
router(routerApiCurry, handleJs, '.js')
} else if (api.endsWith('.json')) {
router(routerApiCurry, handleJson, '.json')
} else if (api.endsWith('.json2')) {
router(routerApiCurry, handleJson, '.json2')
} else {
router(routerApiCurry, handleError, '')
}
})
log.succcess('mock is ready')
} else {
log.warn("'mock' floder is unExisted")
}
}
exports.routeProxy = () => {
let proxtOptions = {}
if (process.env.PROXY_HOST) {
const port = process.env.PROXY_PORT ? ':' + process.env.PROXY_PORT : ''
const target = 'http://' + process.env.PROXY_HOST + port
log.succcess(`mock api start with '/api' is proxy on ${target}`)
proxtOptions = {
proxy: {
'/api': {
target,
pathRewrite: {
'^/api': ''
}
}
}
}
}
return proxtOptions
}
/*
* @Author: flyharvest
* @Date: 2020-07-08 17:22:20
* @LastEditTime: 2020-07-14 10:44:43
* @LastEditors: flyharvest
*/
const { execSync, dotenv } = require('./util')
const buildEntry = require('./build-entry')
dotenv(`.env.${process.env.NODE_ENV}`, true)
// 获取命令行参数
async function start () {
const env = process.env
execSync('cross-env BUILD_TYPE=page npx webpack-dev-server --config cli/webpack/index.js', { env, stdio: [0, 1, 2] })
}
buildEntry().then(() => {
start()
})
const fs = require('fs')
const path = require('path')
// 缓存的目录
const cacheDir = path.join(__dirname, '../../node_modules/.cache')
if (!fs.existsSync(cacheDir)) {
fs.mkdirSync(cacheDir)
}
// 缓存的文件
const dir = path.join(cacheDir, 'cli-cache.json')
if (!fs.existsSync(dir)) {
fs.writeFileSync(dir, '{}')
}
// 缓存
const res = JSON.parse(fs.readFileSync(dir))
// 缓存用到的key
exports.keys = {
LAST_CHOICE_PAGE: 'last-choice-page'
}
// 获取缓存
exports.get = key => {
return res[key]
}
// 设置缓存
exports.set = (key, value) => {
res[key] = value
fs.writeFileSync(dir, JSON.stringify(res))
}
const path = require('path')
const fs = require('fs')
function copyFileSync (target, dest) {
fs.copyFileSync(target, dest)
}
function copydirSync (target, dest) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest)
}
const dirs = fs.readdirSync(target)
dirs.forEach(dir => {
const filepath = path.join(target, dir)
const temp = fs.statSync(filepath)
if (temp.isFile()) {
copyFileSync(filepath, path.join(dest, dir))
} else if (temp.isDirectory()) {
copydirSync(filepath, path.join(dest, dir))
}
})
}
/**
* 移动目录以及内容
*/
module.exports = (target, dest) => {
copydirSync(target, dest)
}
const fs = require('fs')
function deletedirSync (path) {
let files = []
if (fs.existsSync(path)) {
files = fs.readdirSync(path)
files.forEach(function (file, index) {
const curPath = path + '/' + file
if (fs.statSync(curPath).isDirectory()) {
deletedirSync(curPath)
} else {
fs.unlinkSync(curPath)
}
})
fs.rmdirSync(path)
}
}
/**
* 删除文件夹及其内容
*/
module.exports = function (dest) {
deletedirSync(dest)
}
const fs = require('fs')
const path = require('path')
const dotenv = require('dotenv')
const baseEnv = path.join(__dirname, '../../.env')
module.exports = (name, isWriteToEnv = false) => {
const filepath = path.join(__dirname, '../../' + name)
if (isWriteToEnv) {
dotenv.config({
path: baseEnv
})
dotenv.config({
path: filepath
})
}
const baseConfig = dotenv.parse(fs.readFileSync(baseEnv))
const config = dotenv.parse(fs.readFileSync(filepath))
return {
...baseConfig,
...config
}
}
const { isDev } = require('./env')
const inquirer = require('inquirer')
const cache = require('./cache')
const fs = require('fs')
const path = require('path')
const glob = require('glob')
/**
* 所有的皮肤
*/
const pages = {}
glob.sync('./src/pages/**/main.js').forEach(fullpath => {
const shortPath = /.\/src\/pages\/(.*)\/main.js/.exec(fullpath)[1]
const key = shortPath.replace(/\//g, '_').toLowerCase()
pages[key] = {
shortPath,
longPath: path.join(__dirname, '../../src/pages/' + shortPath + '/main.js')
}
})
exports.pages = pages
/**
* 启动询问
*/
exports.inquirer = () => {
return inquirer.prompt({
type: 'list',
name: 'name',
message: 'Pick pages, default is last choice',
default: cache.get(cache.keys.LAST_CHOICE_PAGE) || Object.keys(pages)[0],
choices: Object.keys(pages)
})
}
/**
* 获取选中的页面
*/
const choicesPages = () => {
const name = process.env.page
if (!name) return pages
const _pages = {}
Object.keys(pages).forEach(key => {
if (name === key) {
_pages[key] = pages[key]
return _pages
}
})
return _pages
}
exports.choicesPages = choicesPages
/**
* 入口文件
*/
let cacheEntrys = null
const entrys = () => {
if (cacheEntrys) return cacheEntrys
const pages = choicesPages()
const isSinglePage = Object.keys(pages).length === 1
// 页面入口
Object.keys(pages).forEach(key => {
// 页面有自己的模版
const pageTemplate = path.join(__dirname, '../../src/pages/' + pages[key].shortPath + '/index.html')
const isPageTplexist = fs.existsSync(pageTemplate)
pages[key].template = isPageTplexist ? pageTemplate : path.join(__dirname, '../../public/index.html')
pages[key] = {
...pages[key],
title: key,
entry: pages[key].longPath,
filename: isSinglePage ? 'index.html' : `${key}.html`,
chunks: [key],
chunksSortMode: 'manual'
}
})
// 如果开发环境,需要注入config
if (isDev && process.env.CFG_INJECT) {
Object.keys(pages).forEach(key => {
// 页面有自己的配置项
const cfgChunkName = `${key}-config.dev`
const pageConfig = path.join(__dirname, '../../src/pages/' + pages[key].path + '/config.js')
const isPageConfigExist = fs.existsSync(pageConfig)
pages[cfgChunkName] = {
entry: isPageConfigExist ? pageConfig : './src/config/index.js'
}
// 页面级注入配置项entry
const chunk = pages[key].chunks
pages[key].chunks = [cfgChunkName, ...chunk]
})
}
cacheEntrys = pages
return pages
}
exports.entrys = entrys
/**
* 环境判断
*/
const isProd = process.env.NODE_ENV === 'production'
const isDev = process.env.NODE_ENV === 'development'
exports.isProd = isProd
exports.isDev = isDev
const { execSync } = require('child_process')
module.exports = execSync
const { execSync } = require('child_process')
/**
* git信息
*/
const email = execSync('git config user.email').toString()
const name = execSync('git config user.name').toString()
module.exports = {
email,
name
}
exports.cache = require('./cache.js')
exports.copydirSync = require('./copydirSync.js')
exports.deletedirSync = require('./deletedirSync.js')
exports.dotenv = require('./dotenv.js')
exports.entry = require('./entry.js')
exports.env = require('./env.js')
exports.execSync = require('./execSync.js')
exports.git = require('./git.js')
exports.log = require('./log.js')
exports.md5 = require('./md5.js')
exports.mkdirSync = require('./mkdirSync.js')
exports.qs = require('./qs.js')
exports.readdirSync = require('./readdirSync.js')
exports.requireNoCache = require('./requireNoCache.js')
const chalk = require('chalk')
/**
* 控制台打印
*/
module.exports = {
succcess: msg => {
console.log('\n')
console.log(chalk.bold.bgGreen(' SUCCESS ') + ' ' + chalk.green(msg))
console.log('\n')
},
warn: msg => {
console.log('\n')
console.log(chalk.bold.bgYellow(' WARN ') + ' ' + chalk.yellow(msg))
console.log('\n')
},
error: msg => {
console.log('\n')
console.log(chalk.bold.bgRed(' ERROR ') + ' ' + chalk.red(msg))
console.log('\n')
},
info: msg => {
console.log('\n')
console.log(chalk.bold.bgBlue(' INFO ') + ' ' + chalk.blue(msg))
console.log('\n')
}
}
const crypto = require('crypto')
const fs = require('fs')
module.exports = filePath => {
const buffer = fs.readFileSync(filePath)
const fsHash = crypto.createHash('md5')
fsHash.update(buffer)
const md5 = fsHash.digest('hex')
return md5
}
const fs = require('fs')
const path = require('path')
const deletedirSync = require('./deletedirSync')
const cacheDir = path.join(__dirname, '../../node_modules/.cache')
if (!fs.existsSync(cacheDir)) {
fs.mkdirSync(cacheDir)
}
module.exports = (dir, isClear = false) => {
const dest = path.join(cacheDir, dir)
if (fs.existsSync(dest)) {
if (isClear) {
deletedirSync(dest)
}
} else {
fs.mkdirSync(dest)
}
return dest
}
/**
* 类似 String.prototype.trim (处于兼容考虑)
* @param { String } str
*/
function trim (str) {
return str.replace(/^\s+|\s+$/g, '')
}
/**
* 解码 (增加对异常的处理)
* @param { String } input 字符串
*/
function decode (input) {
try {
// decodeURIComponent('param=%A8')
return decodeURIComponent(input)
} catch (err) {
return ''
}
}
// 解析缓存
const qsCache = {}
module.exports = {
/**
* 从 url 上获取 query string, 返回对象
* 如: //xxx.com?a=1&b=2 => {a: 1, b: 2}
* @param { String } url 链接
*/
parse: function (url = window.location.href) {
if (!url) {
return {}
}
if (qsCache[url]) {
return qsCache[url]
}
const m = url.match(/\?([^#]*)/)
const search = m ? m[1] : '' // a=1&b=2
if (!search) {
return {}
}
const res = {}
const pairs = search.split('&')
for (let i = 0; i < pairs.length; i++) {
const kv = pairs[i] // a=1
if (!kv) {
continue
}
let [key, value] = kv.split('=')
key = trim(decode(key))
value = trim(decode(value))
// 空值
if (value === 'undefined' || value === 'null') {
value = ''
}
res[key] = value
}
qsCache[url] = res
return res
},
/**
* 将对象参数,转换 query string
* 如: { a: 1, b: 2} => a=1&b=2
* @param { Object } params 参数对象
*/
stringify: function (params = {}) {
return Object.keys(params).map(key => {
let value = params[key]
if (value == null) {
value = ''
}
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
}).join('&')
}
}
const path = require('path')
const fs = require('fs')
let fileList = []
function readdirSync (dest) {
const dirs = fs.readdirSync(dest)
dirs.forEach(dir => {
const filePath = path.join(dest, dir)
const temp = fs.statSync(filePath)
if (temp.isFile()) {
fileList.push({
name: dir,
filePath
})
} else if (temp.isDirectory()) {
readdirSync(filePath)
}
})
}
module.exports = dest => {
fileList = []
readdirSync(dest)
return fileList
}
/**
* 没有缓存的require
*/
module.exports = function (filePath) {
delete require.cache[filePath]
return require(filePath)
}
const path = require('path')
const webpack = require('webpack')
const resolve = dir => path.join(__dirname, dir)
const route = require('../route')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { env } = require('../util')
const entry = require('../entry')
const { isProd, isDev } = env
const localDir = path.join(__dirname, '../../' + process.env.LOCAL_DIR)
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = {
mode: process.env.NODE_ENV,
entry: {
main: entry.entry
},
output: {
path: entry.output.path,
filename: '[name].js',
publicPath: '/'
},
devtool: 'inline-source-map',
devServer: {
historyApiFallback: true,
port: process.env.SERVER_PORT,
contentBase: localDir,
hot: true,
inline: true,
stats: 'errors-only',
overlay: true,
compress: true,
before (app) {
route.routeAPi(app)
},
...route.routeProxy()
},
optimization: {
splitChunks: false // 禁止webpack自动分包优化
},
// 解析
resolve: {
// 路径优化
alias: {
'@lib': resolve('../../src')
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.(le|c)ss$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'less-loader', {
loader: 'style-resources-loader',
options: {
patterns: [
'./src/style/mixin/index.less'
]
}
}]
},
{
test: /\.(js|vue)$/,
enforce: 'pre', // 必须强制在代码babel之前处理
use: 'eslint-loader',
exclude: /node_modules/
},
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(json|json2)$/,
use: 'json-loader'
},
{
test: /\.(png|jpe?g|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 1,
name: isProd ? '[name].[contenthash:8].[ext]' : '[path][name].[ext]'
}
}
]
}
]
},
plugins: [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: entry.libHtml,
title: process.env.APP_NAME,
entry: resolve('../../src/main.js'),
filename: 'index.html',
chunks: ['main'],
chunksSortMode: 'manual'
}),
new webpack.EnvironmentPlugin({
isProd,
isDev
}),
// 当开启 HMR 的时候使用该插件会显示模块的相对路径,建议用于开发环境。
new webpack.NamedModulesPlugin(),
// 启用热替换模块(Hot Module Replacement),也被称为 HMR。
new webpack.HotModuleReplacementPlugin()
]
}
{
"exclude": [
"node_modules"
],
"include": [
"src/**/*", "app.js"
],
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"baseUrl": ".",
"paths": {
"@/*": [
"./src/*"
]
},
"allowSyntheticDefaultImports": true
}
}
{
"name": "@tuia/flexible",
"version": "1.0.2",
"main": "dist/index.umd.js",
"module": "dist/index.es.js",
"license": "MIT",
"scripts": {
"serve": "cross-env NODE_ENV=development node cli/serve",
"build": "cross-env NODE_ENV=production node cli/build",
"check": "cross-env NODE_ENV=production node cli/check.branch",
"publish": "npm publish --access=public"
},
"files": [
"dist",
"package.json",
"README.md",
"types"
],
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.10.4",
"@babel/preset-env": "^7.9.5",
"@rollup/plugin-alias": "^3.1.0",
"@rollup/plugin-babel": "^5.0.2",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^12.0.0",
"@rollup/plugin-image": "^2.0.4",
"@rollup/plugin-json": "^4.0.3",
"@rollup/plugin-multi-entry": "^3.0.1",
"@rollup/plugin-node-resolve": "^8.0.0",
"@rollup/plugin-replace": "^2.3.2",
"@vue/compiler-sfc": "^3.0.0-beta.19",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"chalk": "^4.0.0",
"clean-webpack-plugin": "^3.0.0",
"cross-env": "^7.0.2",
"css-loader": "^3.5.2",
"dotenv": "^8.2.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^4.0.0",
"eslint-plugin-html": "^6.0.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-vue": "^6.2.2",
"express": "^4.17.1",
"file-loader": "^6.0.0",
"glob": "^7.1.6",
"html-webpack-plugin": "^4.2.0",
"husky": "^4.2.5",
"inquirer": "^7.1.0",
"json-loader": "^0.5.7",
"less": "^3.11.1",
"less-loader": "^5.0.0",
"lint-staged": "^10.1.7",
"mini-css-extract-plugin": "^0.9.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"postcss-loader": "^3.0.0",
"postcss-px2rem": "^0.3.0",
"rollup": "^2.7.2",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-less": "^1.1.2",
"rollup-plugin-multi-input": "^1.1.1",
"rollup-plugin-postcss": "^3.1.2",
"rollup-plugin-terser": "^6.1.0",
"rollup-plugin-vue": "5.1.6",
"style-loader": "^1.1.4",
"style-resources-loader": "^1.3.3",
"stylelint": "^13.3.3",
"stylelint-config-recess-order": "^2.0.4",
"stylelint-config-standard": "^20.0.0",
"stylelint-order": "^4.0.0",
"ts-loader": "^7.0.1",
"typescript": "^3.8.3",
"url-loader": "^4.1.0",
"vue": "^2.6.11",
"vue-loader": "15.9",
"vue-template-compiler": "^2.6.11",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-middleware": "^3.7.2",
"webpack-dev-server": "^3.10.3",
"webpack-hot-middleware": "^2.25.0"
}
}
/*
* @Author: flyharvest
* @Date: 2020-07-08 14:10:50
* @LastEditTime: 2020-07-08 16:42:20
* @LastEditors: flyharvest
*/
module.exports = {
plugins: {
'postcss-px2rem': {
// 基准大小 baseSize,需要html中font-size换算比例倍数相同
remUnit: 200
}
}
}
/*
* @Author: flyharvest
* @Date: 2020-07-14 10:20:49
* @LastEditTime: 2020-07-14 10:55:15
* @LastEditors: flyharvest
*/
import b from '@lib/xhr'
console.log(b)
/*
* @Author: flyharvest
* @Date: 2020-07-14 11:14:25
* @LastEditTime: 2020-07-14 11:18:57
* @LastEditors: flyharvest
*/
import * as flexible from '@lib/flexible'
import * as xhr from '@lib/xhr'
export {
flexible,
xhr
}
/*
* @Author: flyharvest
* @Date: 2020-07-14 10:47:13
* @LastEditTime: 2020-07-14 10:55:38
* @LastEditors: flyharvest
*/
const b = 'sss'
export default b
<!--
* @Author: flyharvest
* @Date: 2020-07-14 10:21:54
* @LastEditTime: 2020-07-14 10:22:46
* @LastEditors: flyharvest
-->
<!DOCTYPE html>
<head>
<title>测试页面</title>
</head>
<body>
<div id="app"></div>
</body>
\ No newline at end of file
/*
* @Author: flyharvest
* @Date: 2020-07-14 10:21:58
* @LastEditTime: 2020-07-14 11:18:04
* @LastEditors: flyharvest
*/
import a from '@lib/xhr'
console.log(a)
<!--
* @Author: flyharvest
* @Date: 2020-07-14 10:30:48
* @LastEditTime: 2020-07-14 10:31:37
* @LastEditors: flyharvest
-->
<!DOCTYPE html>
<head>
<title>测试页面</title>
</head>
<body>
<div id="app"></div>
</body>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment