반응형
package.json
{
"name": "svelte-app",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public --no-clear"
},
"devDependencies": {
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-terser": "^0.4.0",
"autoprefixer": "^10.4.14",
"node-sass": "^8.0.0",
"postcss": "^8.4.21",
"require": "^2.4.20",
"rollup": "^3.15.0",
"rollup-plugin-css-only": "^4.3.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-scss": "^4.0.0",
"rollup-plugin-svelte": "^7.1.2",
"sass": "^1.61.0",
"svelte": "^3.55.0",
"svelte-preprocess": "^5.0.3"
},
"dependencies": {
"sirv-cli": "^2.0.0",
"svelte-spa-router": "^3.3.0"
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
rollup.config.js
import { spawn } from 'child_process';
import svelte from 'rollup-plugin-svelte';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
import css from 'rollup-plugin-css-only';
import autoprefixer from 'autoprefixer';
import postcss from 'postcss';
import sveltePreProcess from 'svelte-preprocess';
const production = !process.env.ROLLUP_WATCH;
function serve() {
let server;
function toExit() {
if (server) server.kill(0);
}
return {
writeBundle() {
if (server) return;
server = spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
process.on('SIGTERM', toExit);
process.on('exit', toExit);
}
};
}
export default {
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: 'public/build/bundle.js'
},
plugins: [
svelte({
compilerOptions: {
// enable run-time checks when not in production
dev: !production
},
preprocess: sveltePreProcess({
scss: {
prependData: `@import "src/assets/scss/variables.scss";`,
},
postcss: {
plugins: [autoprefixer()]
}
}),
}),
// we'll extract any Page CSS out into
// a separate file - better for performance
css({ output: 'bundle.css' }),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ['svelte'],
exportConditions: ['svelte']
}),
commonjs(),
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload('public'),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
watch: {
clearScreen: false
}
};
'Front-end 개발 > JAVASCRIPT' 카테고리의 다른 글
PC에서 가로 스크롤 터치로 움직일 수 있도록 구현 테스트 (0) | 2023.02.26 |
---|---|
Vue directive - 버튼 외 다른 영역 클릭 시 함수 실행 테스트 (0) | 2023.01.27 |
Vue directive - for문 끝난 후 callback 처리 관련 테스트 (0) | 2023.01.27 |
숫자 comma (,) 포맷 적용 테스트 (0) | 2023.01.11 |
파일 용량 단위 포맷 적용 테스트 (Bytes, GB, MB 등) (0) | 2023.01.11 |